@ -9,9 +9,6 @@ import PromiseKit
// • D o c u m e n t t h e e x p e c t e d c a s e s f o r e v e r y t h i n g .
// • D o c u m e n t t h e e x p e c t e d c a s e s f o r e v e r y t h i n g .
// • E x p r e s s t h o s e c a s e s i n t e s t s .
// • E x p r e s s t h o s e c a s e s i n t e s t s .
// FIXME: W e ' r e m a n u a l l y a t t a c h i n g t h e s e n d e r c e r t i f i c a t e a n d U D r e c i p i e n t a c c e s s t o m e s s a g e s e n d s i n a l o t o f p l a c e s . I t ' d b e g r e a t
// t o c l e a n t h i s u p a n d j u s t d o i t i n o n e s p o t .
@objc ( LKMultiDeviceProtocol )
@objc ( LKMultiDeviceProtocol )
public final class MultiDeviceProtocol : NSObject {
public final class MultiDeviceProtocol : NSObject {
@ -45,15 +42,9 @@ public final class MultiDeviceProtocol : NSObject {
storage . dbReadConnection . read { transaction in
storage . dbReadConnection . read { transaction in
recipient = SignalRecipient . getOrBuildUnsavedRecipient ( forRecipientId : destination . hexEncodedPublicKey , transaction : transaction )
recipient = SignalRecipient . getOrBuildUnsavedRecipient ( forRecipientId : destination . hexEncodedPublicKey , transaction : transaction )
}
}
let udManager = SSKEnvironment . shared . udManager
// TODO: W h y i s i t o k a y t h a t t h e t h r e a d , s e n d e r c e r t i f i c a t e , e t c . d o n ' t g e t c h a n g e d ?
let senderCertificate = udManager . getSenderCertificate ( )
var recipientUDAccess : OWSUDAccess ?
if let senderCertificate = senderCertificate {
recipientUDAccess = udManager . udAccess ( forRecipientId : destination . hexEncodedPublicKey , requireSyncAccess : true ) // S t a r t s a n e w w r i t e t r a n s a c t i o n i n t e r n a l l y
}
// TODO: W h y i s i t o k a y t h a t t h e t h r e a d d o e s n ' t g e t c h a n g e d ?
return OWSMessageSend ( message : messageSend . message , thread : messageSend . thread , recipient : recipient ,
return OWSMessageSend ( message : messageSend . message , thread : messageSend . thread , recipient : recipient ,
senderCertificate : senderCertificate, udAccess : recipientUD Access, localNumber : messageSend . localNumber , success : {
senderCertificate : messageSend . senderCertificate , udAccess : messageSend . udAccess , localNumber : messageSend . localNumber , success : {
seal . fulfill ( ( ) )
seal . fulfill ( ( ) )
} , failure : { error in
} , failure : { error in
seal . reject ( error )
seal . reject ( error )
@ -73,6 +64,7 @@ public final class MultiDeviceProtocol : NSObject {
}
}
}
}
return threadPromise . then2 { thread -> Promise < Void > in
return threadPromise . then2 { thread -> Promise < Void > in
return threadPromise . then ( on : OWSDispatch . sendingQueue ( ) ) { thread -> Promise < Void > in
let message = messageSend . message
let message = messageSend . message
let messageSender = SSKEnvironment . shared . messageSender
let messageSender = SSKEnvironment . shared . messageSender
let ( promise , seal ) = Promise < Void > . pending ( )
let ( promise , seal ) = Promise < Void > . pending ( )
@ -81,9 +73,7 @@ public final class MultiDeviceProtocol : NSObject {
&& message . shouldBeSaved ( ) // s h o u l d B e S a v e d i n d i c a t e s i t i s n ' t a t r a n s i e n t m e s s a g e
&& message . shouldBeSaved ( ) // s h o u l d B e S a v e d i n d i c a t e s i t i s n ' t a t r a n s i e n t m e s s a g e
if ! shouldSendAutoGeneratedFR {
if ! shouldSendAutoGeneratedFR {
let messageSendCopy = copy ( messageSend , for : destination , with : seal )
let messageSendCopy = copy ( messageSend , for : destination , with : seal )
OWSDispatch . sendingQueue ( ) . async {
messageSender . sendMessage ( messageSendCopy )
messageSender . sendMessage ( messageSendCopy )
}
} else {
} else {
Storage . write { transaction in
Storage . write { transaction in
getAutoGeneratedMultiDeviceFRMessageSend ( for : destination . hexEncodedPublicKey , in : transaction , seal : seal )
getAutoGeneratedMultiDeviceFRMessageSend ( for : destination . hexEncodedPublicKey , in : transaction , seal : seal )
@ -141,19 +131,9 @@ public final class MultiDeviceProtocol : NSObject {
} . catch2 { error in
} . catch2 { error in
// P r o c e e d e v e n i f u p d a t i n g t h e r e c i p i e n t ' s d e v i c e l i n k s f a i l e d , s o t h a t m e s s a g e s e n d i n g
// P r o c e e d e v e n i f u p d a t i n g t h e r e c i p i e n t ' s d e v i c e l i n k s f a i l e d , s o t h a t m e s s a g e s e n d i n g
// i s i n d e p e n d e n t o f w h e t h e r t h e f i l e s e r v e r i s o n l i n e
// i s i n d e p e n d e n t o f w h e t h e r t h e f i l e s e r v e r i s o n l i n e
let udManager = SSKEnvironment . shared . udManager
let senderCertificate = udManager . getSenderCertificate ( )
var recipientUDAccess : OWSUDAccess ?
if let senderCertificate = senderCertificate {
recipientUDAccess = udManager . udAccess ( forRecipientId : recipientID , requireSyncAccess : true ) // S t a r t s a n e w w r i t e t r a n s a c t i o n i n t e r n a l l y
}
messageSend . senderCertificate = senderCertificate
messageSend . udAccess = recipientUDAccess
OWSDispatch . sendingQueue ( ) . async {
messageSender . sendMessage ( messageSend )
messageSender . sendMessage ( messageSend )
}
}
}
}
}
@objc ( updateDeviceLinksIfNeededForHexEncodedPublicKey : in : )
@objc ( updateDeviceLinksIfNeededForHexEncodedPublicKey : in : )
public static func updateDeviceLinksIfNeeded ( for hexEncodedPublicKey : String , in transaction : YapDatabaseReadTransaction ) -> AnyPromise {
public static func updateDeviceLinksIfNeeded ( for hexEncodedPublicKey : String , in transaction : YapDatabaseReadTransaction ) -> AnyPromise {
@ -165,9 +145,7 @@ public final class MultiDeviceProtocol : NSObject {
@objc ( getAutoGeneratedMultiDeviceFRMessageForHexEncodedPublicKey : in : )
@objc ( getAutoGeneratedMultiDeviceFRMessageForHexEncodedPublicKey : in : )
public static func getAutoGeneratedMultiDeviceFRMessage ( for hexEncodedPublicKey : String , in transaction : YapDatabaseReadWriteTransaction ) -> FriendRequestMessage {
public static func getAutoGeneratedMultiDeviceFRMessage ( for hexEncodedPublicKey : String , in transaction : YapDatabaseReadWriteTransaction ) -> FriendRequestMessage {
let thread = TSContactThread . getOrCreateThread ( withContactId : hexEncodedPublicKey , transaction : transaction )
let thread = TSContactThread . getOrCreateThread ( withContactId : hexEncodedPublicKey , transaction : transaction )
let result = FriendRequestMessage ( timestamp : NSDate . ows_millisecondTimeStamp ( ) , thread : thread , body : " Please accept to enable messages to be synced across devices " )
return FriendRequestMessage ( timestamp : NSDate . ows_millisecondTimeStamp ( ) , thread : thread , body : " Please accept to enable messages to be synced across devices " )
result . skipSave = true // TODO: W h y i s t h i s n e c e s s a r y a g a i n ?
return result
}
}
// / S e e [ A u t o - G e n e r a t e d F r i e n d R e q u e s t s ] ( h t t p s : / / g i t h u b . c o m / l o k i - p r o j e c t / s e s s i o n - p r o t o c o l - d o c s / w i k i / A u t o - G e n e r a t e d - F r i e n d - R e q u e s t s ) f o r m o r e i n f o r m a t i o n .
// / S e e [ A u t o - G e n e r a t e d F r i e n d R e q u e s t s ] ( h t t p s : / / g i t h u b . c o m / l o k i - p r o j e c t / s e s s i o n - p r o t o c o l - d o c s / w i k i / A u t o - G e n e r a t e d - F r i e n d - R e q u e s t s ) f o r m o r e i n f o r m a t i o n .