use isDM from the SDK to determine if a spaceRoom, a joinedRoom or a notificationItem are from a dm room.

This commit is contained in:
Mauro Romito
2026-05-13 17:43:58 +02:00
committed by Mauro
parent ff5dcb040d
commit a4a857003c
29 changed files with 81 additions and 45 deletions
@@ -91,7 +91,7 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
}
if canMentionAllUsers,
!roomProxy.isDirectOneToOneRoom,
!roomProxy.infoPublisher.value.isDM,
Self.shouldIncludeMember(userID: PillUtilities.atRoom, displayName: PillUtilities.everyone, searchText: suggestionTrigger.text) {
membersSuggestion
.insert(SuggestionItem(suggestionType: .allUsers(roomProxy.details.avatar), range: suggestionTrigger.range, rawSuggestionText: suggestionTrigger.text), at: 0)
@@ -70,7 +70,7 @@ struct RoomScreenViewState: BindableState {
}
/// Whether the current room is a DM
var isDirectOneToOneRoom: Bool
var isDM: Bool
var roomThreadListEnabled = false
var isKnockableRoom = false
@@ -70,7 +70,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
let viewState = RoomScreenViewState(roomTitle: roomProxy.infoPublisher.value.displayName ?? roomProxy.id,
roomAvatar: roomProxy.infoPublisher.value.avatar,
hasOngoingCall: roomProxy.infoPublisher.value.hasRoomCall,
isDirectOneToOneRoom: roomProxy.isDirectOneToOneRoom,
isDM: roomProxy.infoPublisher.value.isDM,
hasSuccessor: roomProxy.infoPublisher.value.successor != nil,
roomHistorySharingState: roomProxy.infoPublisher.value.historySharingState)
super.init(initialViewState: appHooks.roomScreenHook.update(viewState),
@@ -271,7 +271,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
private func updateVerificationBadge() async {
guard roomProxy.isDirectOneToOneRoom,
guard roomProxy.infoPublisher.value.isDM,
let dmRecipient = roomProxy.membersPublisher.value.first(where: { $0.userID != roomProxy.ownUserID }),
case let .success(userIdentity) = await clientProxy.userIdentity(for: dmRecipient.userID, fallBackToServer: true) else {
state.dmRecipientVerificationState = .notVerified
@@ -338,6 +338,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
state.hasOngoingCall = roomInfo.hasRoomCall
state.activeRoomCallIntent = roomInfo.activeRoomCallIntent
state.hasSuccessor = roomInfo.successor != nil
state.isDM = roomInfo.isDM
let pinnedEventIDs = roomInfo.pinnedEventIDs
// Only update the loading state of the banner
@@ -345,7 +346,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
state.pinnedEventsBannerState = .loading(numbersOfEvents: pinnedEventIDs.count)
}
switch (roomProxy.isDirectOneToOneRoom, roomInfo.joinRule) {
switch (roomInfo.isDM, roomInfo.joinRule) {
case (false, .knock), (false, .knockRestricted):
state.isKnockableRoom = true
default:
@@ -22,7 +22,7 @@ struct RoomCallControlsToolbar: ToolbarContent {
.disabled(!viewState.canJoinCall)
}
} else {
if viewState.isDirectOneToOneRoom {
if viewState.isDM {
if viewState.roomThreadListEnabled {
// If the developer mode room thread list option is enabled there
// is not enough place for 2 calls buttons
@@ -85,11 +85,11 @@ struct RoomCallControlsToolbar_Previews: PreviewProvider {
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: true)) { _ in } }
}
ElementNavigationStack {
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: false, isDirectOneToOneRoom: true)) { _ in } }
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: false, isDM: true)) { _ in } }
}
ElementNavigationStack {
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: false, isDirectOneToOneRoom: true, roomThreadListEnabled: true)) { _ in } }
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: false, isDM: true, roomThreadListEnabled: true)) { _ in } }
}
ElementNavigationStack {
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: false)) { _ in } }
@@ -106,12 +106,12 @@ struct RoomCallControlsToolbar_Previews: PreviewProvider {
}
private extension RoomScreenViewState {
static func mock(hasOngoingCall: Bool, isDirectOneToOneRoom: Bool = false, canJoinCall: Bool = true, activeRoomCallIntent: CallIntent? = nil, roomThreadListEnabled: Bool = false) -> RoomScreenViewState {
static func mock(hasOngoingCall: Bool, isDM: Bool = false, canJoinCall: Bool = true, activeRoomCallIntent: CallIntent? = nil, roomThreadListEnabled: Bool = false) -> RoomScreenViewState {
RoomScreenViewState(roomAvatar: .room(id: "mock", name: "Mock Room", avatarURL: nil),
canJoinCall: canJoinCall,
hasOngoingCall: hasOngoingCall,
activeRoomCallIntent: activeRoomCallIntent,
isDirectOneToOneRoom: isDirectOneToOneRoom,
isDM: isDM,
roomThreadListEnabled: roomThreadListEnabled,
hasSuccessor: false)
}