Skip to content

Commit

Permalink
Fix some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Oct 15, 2024
1 parent 236d142 commit ea70f1b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Other/Extensions/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Services/BugReport/BugReportService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ClientProxyError> {
do {
// TODO: Revisit once the SDK supports the knocking API
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Services/Client/ClientProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {

func createDirectRoom(with userID: String, expectedRoomName: String?) async -> Result<String, ClientProxyError>

// swiftlint:disable:next function_parameter_count
func createRoom(name: String, topic: String?, isRoomPrivate: Bool, isKnockingOnly: Bool, userIDs: [String], avatarURL: URL?) async -> Result<String, ClientProxyError>

func joinRoom(_ roomID: String, via: [String]) async -> Result<Void, ClientProxyError>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
switch action {
case .roomInfoUpdate:
return (roomProxy.hasOngoingCall, roomProxy.activeRoomCallParticipants)
default:
return nil
}
}
.removeDuplicates { $0 == $1 }
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Timeline/TimelineItemProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ struct TimelineItemDebugInfo: Identifiable, CustomStringConvertible {
return nil
}

return String(decoding: jsonData, as: UTF8.self)
return String(data: jsonData, encoding: .utf8)
}
}

Expand Down
10 changes: 5 additions & 5 deletions ElementX/Sources/UITests/UITestsSignalling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 }

Expand Down

0 comments on commit ea70f1b

Please sign in to comment.