Make the room power levels optional as they can be missing depending on what state events are requested

This commit is contained in:
Stefan Ceriu
2025-06-25 12:35:04 +03:00
committed by Stefan Ceriu
parent c7ff6c019d
commit de723853e3
16 changed files with 65 additions and 45 deletions
@@ -405,12 +405,13 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
private func updateRoomInfo(roomInfo: RoomInfoProxyProtocol) {
state.pinnedEventIDs = roomInfo.pinnedEventIDs
state.canCurrentUserSendMessage = roomInfo.powerLevels.canOwnUser(sendMessage: .roomMessage)
state.canCurrentUserRedactOthers = roomInfo.powerLevels.canOwnUserRedactOther()
state.canCurrentUserRedactSelf = roomInfo.powerLevels.canOwnUserRedactOwn()
state.canCurrentUserPin = roomInfo.powerLevels.canOwnUserPinOrUnpin()
state.canCurrentUserKick = roomInfo.powerLevels.canOwnUserKick()
state.canCurrentUserBan = roomInfo.powerLevels.canOwnUserBan()
guard let powerLevels = roomInfo.powerLevels else { fatalError("Missing room power levels") }
state.canCurrentUserSendMessage = powerLevels.canOwnUser(sendMessage: .roomMessage)
state.canCurrentUserRedactOthers = powerLevels.canOwnUserRedactOther()
state.canCurrentUserRedactSelf = powerLevels.canOwnUserRedactOwn()
state.canCurrentUserPin = powerLevels.canOwnUserPinOrUnpin()
state.canCurrentUserKick = powerLevels.canOwnUserKick()
state.canCurrentUserBan = powerLevels.canOwnUserBan()
}
private func setupSubscriptions() {