From e3f99d7aafdca940d5b9816ba77f499962a22adc Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 25 Jun 2025 17:15:21 +0300 Subject: [PATCH] Make the RoomInfo isPrivate field optional and handle it accordingly. --- .../Screens/HomeScreen/HomeScreenViewModel.swift | 2 +- .../RoomDetailsScreenViewModel.swift | 2 +- .../Screens/Timeline/TimelineViewModel.swift | 4 ++-- .../Services/Room/RoomInfoProxyProtocol.swift | 14 ++++++++++---- .../Services/Room/RoomPowerLevelsProxy.swift | 2 +- .../Sources/Services/Room/RoomProxyProtocol.swift | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 3112e3e3f..13b7bd977 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -364,7 +364,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol return } - if !roomProxy.infoPublisher.value.isPrivate { + if !(roomProxy.infoPublisher.value.isPrivate ?? true) { state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomID, isDM: roomProxy.isDirectOneToOneRoom, state: .public) } else { state.bindings.leaveRoomAlertItem = if roomProxy.infoPublisher.value.joinedMembersCount > 1 { diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift index 34dffd87a..f84d4c50c 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift @@ -125,7 +125,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr } state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id, isDM: roomProxy.isDirectOneToOneRoom, - state: roomProxy.infoPublisher.value.isPrivate ? .private : .public) + state: roomProxy.infoPublisher.value.isPrivate ?? true ? .private : .public) case .confirmLeave: Task { await leaveRoom() } case .processTapIgnore: diff --git a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift index 65a588298..6616136bd 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift @@ -92,7 +92,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol { case .always: false case .privateOnly: - !roomProxy.infoPublisher.value.isPrivate + !(roomProxy.infoPublisher.value.isPrivate ?? true) case .never: true } @@ -524,7 +524,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol { case .privateOnly: guard let self else { return Just(false).eraseToAnyPublisher() } return roomProxy.infoPublisher - .map { !$0.isPrivate } + .map { !($0.isPrivate ?? false) } .removeDuplicates() .eraseToAnyPublisher() } diff --git a/ElementX/Sources/Services/Room/RoomInfoProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomInfoProxyProtocol.swift index 550b980dc..be54de5ec 100644 --- a/ElementX/Sources/Services/Room/RoomInfoProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomInfoProxyProtocol.swift @@ -79,12 +79,18 @@ extension BaseRoomInfoProxyProtocol { extension RoomInfoProxyProtocol { /// A room might be non public but also not private given the fact that the join rule might be missing or unsupported. - var isPrivate: Bool { - switch joinRule { - case .invite, .knock, .restricted, .knockRestricted: + var isPrivate: Bool? { + guard let joinRule else { + return nil + } + + return switch joinRule { + case .invite, .knock, .restricted, .knockRestricted, .private: true - default: + case .public: false + case .custom: // We don't know how to handle this + nil } } diff --git a/ElementX/Sources/Services/Room/RoomPowerLevelsProxy.swift b/ElementX/Sources/Services/Room/RoomPowerLevelsProxy.swift index 95ebb179f..aeb3588ec 100644 --- a/ElementX/Sources/Services/Room/RoomPowerLevelsProxy.swift +++ b/ElementX/Sources/Services/Room/RoomPowerLevelsProxy.swift @@ -27,7 +27,7 @@ struct RoomPowerLevelsProxy: RoomPowerLevelsProxyProtocol { } func suggestedRole(forUser userID: String) -> RoomMemberRole { - let powerLevel = powerLevels.userPowerLevels()[userID] ?? 0 + let powerLevel = powerLevels.userPowerLevels()[userID] ?? values.usersDefault return suggestedRoleForPowerLevel(powerLevel: powerLevel) } diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index b0374c3c5..bae679dd3 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -188,7 +188,7 @@ extension JoinedRoomProxyProtocol { avatar: infoPublisher.value.avatar, canonicalAlias: infoPublisher.value.canonicalAlias, isEncrypted: infoPublisher.value.isEncrypted, - isPublic: !infoPublisher.value.isPrivate, + isPublic: !(infoPublisher.value.isPrivate ?? false), isDirect: infoPublisher.value.isDirect) }