From 824190510fd1d375ae15ca41b30f27756ab96276 Mon Sep 17 00:00:00 2001 From: Doug Date: Fri, 10 May 2024 10:59:57 +0100 Subject: [PATCH] Show a failure toast when alias look-up fails. --- .../UserSessionFlowCoordinator.swift | 35 ++++++++++++++----- .../Mocks/Generated/GeneratedMocks.swift | 10 +++--- .../Sources/Services/Client/ClientProxy.swift | 6 ++-- .../Services/Client/ClientProxyProtocol.swift | 2 +- changelog.d/2825.bugfix | 1 + 5 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 changelog.d/2825.bugfix diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index b94c10f87..092c7c269 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -203,8 +203,10 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { case .room(let roomID, let via): stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .room), userInfo: .init(animated: animated)) case .roomAlias(let alias): - guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } - await asyncHandleAppRoute(.room(roomID: resolved.roomId, via: resolved.servers), animated: animated) + switch await userSession.clientProxy.resolveRoomAlias(alias) { + case .success(let resolved): await asyncHandleAppRoute(.room(roomID: resolved.roomId, via: resolved.servers), animated: animated) + case .failure: showFailureIndicator() + } case .childRoom(let roomID, let via): if let roomFlowCoordinator { 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)) } case .childRoomAlias(let alias): - guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } - await asyncHandleAppRoute(.childRoom(roomID: resolved.roomId, via: resolved.servers), animated: animated) + switch await userSession.clientProxy.resolveRoomAlias(alias) { + case .success(let resolved): await asyncHandleAppRoute(.childRoom(roomID: resolved.roomId, via: resolved.servers), animated: animated) + case .failure: showFailureIndicator() + } + case .roomDetails(let roomID): if stateMachine.state.selectedRoomID == roomID { roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated) @@ -227,13 +232,19 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { case .event(let eventID, let roomID, let via): stateMachine.processEvent(.selectRoom(roomID: roomID, via: via, entryPoint: .eventID(eventID)), userInfo: .init(animated: animated)) case .eventOnRoomAlias(let eventID, let alias): - guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } - await asyncHandleAppRoute(.event(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated) + switch await userSession.clientProxy.resolveRoomAlias(alias) { + case .success(let resolved): await asyncHandleAppRoute(.event(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated) + case .failure: showFailureIndicator() + } + case .childEvent: roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated) case .childEventOnRoomAlias(let eventID, let alias): - guard let resolved = await userSession.clientProxy.resolveRoomAlias(alias) else { return } - await asyncHandleAppRoute(.childEvent(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated) + switch await userSession.clientProxy.resolveRoomAlias(alias) { + case .success(let resolved): await asyncHandleAppRoute(.childEvent(eventID: eventID, roomID: resolved.roomId, via: resolved.servers), animated: animated) + case .failure: showFailureIndicator() + } + case .userProfile(let userID): stateMachine.processEvent(.showUserProfileScreen(userID: userID), userInfo: .init(animated: animated)) case .genericCallLink(let url): @@ -682,6 +693,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { // MARK: Toasts and loading indicators private static let loadingIndicatorIdentifier = "\(UserSessionFlowCoordinator.self)-Loading" + private static let failureIndicatorIdentifier = "\(UserSessionFlowCoordinator.self)-Failure" private func showLoadingIndicator(delay: Duration? = nil) { ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier, @@ -694,4 +706,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { private func hideLoadingIndicator() { ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier) } + + private func showFailureIndicator() { + ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorIdentifier, + type: .toast, + title: L10n.errorUnknown, + iconName: "xmark")) + } } diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 866ef644f..c9a2bec1d 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -3431,13 +3431,13 @@ class ClientProxyMock: ClientProxyProtocol { var resolveRoomAliasReceivedAlias: String? var resolveRoomAliasReceivedInvocations: [String] = [] - var resolveRoomAliasUnderlyingReturnValue: ResolvedRoomAlias? - var resolveRoomAliasReturnValue: ResolvedRoomAlias? { + var resolveRoomAliasUnderlyingReturnValue: Result! + var resolveRoomAliasReturnValue: Result! { get { if Thread.isMainThread { return resolveRoomAliasUnderlyingReturnValue } else { - var returnValue: ResolvedRoomAlias?? = nil + var returnValue: Result? = nil DispatchQueue.main.sync { returnValue = resolveRoomAliasUnderlyingReturnValue } @@ -3455,9 +3455,9 @@ class ClientProxyMock: ClientProxyProtocol { } } } - var resolveRoomAliasClosure: ((String) async -> ResolvedRoomAlias?)? + var resolveRoomAliasClosure: ((String) async -> Result)? - func resolveRoomAlias(_ alias: String) async -> ResolvedRoomAlias? { + func resolveRoomAlias(_ alias: String) async -> Result { resolveRoomAliasCallsCount += 1 resolveRoomAliasReceivedAlias = alias resolveRoomAliasReceivedInvocations.append(alias) diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 61d1dd99a..ee8263630 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -569,12 +569,12 @@ class ClientProxy: ClientProxyProtocol { RoomDirectorySearchProxy(roomDirectorySearch: client.roomDirectorySearch()) } - func resolveRoomAlias(_ alias: String) async -> ResolvedRoomAlias? { + func resolveRoomAlias(_ alias: String) async -> Result { do { - return try await client.resolveRoomAlias(roomAlias: alias) + return try await .success(client.resolveRoomAlias(roomAlias: alias)) } catch { MXLog.error("Failed resolving room alias: \(alias) with error: \(error)") - return nil + return .failure(.sdkError(error)) } } diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index 7e2d6126a..4d3e546a5 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -159,7 +159,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol { func roomDirectorySearchProxy() -> RoomDirectorySearchProxyProtocol - func resolveRoomAlias(_ alias: String) async -> ResolvedRoomAlias? + func resolveRoomAlias(_ alias: String) async -> Result // MARK: - Ignored users diff --git a/changelog.d/2825.bugfix b/changelog.d/2825.bugfix new file mode 100644 index 000000000..f93257c8f --- /dev/null +++ b/changelog.d/2825.bugfix @@ -0,0 +1 @@ +Show a failure toast when alias look-up fails. \ No newline at end of file