mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Prioritise joining rooms by alias if available and letting the homeserver do the right thing
This commit is contained in:
parent
a2faae20c2
commit
b73e5e9e5d
@ -2523,6 +2523,74 @@ class ClientProxyMock: ClientProxyProtocol {
|
|||||||
return joinRoomViaReturnValue
|
return joinRoomViaReturnValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//MARK: - joinRoomAlias
|
||||||
|
|
||||||
|
var joinRoomAliasUnderlyingCallsCount = 0
|
||||||
|
var joinRoomAliasCallsCount: Int {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return joinRoomAliasUnderlyingCallsCount
|
||||||
|
} else {
|
||||||
|
var returnValue: Int? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = joinRoomAliasUnderlyingCallsCount
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
joinRoomAliasUnderlyingCallsCount = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
joinRoomAliasUnderlyingCallsCount = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var joinRoomAliasCalled: Bool {
|
||||||
|
return joinRoomAliasCallsCount > 0
|
||||||
|
}
|
||||||
|
var joinRoomAliasReceivedRoomAlias: String?
|
||||||
|
var joinRoomAliasReceivedInvocations: [String] = []
|
||||||
|
|
||||||
|
var joinRoomAliasUnderlyingReturnValue: Result<Void, ClientProxyError>!
|
||||||
|
var joinRoomAliasReturnValue: Result<Void, ClientProxyError>! {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return joinRoomAliasUnderlyingReturnValue
|
||||||
|
} else {
|
||||||
|
var returnValue: Result<Void, ClientProxyError>? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = joinRoomAliasUnderlyingReturnValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
joinRoomAliasUnderlyingReturnValue = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
joinRoomAliasUnderlyingReturnValue = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var joinRoomAliasClosure: ((String) async -> Result<Void, ClientProxyError>)?
|
||||||
|
|
||||||
|
func joinRoomAlias(_ roomAlias: String) async -> Result<Void, ClientProxyError> {
|
||||||
|
joinRoomAliasCallsCount += 1
|
||||||
|
joinRoomAliasReceivedRoomAlias = roomAlias
|
||||||
|
joinRoomAliasReceivedInvocations.append(roomAlias)
|
||||||
|
if let joinRoomAliasClosure = joinRoomAliasClosure {
|
||||||
|
return await joinRoomAliasClosure(roomAlias)
|
||||||
|
} else {
|
||||||
|
return joinRoomAliasReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
//MARK: - uploadMedia
|
//MARK: - uploadMedia
|
||||||
|
|
||||||
var uploadMediaUnderlyingCallsCount = 0
|
var uploadMediaUnderlyingCallsCount = 0
|
||||||
|
@ -92,14 +92,25 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
|||||||
hideLoadingIndicator()
|
hideLoadingIndicator()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prioritise joining by the alias and letting the homeserver do the right thing
|
||||||
|
if let alias = state.roomDetails?.canonicalAlias {
|
||||||
|
switch await clientProxy.joinRoomAlias(alias) {
|
||||||
|
case .success:
|
||||||
|
actionsSubject.send(.joined)
|
||||||
|
case .failure(let error):
|
||||||
|
MXLog.error("Failed joining room alias: \(alias) with error: \(error)")
|
||||||
|
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
switch await clientProxy.joinRoom(roomID, via: via) {
|
switch await clientProxy.joinRoom(roomID, via: via) {
|
||||||
case .success:
|
case .success:
|
||||||
actionsSubject.send(.joined)
|
actionsSubject.send(.joined)
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
MXLog.error("Failed joining room with error: \(error)")
|
MXLog.error("Failed joining room id: \(roomID) with error: \(error)")
|
||||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func showDeclineInviteConfirmationAlert() {
|
private func showDeclineInviteConfirmationAlert() {
|
||||||
guard let roomDetails = state.roomDetails else {
|
guard let roomDetails = state.roomDetails else {
|
||||||
|
@ -385,6 +385,20 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func joinRoomAlias(_ roomAlias: String) async -> Result<Void, ClientProxyError> {
|
||||||
|
do {
|
||||||
|
let room = try await client.joinRoomByIdOrAlias(roomIdOrAlias: roomAlias, serverNames: [])
|
||||||
|
|
||||||
|
// Wait for the room to appear in the room lists to avoid issues downstream
|
||||||
|
let _ = await waitForRoomSummary(with: .success(room.id()), name: nil, timeout: 30)
|
||||||
|
|
||||||
|
return .success(())
|
||||||
|
} catch {
|
||||||
|
MXLog.error("Failed joining roomAlias: \(roomAlias) with error: \(error)")
|
||||||
|
return .failure(.sdkError(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
|
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
|
||||||
guard let mimeType = media.mimeType else {
|
guard let mimeType = media.mimeType else {
|
||||||
MXLog.error("Failed uploading media, invalid mime type: \(media)")
|
MXLog.error("Failed uploading media, invalid mime type: \(media)")
|
||||||
|
@ -131,6 +131,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
|||||||
|
|
||||||
func joinRoom(_ roomID: String, via: [String]) async -> Result<Void, ClientProxyError>
|
func joinRoom(_ roomID: String, via: [String]) async -> Result<Void, ClientProxyError>
|
||||||
|
|
||||||
|
func joinRoomAlias(_ roomAlias: String) async -> Result<Void, ClientProxyError>
|
||||||
|
|
||||||
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError>
|
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError>
|
||||||
|
|
||||||
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol?
|
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user