From de626186bd7706196c444defb8eb15211229e95f Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Thu, 14 Aug 2025 13:02:07 +0100 Subject: [PATCH] Add a workaround to include some via parameters for room v12 tombstone links. (#4413) Without them, following the link fails as previously the server could use the server name from the room ID (which in and of itself seems somewhat error prone). --- .../Sources/FlowCoordinators/RoomFlowCoordinator.swift | 4 ++-- .../Screens/RoomScreen/RoomScreenCoordinator.swift | 10 +++++----- .../Sources/Screens/RoomScreen/RoomScreenModels.swift | 2 +- .../Screens/RoomScreen/RoomScreenViewModel.swift | 4 +++- ElementX/Sources/Screens/Timeline/TimelineModels.swift | 2 +- .../Sources/Screens/Timeline/TimelineViewModel.swift | 3 ++- ElementX/Sources/Services/Room/RoomProxyProtocol.swift | 9 +++++++++ 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index 0b94a8ef7..b2fea711b 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -627,9 +627,9 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { stateMachine.tryEvent(.presentKnockRequestsListScreen) case .presentThread(let itemID): stateMachine.tryEvent(.presentThread(itemID: itemID)) - case .presentRoom(roomID: let roomID): + case .presentRoom(let roomID, let via): stateMachine.tryEvent(.startChildFlow(roomID: roomID, - via: [], + via: via, entryPoint: .room)) } } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index f40741b08..584cc129e 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -46,7 +46,7 @@ enum RoomScreenCoordinatorAction { case presentResolveSendFailure(failure: TimelineItemSendFailure.VerifiedUser, sendHandle: SendHandleProxy) case presentKnockRequestsList case presentThread(itemID: TimelineItemIdentifier) - case presentRoom(roomID: String) + case presentRoom(roomID: String, via: [String]) } final class RoomScreenCoordinator: CoordinatorProtocol { @@ -148,8 +148,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol { composerViewModel.process(timelineAction: action) case .hasScrolled(direction: let direction): roomViewModel.timelineHasScrolled(direction: direction) - case .displayRoom(let roomID): - actionsSubject.send(.presentRoom(roomID: roomID)) + case .displayRoom(let roomID, let via): + actionsSubject.send(.presentRoom(roomID: roomID, via: via)) case .viewInRoomTimeline: fatalError("The action: \(action) should not be sent to this coordinator") } @@ -181,8 +181,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol { composerViewModel.process(timelineAction: .removeFocus) case .displayKnockRequests: actionsSubject.send(.presentKnockRequestsList) - case .displayRoom(let roomID): - actionsSubject.send(.presentRoom(roomID: roomID)) + case .displayRoom(let roomID, let via): + actionsSubject.send(.presentRoom(roomID: roomID, via: via)) } } .store(in: &cancellables) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 942cc799f..145c36041 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -15,7 +15,7 @@ enum RoomScreenViewModelAction: Equatable { case displayCall case removeComposerFocus case displayKnockRequests - case displayRoom(roomID: String) + case displayRoom(roomID: String, via: [String]) } enum RoomScreenViewAction { diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index ea95ac719..6366de349 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -5,6 +5,7 @@ // Please see LICENSE files in the repository root for full details. // +import Algorithms import Combine import Foundation import MatrixRustSDK @@ -117,7 +118,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol actionsSubject.send(.displayKnockRequests) case .displaySuccessorRoom: guard let successorID = roomProxy.infoPublisher.value.successor?.roomId else { return } - actionsSubject.send(.displayRoom(roomID: successorID)) + let serverNames = roomProxy.knownServerNames(maxCount: 50) // Limit to the same number used by ClientProxy.resolveRoomAlias(_:) + actionsSubject.send(.displayRoom(roomID: successorID, via: Array(serverNames))) } } diff --git a/ElementX/Sources/Screens/Timeline/TimelineModels.swift b/ElementX/Sources/Screens/Timeline/TimelineModels.swift index 894562e1d..4f1918f02 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineModels.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineModels.swift @@ -28,7 +28,7 @@ enum TimelineViewModelAction { case composer(action: TimelineComposerAction) case hasScrolled(direction: ScrollDirection) case viewInRoomTimeline(eventID: String) - case displayRoom(roomID: String) + case displayRoom(roomID: String, via: [String]) } enum TimelineViewPollAction { diff --git a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift index 091bd5802..374755d7c 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift @@ -214,7 +214,8 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol { guard let predecessorID = roomProxy.predecessorRoom?.roomId else { fatalError("Predecessor room should exist if this action is triggered.") } - actionsSubject.send(.displayRoom(roomID: predecessorID)) + let serverNames = roomProxy.knownServerNames(maxCount: 50) // Limit to the same number used by ClientProxy.resolveRoomAlias(_:) + actionsSubject.send(.displayRoom(roomID: predecessorID, via: Array(serverNames))) } } diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index 5203ff1ac..31f632515 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -200,4 +200,13 @@ extension JoinedRoomProxyProtocol { await updateMembers() return membersPublisher.value } + + // This is a horrible workaround for not having any server names available when using tombstone links with v12 room IDs. + func knownServerNames(maxCount: Int) -> any Sequence { + membersPublisher.value + .prefix(1000) // No need to go crazy here… + .compactMap { $0.userID.split(separator: ":").last.map(String.init) } + .uniqued() + .prefix(maxCount) + } }