RoomsListStore.swift 825 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // RoomsListStore.swift
  3. // Chat
  4. //
  5. // Created by Sergey Tarasov on 10.08.2022.
  6. //
  7. import Foundation
  8. import XMPPFramework
  9. import XMPPFrameworkSwift
  10. final class RoomsListStore: NSObject, ObservableObject {
  11. @Published var rooms: [Room] = []
  12. override init() {
  13. super.init()
  14. XMPPController.shared.xmppMUCLight.addDelegate(self, delegateQueue: .main)
  15. }
  16. func fetchRooms() {
  17. _ = XMPPController.shared.xmppMUCLight.discoverRooms(forServiceNamed: "chat.msg.sharix-app.org")
  18. }
  19. }
  20. extension RoomsListStore: XMPPMUCLightDelegate {
  21. func xmppMUCLight(_ sender: XMPPMUCLight, didDiscoverRooms rooms: [DDXMLElement], forServiceNamed serviceName: String) {
  22. debugPrint(rooms)
  23. self.rooms = rooms.map({ Room(id: $0.attributeStringValue(forName: "jid") ?? "", name: $0.attributeStringValue(forName: "name") ?? "") })
  24. }
  25. }