Skip to content

Commit de62618

Browse files
authored
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).
1 parent 3dc6d73 commit de62618

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,9 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
627627
stateMachine.tryEvent(.presentKnockRequestsListScreen)
628628
case .presentThread(let itemID):
629629
stateMachine.tryEvent(.presentThread(itemID: itemID))
630-
case .presentRoom(roomID: let roomID):
630+
case .presentRoom(let roomID, let via):
631631
stateMachine.tryEvent(.startChildFlow(roomID: roomID,
632-
via: [],
632+
via: via,
633633
entryPoint: .room))
634634
}
635635
}

ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum RoomScreenCoordinatorAction {
4646
case presentResolveSendFailure(failure: TimelineItemSendFailure.VerifiedUser, sendHandle: SendHandleProxy)
4747
case presentKnockRequestsList
4848
case presentThread(itemID: TimelineItemIdentifier)
49-
case presentRoom(roomID: String)
49+
case presentRoom(roomID: String, via: [String])
5050
}
5151

5252
final class RoomScreenCoordinator: CoordinatorProtocol {
@@ -148,8 +148,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
148148
composerViewModel.process(timelineAction: action)
149149
case .hasScrolled(direction: let direction):
150150
roomViewModel.timelineHasScrolled(direction: direction)
151-
case .displayRoom(let roomID):
152-
actionsSubject.send(.presentRoom(roomID: roomID))
151+
case .displayRoom(let roomID, let via):
152+
actionsSubject.send(.presentRoom(roomID: roomID, via: via))
153153
case .viewInRoomTimeline:
154154
fatalError("The action: \(action) should not be sent to this coordinator")
155155
}
@@ -181,8 +181,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
181181
composerViewModel.process(timelineAction: .removeFocus)
182182
case .displayKnockRequests:
183183
actionsSubject.send(.presentKnockRequestsList)
184-
case .displayRoom(let roomID):
185-
actionsSubject.send(.presentRoom(roomID: roomID))
184+
case .displayRoom(let roomID, let via):
185+
actionsSubject.send(.presentRoom(roomID: roomID, via: via))
186186
}
187187
}
188188
.store(in: &cancellables)

ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum RoomScreenViewModelAction: Equatable {
1515
case displayCall
1616
case removeComposerFocus
1717
case displayKnockRequests
18-
case displayRoom(roomID: String)
18+
case displayRoom(roomID: String, via: [String])
1919
}
2020

2121
enum RoomScreenViewAction {

ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Please see LICENSE files in the repository root for full details.
66
//
77

8+
import Algorithms
89
import Combine
910
import Foundation
1011
import MatrixRustSDK
@@ -117,7 +118,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
117118
actionsSubject.send(.displayKnockRequests)
118119
case .displaySuccessorRoom:
119120
guard let successorID = roomProxy.infoPublisher.value.successor?.roomId else { return }
120-
actionsSubject.send(.displayRoom(roomID: successorID))
121+
let serverNames = roomProxy.knownServerNames(maxCount: 50) // Limit to the same number used by ClientProxy.resolveRoomAlias(_:)
122+
actionsSubject.send(.displayRoom(roomID: successorID, via: Array(serverNames)))
121123
}
122124
}
123125

ElementX/Sources/Screens/Timeline/TimelineModels.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum TimelineViewModelAction {
2828
case composer(action: TimelineComposerAction)
2929
case hasScrolled(direction: ScrollDirection)
3030
case viewInRoomTimeline(eventID: String)
31-
case displayRoom(roomID: String)
31+
case displayRoom(roomID: String, via: [String])
3232
}
3333

3434
enum TimelineViewPollAction {

ElementX/Sources/Screens/Timeline/TimelineViewModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
214214
guard let predecessorID = roomProxy.predecessorRoom?.roomId else {
215215
fatalError("Predecessor room should exist if this action is triggered.")
216216
}
217-
actionsSubject.send(.displayRoom(roomID: predecessorID))
217+
let serverNames = roomProxy.knownServerNames(maxCount: 50) // Limit to the same number used by ClientProxy.resolveRoomAlias(_:)
218+
actionsSubject.send(.displayRoom(roomID: predecessorID, via: Array(serverNames)))
218219
}
219220
}
220221

ElementX/Sources/Services/Room/RoomProxyProtocol.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,13 @@ extension JoinedRoomProxyProtocol {
200200
await updateMembers()
201201
return membersPublisher.value
202202
}
203+
204+
// This is a horrible workaround for not having any server names available when using tombstone links with v12 room IDs.
205+
func knownServerNames(maxCount: Int) -> any Sequence<String> {
206+
membersPublisher.value
207+
.prefix(1000) // No need to go crazy here…
208+
.compactMap { $0.userID.split(separator: ":").last.map(String.init) }
209+
.uniqued()
210+
.prefix(maxCount)
211+
}
203212
}

0 commit comments

Comments
 (0)