mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
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:
@@ -156,7 +156,7 @@ class TimelineMediaPreviewViewModel: TimelineMediaPreviewViewModelType {
|
||||
canCurrentUserRedactOthers: timelineContext.viewState.canCurrentUserRedactOthers,
|
||||
canCurrentUserPin: timelineContext.viewState.canCurrentUserPin,
|
||||
pinnedEventIDs: timelineContext.viewState.pinnedEventIDs,
|
||||
isDM: timelineContext.viewState.isDirectOneToOneRoom,
|
||||
isDM: timelineContext.viewState.isDM,
|
||||
isViewSourceEnabled: timelineContext.viewState.isViewSourceEnabled,
|
||||
areThreadsEnabled: timelineContext.viewState.areThreadsEnabled,
|
||||
timelineKind: timelineContext.viewState.timelineKind,
|
||||
|
||||
@@ -404,12 +404,12 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
|
||||
guard roomProxy.infoPublisher.value.joinedMembersCount > 1 else {
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomID,
|
||||
isDM: roomProxy.isDirectOneToOneRoom,
|
||||
isDM: roomProxy.infoPublisher.value.isDM,
|
||||
state: roomProxy.infoPublisher.value.isPrivate ?? true ? .empty : .public)
|
||||
return
|
||||
}
|
||||
|
||||
if !roomProxy.isDirectOneToOneRoom {
|
||||
if !roomProxy.infoPublisher.value.isDM {
|
||||
if case let .success(ownMember) = await roomProxy.getMember(userID: roomProxy.ownUserID),
|
||||
ownMember.role.isOwner {
|
||||
await roomProxy.updateMembers()
|
||||
@@ -434,7 +434,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
}
|
||||
}
|
||||
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomID, isDM: roomProxy.isDirectOneToOneRoom, state: roomProxy.infoPublisher.value.isPrivate ?? true ? .private : .public)
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomID, isDM: roomProxy.infoPublisher.value.isDM, state: roomProxy.infoPublisher.value.isPrivate ?? true ? .private : .public)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
if case .space(let spaceServiceRoom) = source {
|
||||
switch spaceServiceRoom.state {
|
||||
case .invited:
|
||||
state.mode = .invited(isDM: spaceServiceRoom.isDirect == true && spaceServiceRoom.joinedMembersCount == 1)
|
||||
state.mode = .invited(isDM: spaceServiceRoom.isDM == true)
|
||||
case .knocked:
|
||||
state.mode = .knocked
|
||||
case .banned:
|
||||
|
||||
@@ -172,12 +172,12 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
|
||||
guard state.joinedMembersCount > 1 else {
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id,
|
||||
isDM: roomProxy.isDirectOneToOneRoom,
|
||||
isDM: roomProxy.infoPublisher.value.isDM,
|
||||
state: roomProxy.infoPublisher.value.isPrivate ?? true ? .empty : .public)
|
||||
return
|
||||
}
|
||||
|
||||
if !roomProxy.isDirectOneToOneRoom, state.accountOwner?.role.isOwner == true {
|
||||
if !roomProxy.infoPublisher.value.isDM, state.accountOwner?.role.isOwner == true {
|
||||
var isLastOwner = true
|
||||
for member in roomProxy.membersPublisher.value where member.userID != roomProxy.ownUserID && member.membership == .join {
|
||||
if member.role.isOwner {
|
||||
@@ -199,7 +199,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
}
|
||||
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id,
|
||||
isDM: roomProxy.isDirectOneToOneRoom,
|
||||
isDM: roomProxy.infoPublisher.value.isDM,
|
||||
state: roomProxy.infoPublisher.value.isPrivate ?? true ? .private : .public)
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
self.state.accountOwner = .init(withProxy: accountOwner)
|
||||
}
|
||||
|
||||
guard roomProxy.isDirectOneToOneRoom else {
|
||||
guard roomProxy.infoPublisher.value.isDM else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
return
|
||||
}
|
||||
|
||||
if roomProxy.isDirectOneToOneRoom {
|
||||
if roomProxy.infoPublisher.value.isDM {
|
||||
if var dmRecipientInfo = state.dmRecipientInfo {
|
||||
if case let .success(userIdentity) = await userSession.clientProxy.userIdentity(for: dmRecipientInfo.member.id, fallBackToServer: true) {
|
||||
dmRecipientInfo.verificationState = userIdentity?.verificationState
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTi
|
||||
// MARK: - Private
|
||||
|
||||
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 userSession.clientProxy.userIdentity(for: dmRecipient.userID, fallBackToServer: true) else {
|
||||
state.dmRecipientVerificationState = .notVerified
|
||||
|
||||
@@ -103,7 +103,7 @@ struct TimelineViewState: BindableState {
|
||||
var typingMembers: [String] = []
|
||||
var showLoading = false
|
||||
var showReadReceipts = false
|
||||
var isDirectOneToOneRoom = false
|
||||
var isDM = false
|
||||
var timelineState: TimelineState // check the doc before changing this
|
||||
|
||||
var ownUserID: String
|
||||
|
||||
@@ -95,7 +95,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
||||
}
|
||||
super.init(initialViewState: TimelineViewState(timelineKind: timelineController.timelineKind,
|
||||
roomID: roomProxy.id,
|
||||
isDirectOneToOneRoom: roomProxy.isDirectOneToOneRoom,
|
||||
isDM: roomProxy.infoPublisher.value.isDM,
|
||||
timelineState: TimelineState(focussedEvent: focussedEventID.map { .init(eventID: $0, appearance: .immediate) }),
|
||||
ownUserID: roomProxy.ownUserID,
|
||||
hideTimelineMedia: hideTimelineMedia,
|
||||
@@ -420,6 +420,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
||||
|
||||
private func updateRoomInfo(_ roomInfo: RoomInfoProxyProtocol) {
|
||||
state.pinnedEventIDs = roomInfo.pinnedEventIDs
|
||||
state.isDM = roomInfo.isDM
|
||||
|
||||
if let powerLevels = roomInfo.powerLevels {
|
||||
state.canCurrentUserSendMessage = powerLevels.canOwnUser(sendMessage: .roomMessage)
|
||||
|
||||
@@ -18,8 +18,8 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
||||
let adjustedDeliveryStatus: TimelineItemDeliveryStatus?
|
||||
@ViewBuilder let content: () -> Content
|
||||
|
||||
private var isDirectOneToOneRoom: Bool {
|
||||
context.viewState.isDirectOneToOneRoom
|
||||
private var isDM: Bool {
|
||||
context.viewState.isDM
|
||||
}
|
||||
|
||||
private var isFocussed: Bool {
|
||||
@@ -40,14 +40,14 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
||||
private let bubbleHorizontalPadding: CGFloat = 8
|
||||
/// Additional padding applied to outgoing bubbles when the avatar is shown
|
||||
private var bubbleAvatarPadding: CGFloat {
|
||||
guard !timelineItem.isOutgoing, !isDirectOneToOneRoom else { return 0 }
|
||||
guard !timelineItem.isOutgoing, !isDM else { return 0 }
|
||||
return 8
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .trailingFirstTextBaseline) {
|
||||
VStack(alignment: alignment, spacing: -12) {
|
||||
if !timelineItem.isOutgoing, !isDirectOneToOneRoom {
|
||||
if !timelineItem.isOutgoing, !isDM {
|
||||
header
|
||||
.zIndex(1)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
||||
canCurrentUserRedactOthers: context.viewState.canCurrentUserRedactOthers,
|
||||
canCurrentUserPin: context.viewState.canCurrentUserPin,
|
||||
pinnedEventIDs: context.viewState.pinnedEventIDs,
|
||||
isDM: context.viewState.isDirectOneToOneRoom,
|
||||
isDM: context.viewState.isDM,
|
||||
isViewSourceEnabled: context.viewState.isViewSourceEnabled,
|
||||
areThreadsEnabled: context.viewState.areThreadsEnabled,
|
||||
timelineKind: context.viewState.timelineKind,
|
||||
@@ -218,7 +218,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
||||
}
|
||||
|
||||
private var messageBubbleTopPadding: CGFloat {
|
||||
guard timelineItem.isOutgoing || isDirectOneToOneRoom else { return 0 }
|
||||
guard timelineItem.isOutgoing || isDM else { return 0 }
|
||||
return timelineGroupStyle == .single || timelineGroupStyle == .first ? 8 : 0
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ struct TimelineStartRoomTimelineView: View {
|
||||
upgradeDialogue
|
||||
}
|
||||
// We don't display the title for tombstoned DMs
|
||||
if context?.viewState.isDirectOneToOneRoom != true {
|
||||
if context?.viewState.isDM != true {
|
||||
Text(title)
|
||||
.font(.compound.bodySM)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
|
||||
@@ -34,7 +34,7 @@ struct TimelineView: View {
|
||||
canCurrentUserRedactOthers: timelineContext.viewState.canCurrentUserRedactOthers,
|
||||
canCurrentUserPin: timelineContext.viewState.canCurrentUserPin,
|
||||
pinnedEventIDs: timelineContext.viewState.pinnedEventIDs,
|
||||
isDM: timelineContext.viewState.isDirectOneToOneRoom,
|
||||
isDM: timelineContext.viewState.isDM,
|
||||
isViewSourceEnabled: timelineContext.viewState.isViewSourceEnabled,
|
||||
areThreadsEnabled: timelineContext.viewState.areThreadsEnabled,
|
||||
timelineKind: timelineContext.viewState.timelineKind,
|
||||
|
||||
Reference in New Issue
Block a user