123456789101112131415161718192021222324252627282930 |
- //
- // RoomsListStore.swift
- // Chat
- //
- // Created by Sergey Tarasov on 10.08.2022.
- //
- import Foundation
- import XMPPFramework
- import XMPPFrameworkSwift
- final class RoomsListStore: NSObject, ObservableObject {
- @Published var rooms: [Room] = []
- override init() {
- super.init()
- XMPPController.shared.xmppMUCLight.addDelegate(self, delegateQueue: .main)
- }
- func fetchRooms() {
- _ = XMPPController.shared.xmppMUCLight.discoverRooms(forServiceNamed: "chat.msg.sharix-app.org")
- }
- }
- extension RoomsListStore: XMPPMUCLightDelegate {
- func xmppMUCLight(_ sender: XMPPMUCLight, didDiscoverRooms rooms: [DDXMLElement], forServiceNamed serviceName: String) {
- debugPrint(rooms)
- self.rooms = rooms.map({ Room(id: $0.attributeStringValue(forName: "jid") ?? "", name: $0.attributeStringValue(forName: "name") ?? "") })
- }
- }
|