|
|
|
@ -9,6 +9,9 @@ import PromiseKit
|
|
|
|
|
// • Document the expected cases for everything.
|
|
|
|
|
// • Express those cases in tests.
|
|
|
|
|
|
|
|
|
|
// FIXME: We're manually attaching the sender certificate and UD recipient access to message sends in a lot of places. It'd be great
|
|
|
|
|
// to clean this up and just do it in one spot.
|
|
|
|
|
|
|
|
|
|
@objc(LKMultiDeviceProtocol)
|
|
|
|
|
public final class MultiDeviceProtocol : NSObject {
|
|
|
|
|
|
|
|
|
@ -46,9 +49,15 @@ public final class MultiDeviceProtocol : NSObject {
|
|
|
|
|
storage.dbReadConnection.read { transaction in
|
|
|
|
|
recipient = SignalRecipient.getOrBuildUnsavedRecipient(forRecipientId: destination.hexEncodedPublicKey, transaction: transaction)
|
|
|
|
|
}
|
|
|
|
|
// TODO: Why is it okay that the thread, sender certificate, etc. don't get changed?
|
|
|
|
|
let udManager = SSKEnvironment.shared.udManager
|
|
|
|
|
let senderCertificate = udManager.getSenderCertificate()
|
|
|
|
|
var recipientUDAccess: OWSUDAccess?
|
|
|
|
|
if let senderCertificate = senderCertificate {
|
|
|
|
|
recipientUDAccess = udManager.udAccess(forRecipientId: destination.hexEncodedPublicKey, requireSyncAccess: true) // Starts a new write transaction internally
|
|
|
|
|
}
|
|
|
|
|
// TODO: Why is it okay that the thread doesn't get changed?
|
|
|
|
|
return OWSMessageSend(message: messageSend.message, thread: messageSend.thread, recipient: recipient,
|
|
|
|
|
senderCertificate: messageSend.senderCertificate, udAccess: messageSend.udAccess, localNumber: messageSend.localNumber, success: {
|
|
|
|
|
senderCertificate: senderCertificate, udAccess: recipientUDAccess, localNumber: messageSend.localNumber, success: {
|
|
|
|
|
seal.fulfill(())
|
|
|
|
|
}, failure: { error in
|
|
|
|
|
seal.reject(error)
|
|
|
|
@ -67,7 +76,7 @@ public final class MultiDeviceProtocol : NSObject {
|
|
|
|
|
threadPromiseSeal.fulfill(thread)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return threadPromise.then(on: OWSDispatch.sendingQueue()) { thread -> Promise<Void> in
|
|
|
|
|
return threadPromise.then(on: DispatchQueue.main) { thread -> Promise<Void> in // Intentionally the main queue
|
|
|
|
|
let message = messageSend.message
|
|
|
|
|
let messageSender = SSKEnvironment.shared.messageSender
|
|
|
|
|
let (promise, seal) = Promise<Void>.pending()
|
|
|
|
@ -76,7 +85,9 @@ public final class MultiDeviceProtocol : NSObject {
|
|
|
|
|
&& message.shouldBeSaved() // shouldBeSaved indicates it isn't a transient message
|
|
|
|
|
if !shouldSendAutoGeneratedFR {
|
|
|
|
|
let messageSendCopy = copy(messageSend, for: destination, with: seal)
|
|
|
|
|
messageSender.sendMessage(messageSendCopy)
|
|
|
|
|
OWSDispatch.sendingQueue().async {
|
|
|
|
|
messageSender.sendMessage(messageSendCopy)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Storage.write { transaction in
|
|
|
|
|
getAutoGeneratedMultiDeviceFRMessageSend(for: destination.hexEncodedPublicKey, in: transaction, seal: seal)
|
|
|
|
@ -131,10 +142,20 @@ public final class MultiDeviceProtocol : NSObject {
|
|
|
|
|
messageSend.failure(errors.first!)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.catch(on: OWSDispatch.sendingQueue()) { error in
|
|
|
|
|
}.catch(on: DispatchQueue.main) { error in // Intentionally the main queue
|
|
|
|
|
// Proceed even if updating the recipient's device links failed, so that message sending
|
|
|
|
|
// is independent of whether the file server is online
|
|
|
|
|
messageSender.sendMessage(messageSend)
|
|
|
|
|
let udManager = SSKEnvironment.shared.udManager
|
|
|
|
|
let senderCertificate = udManager.getSenderCertificate()
|
|
|
|
|
var recipientUDAccess: OWSUDAccess?
|
|
|
|
|
if let senderCertificate = senderCertificate {
|
|
|
|
|
recipientUDAccess = udManager.udAccess(forRecipientId: recipientID, requireSyncAccess: true) // Starts a new write transaction internally
|
|
|
|
|
}
|
|
|
|
|
messageSend.senderCertificate = senderCertificate
|
|
|
|
|
messageSend.udAccess = recipientUDAccess
|
|
|
|
|
OWSDispatch.sendingQueue().async {
|
|
|
|
|
messageSender.sendMessage(messageSend)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|