Be more lenient with the power levels as they can still be missing at the time the various screens are created e.g. after accepting an invite.

The correct solution is to subscribe to update and update the UI accordingly when receiving them.
This commit is contained in:
Stefan Ceriu
2025-06-26 16:34:34 +03:00
committed by Stefan Ceriu
parent 37cbf733d4
commit 9c28a69ccf
10 changed files with 108 additions and 103 deletions
@@ -23,18 +23,14 @@ class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTi
super.init(initialViewState: ThreadTimelineScreenViewState())
Task { [weak self] in
for await roomInfo in roomProxy.infoPublisher.receive(on: DispatchQueue.main).values {
guard !Task.isCancelled else {
return
}
self?.handleRoomInfoUpdate(roomInfo)
roomProxy.infoPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] roomInfo in
self?.updateRoomInfo(roomInfo)
}
}
.store(in: &cancellables)
.store(in: &cancellables)
handleRoomInfoUpdate(roomProxy.infoPublisher.value)
updateRoomInfo(roomProxy.infoPublisher.value)
}
// MARK: - Public
@@ -62,8 +58,9 @@ class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTi
// MARK: - Private
private func handleRoomInfoUpdate(_ roomInfo: RoomInfoProxyProtocol) {
guard let powerLevels = roomInfo.powerLevels else { fatalError("Missing room power levels") }
state.canSendMessage = powerLevels.canOwnUser(sendMessage: .roomMessage)
private func updateRoomInfo(_ roomInfo: RoomInfoProxyProtocol) {
if let powerLevels = roomInfo.powerLevels {
state.canSendMessage = powerLevels.canOwnUser(sendMessage: .roomMessage)
}
}
}