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 009da42b08
commit e3f99d7aaf
6 changed files with 16 additions and 10 deletions

View File

@@ -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 {

View File

@@ -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:

View File

@@ -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()
}

View File

@@ -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
}
}

View File

@@ -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)
}

View File

@@ -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)
}