// // RoomsListViewModel.swift // Chat // // Created by Sergey Tarasov on 10.08.2022. // import Foundation import XMPPFramework import XMPPFrameworkSwift class RoomsListViewModel: ObservableObject { let manager = MUCManager() @Published var rooms: [Room] = [] var timer: Timer? init() { self.timer = Timer.scheduledTimer( timeInterval: 2, target: self, selector: #selector(fetchChatList), userInfo: nil, repeats: true ) } @objc public func fetchChatList() { if rooms.isEmpty { self.manager.fetchRooms() self.rooms = self.manager.rooms } else { self.timer?.invalidate() } } }