This commit is contained in:
Niels Andriesse 2020-12-03 10:53:30 +11:00
parent 7a8dbe1bf9
commit 00549a993f
2 changed files with 6 additions and 13 deletions

View File

@ -107,9 +107,7 @@ public final class MessageSender : NSObject {
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
NotificationCenter.default.post(name: .messageSendingFailed, object: NSNumber(value: message.sentTimestamp!))
}
transaction.addCompletionQueue(DispatchQueue.main) {
seal.reject(error)
}
seal.reject(error)
}
// Validate the message
guard message.isValid else { handleFailure(with: Error.invalidMessage, using: transaction); return promise }
@ -117,9 +115,8 @@ public final class MessageSender : NSObject {
guard !isSelfSend else {
storage.withAsync({ transaction in
MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
}, completion: {
seal.fulfill(())
})
}, completion: { })
return promise
}
// Attach the user's profile if needed
@ -224,9 +221,8 @@ public final class MessageSender : NSObject {
let notifyPNServerJob = NotifyPNServerJob(message: snodeMessage)
JobQueue.shared.add(notifyPNServerJob, using: transaction)
}
}, completion: {
seal.fulfill(())
})
}, completion: { })
}
$0.catch(on: DispatchQueue.global(qos: .userInitiated)) { error in
errorCount += 1
@ -264,9 +260,7 @@ public final class MessageSender : NSObject {
// Set the failure handler (need it here already for precondition failure handling)
func handleFailure(with error: Swift.Error, using transaction: YapDatabaseReadWriteTransaction) {
MessageSender.handleFailedMessageSend(message, with: error, using: transaction)
transaction.addCompletionQueue(DispatchQueue.main) {
seal.reject(error)
}
seal.reject(error)
}
// Validate the message
guard let message = message as? VisibleMessage else {
@ -291,9 +285,8 @@ public final class MessageSender : NSObject {
message.openGroupServerMessageID = openGroupMessage.serverID
storage.withAsync({ transaction in
MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
}, completion: {
seal.fulfill(())
})
}, completion: { })
}.catch(on: DispatchQueue.global(qos: .userInitiated)) { error in
storage.withAsync({ transaction in
handleFailure(with: error, using: transaction as! YapDatabaseReadWriteTransaction)

View File

@ -355,7 +355,7 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
private func generateSenderCertificate() -> Promise<(certificateData: Data, certificate: SMKSenderCertificate)> {
return Promise<(certificateData: Data, certificate: SMKSenderCertificate)> { seal in
// Loki: Generate a sender certificate locally
let sender = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
guard let sender = OWSIdentityManager.shared().identityKeyPair()?.hexEncodedPublicKey else { seal.reject(OWSUDError.assertionError(description: "")); return }
let certificate = SMKSenderCertificate(senderDeviceId: 1, senderRecipientId: sender)
let certificateAsData = try certificate.serialized()
guard isValidCertificate(certificate) else {