wip
This commit is contained in:
parent
f3aabc34e8
commit
c69e7e50cf
|
@ -102,8 +102,9 @@ extension Client {
|
|||
return
|
||||
}
|
||||
|
||||
let msg = chat.createMessage(text: message.body ?? "??", id: message.id)
|
||||
var msg = chat.createMessage(text: message.body ?? "??", id: message.id)
|
||||
msg.oob = message.oobUrl
|
||||
msg = try await encryptMessage(msg)
|
||||
try await chat.send(message: msg)
|
||||
}
|
||||
|
||||
|
@ -151,6 +152,33 @@ extension Client {
|
|||
}
|
||||
}
|
||||
|
||||
private extension Client {
|
||||
func encryptMessage(_ message: Martin.Message) async throws -> Martin.Message {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
connection.module(.omemo).encode(message: message, completionHandler: { result in
|
||||
switch result {
|
||||
case .successMessage(let encodedMessage, _):
|
||||
// guard connection.isConnected else {
|
||||
// continuation.resume(returning: message)
|
||||
// return
|
||||
// }
|
||||
continuation.resume(returning: encodedMessage)
|
||||
|
||||
case .failure(let error):
|
||||
var errorMessage = NSLocalizedString("It was not possible to send encrypted message due to encryption error", comment: "message encryption failure")
|
||||
switch error {
|
||||
case .noSession:
|
||||
errorMessage = NSLocalizedString("There is no trusted device to send message to", comment: "message encryption failure")
|
||||
default:
|
||||
break
|
||||
}
|
||||
continuation.resume(throwing: XMPPError.unexpected_request(errorMessage))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Client {
|
||||
static func tryLogin(with credentials: Credentials) async throws -> Client {
|
||||
let client = Client(credentials: credentials)
|
||||
|
|
Loading…
Reference in a new issue