Observe presence changes to update RoomInfoBasicView

This commit is contained in:
aringenbach
2022-04-04 16:36:52 +02:00
parent f776b335ef
commit 967b4429f5
@@ -58,10 +58,12 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
self.room = room
super.init()
startObservingSummaryChanges()
startObservingPresenceChanges()
}
deinit {
stopObservingSummaryChanges()
stopObservingPresenceChanges()
}
// MARK: - Public
@@ -89,11 +91,27 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
NotificationCenter.default.removeObserver(self, name: .mxRoomSummaryDidChange, object: nil)
}
private func startObservingPresenceChanges() {
NotificationCenter.default.addObserver(self, selector: #selector(presenceUpdated(_:)), name: .mxkContactManagerMatrixUserPresenceChange, object: nil)
}
private func stopObservingPresenceChanges() {
NotificationCenter.default.removeObserver(self, name: .mxkContactManagerMatrixUserPresenceChange, object: nil)
}
@objc private func roomSummaryUpdated(_ notification: Notification) {
// force update view
self.update(viewState: .loaded(viewData: viewData))
}
@objc private func presenceUpdated(_ notification: NSNotification) {
guard let updatedUserId = notification.object as? String, updatedUserId == room.directUserId else {
return
}
self.update(viewState: .loaded(viewData: viewData))
}
private func loadData() {
self.update(viewState: .loaded(viewData: viewData))
}