updated the SDK (#3737)

This commit is contained in:
Mauro
2025-02-04 17:57:39 +01:00
committed by GitHub
parent f0b8775701
commit 6c190cf735
8 changed files with 36 additions and 75 deletions
@@ -1,28 +0,0 @@
//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Foundation
import MatrixRustSDK
enum MatrixErrorCode: String, CaseIterable {
case unknown = "M_UNKNOWN"
case userDeactivated = "M_USER_DEACTIVATED"
case forbidden = "M_FORBIDDEN"
case fileTooLarge = "M_TOO_LARGE"
}
extension ClientError {
var code: MatrixErrorCode {
guard case let .Generic(message) = self else { return .unknown }
guard let first = MatrixErrorCode.allCases.first(where: { message.contains($0.rawValue) }) else {
return .unknown
}
return first
}
}
@@ -465,9 +465,9 @@ class ClientProxy: ClientProxyProtocol {
let data = try Data(contentsOf: media.url)
let matrixUrl = try await client.uploadMedia(mimeType: mimeType, data: data, progressWatcher: nil)
return .success(matrixUrl)
} catch let error as ClientError {
MXLog.error("Failed uploading media with error: \(error)")
return .failure(ClientProxyError.failedUploadingMedia(error, error.code))
} catch let ClientError.MatrixApi(errorKind, _, _) {
MXLog.error("Failed uploading media with error kind: \(errorKind)")
return .failure(ClientProxyError.failedUploadingMedia(errorKind))
} catch {
MXLog.error("Failed uploading media with error: \(error)")
return .failure(ClientProxyError.sdkError(error))
@@ -503,7 +503,8 @@ class ClientProxy: ClientProxyProtocol {
do {
let roomPreview = try await client.getRoomPreviewFromRoomId(roomId: identifier, viaServers: via)
return try .success(RoomPreviewProxy(roomPreview: roomPreview))
} catch let error as ClientError where error.code == .forbidden {
} catch ClientError.MatrixApi(.forbidden, _, _) {
MXLog.error("Failed retrieving preview for room: \(identifier) is private")
return .failure(.roomPreviewIsPrivate)
} catch {
MXLog.error("Failed retrieving preview for room: \(identifier) with error: \(error)")
@@ -33,7 +33,7 @@ enum ClientProxyError: Error {
case invalidMedia
case invalidServerName
case failedUploadingMedia(Error, MatrixErrorCode)
case failedUploadingMedia(ErrorKind)
case roomPreviewIsPrivate
case failedRetrievingUserIdentity
case failedResolvingRoomAlias