Make the RoomInfo isPrivate field optional and handle it accordingly.

This commit is contained in:
Stefan Ceriu
2025-06-25 17:15:21 +03:00
committed by Stefan Ceriu
parent 11c7d07e76
commit bfd97cd560
6 changed files with 16 additions and 10 deletions
@@ -364,7 +364,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
return return
} }
if !roomProxy.infoPublisher.value.isPrivate { if !(roomProxy.infoPublisher.value.isPrivate ?? true) {
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomID, isDM: roomProxy.isDirectOneToOneRoom, state: .public) state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomID, isDM: roomProxy.isDirectOneToOneRoom, state: .public)
} else { } else {
state.bindings.leaveRoomAlertItem = if roomProxy.infoPublisher.value.joinedMembersCount > 1 { state.bindings.leaveRoomAlertItem = if roomProxy.infoPublisher.value.joinedMembersCount > 1 {
@@ -125,7 +125,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
} }
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id, state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id,
isDM: roomProxy.isDirectOneToOneRoom, isDM: roomProxy.isDirectOneToOneRoom,
state: roomProxy.infoPublisher.value.isPrivate ? .private : .public) state: roomProxy.infoPublisher.value.isPrivate ?? true ? .private : .public)
case .confirmLeave: case .confirmLeave:
Task { await leaveRoom() } Task { await leaveRoom() }
case .processTapIgnore: case .processTapIgnore:
@@ -92,7 +92,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
case .always: case .always:
false false
case .privateOnly: case .privateOnly:
!roomProxy.infoPublisher.value.isPrivate !(roomProxy.infoPublisher.value.isPrivate ?? true)
case .never: case .never:
true true
} }
@@ -524,7 +524,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
case .privateOnly: case .privateOnly:
guard let self else { return Just(false).eraseToAnyPublisher() } guard let self else { return Just(false).eraseToAnyPublisher() }
return roomProxy.infoPublisher return roomProxy.infoPublisher
.map { !$0.isPrivate } .map { !($0.isPrivate ?? false) }
.removeDuplicates() .removeDuplicates()
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }
@@ -79,12 +79,18 @@ extension BaseRoomInfoProxyProtocol {
extension RoomInfoProxyProtocol { extension RoomInfoProxyProtocol {
/// A room might be non public but also not private given the fact that the join rule might be missing or unsupported. /// 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 { var isPrivate: Bool? {
switch joinRule { guard let joinRule else {
case .invite, .knock, .restricted, .knockRestricted: return nil
}
return switch joinRule {
case .invite, .knock, .restricted, .knockRestricted, .private:
true true
default: case .public:
false false
case .custom: // We don't know how to handle this
nil
} }
} }
@@ -27,7 +27,7 @@ struct RoomPowerLevelsProxy: RoomPowerLevelsProxyProtocol {
} }
func suggestedRole(forUser userID: String) -> RoomMemberRole { func suggestedRole(forUser userID: String) -> RoomMemberRole {
let powerLevel = powerLevels.userPowerLevels()[userID] ?? 0 let powerLevel = powerLevels.userPowerLevels()[userID] ?? values.usersDefault
return suggestedRoleForPowerLevel(powerLevel: powerLevel) return suggestedRoleForPowerLevel(powerLevel: powerLevel)
} }
@@ -188,7 +188,7 @@ extension JoinedRoomProxyProtocol {
avatar: infoPublisher.value.avatar, avatar: infoPublisher.value.avatar,
canonicalAlias: infoPublisher.value.canonicalAlias, canonicalAlias: infoPublisher.value.canonicalAlias,
isEncrypted: infoPublisher.value.isEncrypted, isEncrypted: infoPublisher.value.isEncrypted,
isPublic: !infoPublisher.value.isPrivate, isPublic: !(infoPublisher.value.isPrivate ?? false),
isDirect: infoPublisher.value.isDirect) isDirect: infoPublisher.value.isDirect)
} }