Show a failure toast when alias look-up fails.

This commit is contained in:
Doug
2024-05-10 10:59:57 +01:00
committed by Stefan Ceriu
parent 1e0a6d76ae
commit 824190510f
5 changed files with 37 additions and 17 deletions
@@ -203,8 +203,10 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
case .room(let roomID, let via): case .room(let roomID, let via):
stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .room), userInfo: .init(animated: animated)) stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .room), userInfo: .init(animated: animated))
case .roomAlias(let alias): case .roomAlias(let alias):
guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } switch await userSession.clientProxy.resolveRoomAlias(alias) {
await asyncHandleAppRoute(.room(roomID: resolved.roomId, via: resolved.servers), animated: animated) case .success(let resolved): await asyncHandleAppRoute(.room(roomID: resolved.roomId, via: resolved.servers), animated: animated)
case .failure: showFailureIndicator()
}
case .childRoom(let roomID, let via): case .childRoom(let roomID, let via):
if let roomFlowCoordinator { if let roomFlowCoordinator {
roomFlowCoordinator.handleAppRoute(appRoute, animated: animated) roomFlowCoordinator.handleAppRoute(appRoute, animated: animated)
@@ -212,8 +214,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .room), userInfo: .init(animated: animated)) stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .room), userInfo: .init(animated: animated))
} }
case .childRoomAlias(let alias): case .childRoomAlias(let alias):
guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } switch await userSession.clientProxy.resolveRoomAlias(alias) {
await asyncHandleAppRoute(.childRoom(roomID: resolved.roomId, via: resolved.servers), animated: animated) case .success(let resolved): await asyncHandleAppRoute(.childRoom(roomID: resolved.roomId, via: resolved.servers), animated: animated)
case .failure: showFailureIndicator()
}
case .roomDetails(let roomID): case .roomDetails(let roomID):
if stateMachine.state.selectedRoomID == roomID { if stateMachine.state.selectedRoomID == roomID {
roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated) roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated)
@@ -227,13 +232,19 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
case .event(let eventID, let roomID, let via): case .event(let eventID, let roomID, let via):
stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .eventID(eventID)), userInfo: .init(animated: animated)) stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .eventID(eventID)), userInfo: .init(animated: animated))
case .eventOnRoomAlias(let eventID, let alias): case .eventOnRoomAlias(let eventID, let alias):
guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } switch await userSession.clientProxy.resolveRoomAlias(alias) {
await asyncHandleAppRoute(.event(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated) case .success(let resolved): await asyncHandleAppRoute(.event(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated)
case .failure: showFailureIndicator()
}
case .childEvent: case .childEvent:
roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated) roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated)
case .childEventOnRoomAlias(let eventID, let alias): case .childEventOnRoomAlias(let eventID, let alias):
guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } switch await userSession.clientProxy.resolveRoomAlias(alias) {
await asyncHandleAppRoute(.childEvent(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated) case .success(let resolved): await asyncHandleAppRoute(.childEvent(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated)
case .failure: showFailureIndicator()
}
case .userProfile(let userID): case .userProfile(let userID):
stateMachine.processEvent(.showUserProfileScreen(userID: userID), userInfo: .init(animated: animated)) stateMachine.processEvent(.showUserProfileScreen(userID: userID), userInfo: .init(animated: animated))
case .genericCallLink(let url): case .genericCallLink(let url):
@@ -682,6 +693,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// MARK: Toasts and loading indicators // MARK: Toasts and loading indicators
private static let loadingIndicatorIdentifier = "\(UserSessionFlowCoordinator.self)-Loading" private static let loadingIndicatorIdentifier = "\(UserSessionFlowCoordinator.self)-Loading"
private static let failureIndicatorIdentifier = "\(UserSessionFlowCoordinator.self)-Failure"
private func showLoadingIndicator(delay: Duration? = nil) { private func showLoadingIndicator(delay: Duration? = nil) {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier, ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
@@ -694,4 +706,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
private func hideLoadingIndicator() { private func hideLoadingIndicator() {
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier) ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
} }
private func showFailureIndicator() {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorIdentifier,
type: .toast,
title: L10n.errorUnknown,
iconName: "xmark"))
}
} }
@@ -3431,13 +3431,13 @@ class ClientProxyMock: ClientProxyProtocol {
var resolveRoomAliasReceivedAlias: String? var resolveRoomAliasReceivedAlias: String?
var resolveRoomAliasReceivedInvocations: [String] = [] var resolveRoomAliasReceivedInvocations: [String] = []
var resolveRoomAliasUnderlyingReturnValue: ResolvedRoomAlias? var resolveRoomAliasUnderlyingReturnValue: Result<ResolvedRoomAlias, ClientProxyError>!
var resolveRoomAliasReturnValue: ResolvedRoomAlias? { var resolveRoomAliasReturnValue: Result<ResolvedRoomAlias, ClientProxyError>! {
get { get {
if Thread.isMainThread { if Thread.isMainThread {
return resolveRoomAliasUnderlyingReturnValue return resolveRoomAliasUnderlyingReturnValue
} else { } else {
var returnValue: ResolvedRoomAlias?? = nil var returnValue: Result<ResolvedRoomAlias, ClientProxyError>? = nil
DispatchQueue.main.sync { DispatchQueue.main.sync {
returnValue = resolveRoomAliasUnderlyingReturnValue returnValue = resolveRoomAliasUnderlyingReturnValue
} }
@@ -3455,9 +3455,9 @@ class ClientProxyMock: ClientProxyProtocol {
} }
} }
} }
var resolveRoomAliasClosure: ((String) async -> ResolvedRoomAlias?)? var resolveRoomAliasClosure: ((String) async -> Result<ResolvedRoomAlias, ClientProxyError>)?
func resolveRoomAlias(_ alias: String) async -> ResolvedRoomAlias? { func resolveRoomAlias(_ alias: String) async -> Result<ResolvedRoomAlias, ClientProxyError> {
resolveRoomAliasCallsCount += 1 resolveRoomAliasCallsCount += 1
resolveRoomAliasReceivedAlias = alias resolveRoomAliasReceivedAlias = alias
resolveRoomAliasReceivedInvocations.append(alias) resolveRoomAliasReceivedInvocations.append(alias)
@@ -569,12 +569,12 @@ class ClientProxy: ClientProxyProtocol {
RoomDirectorySearchProxy(roomDirectorySearch: client.roomDirectorySearch()) RoomDirectorySearchProxy(roomDirectorySearch: client.roomDirectorySearch())
} }
func resolveRoomAlias(_ alias: String) async -> ResolvedRoomAlias? { func resolveRoomAlias(_ alias: String) async -> Result<ResolvedRoomAlias, ClientProxyError> {
do { do {
return try await client.resolveRoomAlias(roomAlias: alias) return try await .success(client.resolveRoomAlias(roomAlias: alias))
} catch { } catch {
MXLog.error("Failed resolving room alias: \(alias) with error: \(error)") MXLog.error("Failed resolving room alias: \(alias) with error: \(error)")
return nil return .failure(.sdkError(error))
} }
} }
@@ -159,7 +159,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
func roomDirectorySearchProxy() -> RoomDirectorySearchProxyProtocol func roomDirectorySearchProxy() -> RoomDirectorySearchProxyProtocol
func resolveRoomAlias(_ alias: String) async -> ResolvedRoomAlias? func resolveRoomAlias(_ alias: String) async -> Result<ResolvedRoomAlias, ClientProxyError>
// MARK: - Ignored users // MARK: - Ignored users
+1
View File
@@ -0,0 +1 @@
Show a failure toast when alias look-up fails.