diff --git a/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift index 9425920ede..5edc7967dd 100644 --- a/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift @@ -137,33 +137,6 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol { bugReportFlowCoordinator?.start() } - // TODO: Move this method after showServerConfirmationScreen - private func showServerSelectionScreen(authenticationFlow: AuthenticationFlow) { - let navigationCoordinator = NavigationStackCoordinator() - - let parameters = ServerSelectionScreenCoordinatorParameters(authenticationService: authenticationService, - authenticationFlow: authenticationFlow, - slidingSyncLearnMoreURL: appSettings.slidingSyncLearnMoreURL, - userIndicatorController: userIndicatorController) - let coordinator = ServerSelectionScreenCoordinator(parameters: parameters) - - coordinator.actions - .sink { [weak self] action in - guard let self else { return } - - switch action { - case .updated: - navigationStackCoordinator.setSheetCoordinator(nil) - case .dismiss: - navigationStackCoordinator.setSheetCoordinator(nil) - } - } - .store(in: &cancellables) - - navigationCoordinator.setRootCoordinator(coordinator) - navigationStackCoordinator.setSheetCoordinator(navigationCoordinator) - } - private func showServerConfirmationScreen(authenticationFlow: AuthenticationFlow) { // Reset the service back to the default homeserver before continuing. This ensures // we check that registration is supported if it was previously configured for login. @@ -196,6 +169,32 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol { navigationStackCoordinator.push(coordinator) } + private func showServerSelectionScreen(authenticationFlow: AuthenticationFlow) { + let navigationCoordinator = NavigationStackCoordinator() + + let parameters = ServerSelectionScreenCoordinatorParameters(authenticationService: authenticationService, + authenticationFlow: authenticationFlow, + slidingSyncLearnMoreURL: appSettings.slidingSyncLearnMoreURL, + userIndicatorController: userIndicatorController) + let coordinator = ServerSelectionScreenCoordinator(parameters: parameters) + + coordinator.actions + .sink { [weak self] action in + guard let self else { return } + + switch action { + case .updated: + navigationStackCoordinator.setSheetCoordinator(nil) + case .dismiss: + navigationStackCoordinator.setSheetCoordinator(nil) + } + } + .store(in: &cancellables) + + navigationCoordinator.setRootCoordinator(coordinator) + navigationStackCoordinator.setSheetCoordinator(navigationCoordinator) + } + private func showWebRegistration() { let parameters = WebRegistrationScreenCoordinatorParameters(authenticationService: authenticationService, userIndicatorController: userIndicatorController) diff --git a/ElementX/Sources/Other/Extensions/Dictionary.swift b/ElementX/Sources/Other/Extensions/Dictionary.swift index 2fe7ddc8f3..14e064dcdd 100644 --- a/ElementX/Sources/Other/Extensions/Dictionary.swift +++ b/ElementX/Sources/Other/Extensions/Dictionary.swift @@ -13,7 +13,7 @@ extension Dictionary { options: [.fragmentsAllowed, .sortedKeys]) else { return nil } - return String(decoding: data, as: UTF8.self) + return String(data: data, encoding: .utf8) } /// Returns a dictionary containing the original values keyed by the results of mapping the given closure over its keys. diff --git a/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift b/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift index abbc817bb6..1e9e0315aa 100644 --- a/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift +++ b/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift @@ -213,14 +213,20 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol } private func postMessageToWidget(_ message: ElementCallWidgetMessage) async { + let data: Data do { - let data = try JSONEncoder().encode(message) - let json = String(decoding: data, as: UTF8.self) - - await postJSONToWidget(json) + data = try JSONEncoder().encode(message) } catch { MXLog.error("Failed encoding widget message with error: \(error)") + return } + + guard let json = String(data: data, encoding: .utf8) else { + MXLog.error("Invalid data for widget message") + return + } + + await postJSONToWidget(json) } private func postJSONToWidget(_ json: String) async { diff --git a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift index 39fde2fcda..da70c7afb2 100644 --- a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift +++ b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift @@ -93,7 +93,7 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol old.roomName == new.roomName && old.roomTopic == new.roomTopic && old.isRoomPrivate == new.isRoomPrivate } .sink { [weak self] bindings in - guard let self = self else { return } + guard let self else { return } updateParameters(bindings: bindings) actionsSubject.send(.updateDetails(createRoomParameters)) } diff --git a/ElementX/Sources/Services/BugReport/BugReportService.swift b/ElementX/Sources/Services/BugReport/BugReportService.swift index f263f653fb..75037c4b30 100644 --- a/ElementX/Sources/Services/BugReport/BugReportService.swift +++ b/ElementX/Sources/Services/BugReport/BugReportService.swift @@ -117,14 +117,14 @@ class BugReportService: NSObject, BugReportServiceProtocol { let (data, response) = try await session.dataWithRetry(for: request, delegate: self) guard let httpResponse = response as? HTTPURLResponse else { - let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines) + let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown error" MXLog.error("Failed to submit bug report: \(errorDescription)") MXLog.error("Response: \(response)") return .failure(.serverError(response, errorDescription)) } guard httpResponse.statusCode == 200 else { - let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines) + let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown error" MXLog.error("Failed to submit bug report: \(errorDescription) (\(httpResponse.statusCode))") MXLog.error("Response: \(httpResponse)") return .failure(.httpError(httpResponse, errorDescription)) diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 77d3ee585a..72a647283a 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -365,6 +365,7 @@ class ClientProxy: ClientProxyProtocol { } } + // swiftlint:disable:next function_parameter_count func createRoom(name: String, topic: String?, isRoomPrivate: Bool, isKnockingOnly: Bool, userIDs: [String], avatarURL: URL?) async -> Result { do { // TODO: Revisit once the SDK supports the knocking API diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index 0726ba83e6..e8160f2412 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -138,6 +138,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol { func createDirectRoom(with userID: String, expectedRoomName: String?) async -> Result + // swiftlint:disable:next function_parameter_count func createRoom(name: String, topic: String?, isRoomPrivate: Bool, isKnockingOnly: Bool, userIDs: [String], avatarURL: URL?) async -> Result func joinRoom(_ roomID: String, via: [String]) async -> Result diff --git a/ElementX/Sources/Services/ElementCall/ElementCallService.swift b/ElementX/Sources/Services/ElementCall/ElementCallService.swift index 049f4c49bf..f08a4e712a 100644 --- a/ElementX/Sources/Services/ElementCall/ElementCallService.swift +++ b/ElementX/Sources/Services/ElementCall/ElementCallService.swift @@ -299,8 +299,6 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe switch action { case .roomInfoUpdate: return (roomProxy.hasOngoingCall, roomProxy.activeRoomCallParticipants) - default: - return nil } } .removeDuplicates { $0 == $1 } diff --git a/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift b/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift index f2b84499a4..baced33cb3 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift @@ -208,7 +208,7 @@ struct TimelineItemDebugInfo: Identifiable, CustomStringConvertible { return nil } - return String(decoding: jsonData, as: UTF8.self) + return String(data: jsonData, encoding: .utf8) } } diff --git a/ElementX/Sources/UITests/UITestsSignalling.swift b/ElementX/Sources/UITests/UITestsSignalling.swift index 84f054e2ef..ece07bfb21 100644 --- a/ElementX/Sources/UITests/UITestsSignalling.swift +++ b/ElementX/Sources/UITests/UITestsSignalling.swift @@ -137,10 +137,11 @@ enum UITestsSignalling { let encoder = JSONEncoder() encoder.outputFormatting = .sortedKeys - guard let data = try? encoder.encode(self) else { + guard let data = try? encoder.encode(self), + let rawMessage = String(data: data, encoding: .utf8) else { return "unknown" } - return String(decoding: data, as: UTF8.self) + return rawMessage } init?(rawValue: String) { @@ -165,9 +166,8 @@ enum UITestsSignalling { /// Processes string data from the file and publishes its signal. private func processFileData(_ data: Data) { - let rawMessage = String(decoding: data, as: UTF8.self) - - guard let message = Message(rawValue: rawMessage), + guard let rawMessage = String(data: data, encoding: .utf8), + let message = Message(rawValue: rawMessage), message.mode != mode // Filter out messages sent by this client. else { return }