Files
Morgan Pretty eddffae6a1 Refactored a number of processes to no longer require database access
• Refactored the MessageSender to no longer require database access
• Refactored the attachment upload process to no longer require database access
• Updated the OpenGroupAPI to no longer require database access
• Added back logic to send the `endCall` message when receiving a call while on another call
• Added `community` to `AuthenticationMethod` to help standardise the code behaviour
• Updated the `toProto` functions to no longer required a `Database` instance
• Updated a bunch of functions to be @MainActor (so we can ditch thread swapping code)
2025-06-03 08:51:05 +10:00

89 lines
4.3 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import Foundation
import SessionUtilitiesKit
public enum MessageSenderError: Error, CustomStringConvertible, Equatable {
case invalidMessage
case protoConversionFailed
case noUserX25519KeyPair
case noUserED25519KeyPair
case signingFailed
case encryptionFailed
case noUsername
case attachmentsNotUploaded
case attachmentsInvalid
case blindingFailed
// Closed groups
case noThread
case noKeyPair
case invalidClosedGroupUpdate
case invalidConfigMessageHandling
case deprecatedLegacyGroup
case other(Log.Category?, String, Error)
internal var isRetryable: Bool {
switch self {
case .invalidMessage, .protoConversionFailed, .invalidClosedGroupUpdate,
.signingFailed, .encryptionFailed, .blindingFailed:
return false
default: return true
}
}
public var description: String {
switch self {
case .invalidMessage: return "Invalid message (MessageSenderError.invalidMessage)."
case .protoConversionFailed: return "Couldn't convert message to proto (MessageSenderError.protoConversionFailed)."
case .noUserX25519KeyPair: return "Couldn't find user X25519 key pair (MessageSenderError.noUserX25519KeyPair)."
case .noUserED25519KeyPair: return "Couldn't find user ED25519 key pair (MessageSenderError.noUserED25519KeyPair)."
case .signingFailed: return "Couldn't sign message (MessageSenderError.signingFailed)."
case .encryptionFailed: return "Couldn't encrypt message (MessageSenderError.encryptionFailed)."
case .noUsername: return "Missing username (MessageSenderError.noUsername)."
case .attachmentsNotUploaded: return "Attachments for this message have not been uploaded (MessageSenderError.attachmentsNotUploaded)."
case .attachmentsInvalid: return "Attachments Invalid (MessageSenderError.attachmentsInvalid)."
case .blindingFailed: return "Couldn't blind the sender (MessageSenderError.blindingFailed)."
// Closed groups
case .noThread: return "Couldn't find a thread associated with the given group public key (MessageSenderError.noThread)."
case .noKeyPair: return "Couldn't find a private key associated with the given group public key (MessageSenderError.noKeyPair)."
case .invalidClosedGroupUpdate: return "Invalid group update (MessageSenderError.invalidClosedGroupUpdate)."
case .invalidConfigMessageHandling: return "Invalid handling of a config message (MessageSenderError.invalidConfigMessageHandling)."
case .deprecatedLegacyGroup: return "Tried to send a message for a deprecated legacy group (MessageSenderError.deprecatedLegacyGroup)."
case .other(_, _, let error): return "\(error)"
}
}
public static func == (lhs: MessageSenderError, rhs: MessageSenderError) -> Bool {
switch (lhs, rhs) {
case (.invalidMessage, .invalidMessage): return true
case (.protoConversionFailed, .protoConversionFailed): return true
case (.noUserX25519KeyPair, .noUserX25519KeyPair): return true
case (.noUserED25519KeyPair, .noUserED25519KeyPair): return true
case (.signingFailed, .signingFailed): return true
case (.encryptionFailed, .encryptionFailed): return true
case (.noUsername, .noUsername): return true
case (.attachmentsNotUploaded, .attachmentsNotUploaded): return true
case (.noThread, .noThread): return true
case (.noKeyPair, .noKeyPair): return true
case (.invalidClosedGroupUpdate, .invalidClosedGroupUpdate): return true
case (.deprecatedLegacyGroup, .deprecatedLegacyGroup): return true
case (.blindingFailed, .blindingFailed): return true
case (.other(_, let lhsDescription, let lhsError), .other(_, let rhsDescription, let rhsError)):
// Not ideal but the best we can do
return (
lhsDescription == rhsDescription &&
"\(lhsError)" == "\(rhsError)"
)
default: return false
}
}
}