@ -249,15 +249,27 @@ public final class MultiDeviceProtocol : NSObject {
public static func handleUnlinkDeviceMessage ( _ dataMessage : SSKProtoDataMessage , wrappedIn envelope : SSKProtoEnvelope , using transaction : YapDatabaseReadWriteTransaction ) {
// T h e e n v e l o p e s o u r c e i s s e t d u r i n g U D d e c r y p t i o n
let hexEncodedPublicKey = envelope . source !
// C h e c k t h a t t h e r e q u e s t w a s s e n t b y o u r m a s t e r d e v i c e
guard let masterHexEncodedPublicKey = storage . getMasterHexEncodedPublicKey ( for : getUserHexEncodedPublicKey ( ) , in : transaction ) else { return }
let wasSentByMasterDevice = ( masterHexEncodedPublicKey = = hexEncodedPublicKey )
guard wasSentByMasterDevice else { return }
let deviceLinks = storage . getDeviceLinks ( for : hexEncodedPublicKey , in : transaction )
if ! deviceLinks . contains ( where : { $0 . master . hexEncodedPublicKey = = hexEncodedPublicKey && $0 . slave . hexEncodedPublicKey = = getUserHexEncodedPublicKey ( ) } ) {
// I g n o r e t h e r e q u e s t i f w e d o n ' t k n o w a b o u t t h e d e v i c e l i n k i n q u e s t i o n
let masterDeviceLinks = storage . getDeviceLinks ( for : masterHexEncodedPublicKey , in : transaction )
if ! masterDeviceLinks . contains ( where : {
$0 . master . hexEncodedPublicKey = = masterHexEncodedPublicKey && $0 . slave . hexEncodedPublicKey = = getUserHexEncodedPublicKey ( )
} ) {
return
}
LokiFileServerAPI . getDeviceLinks ( associatedWith : getUserHexEncodedPublicKey ( ) ) . done ( on : DispatchQueue . main ) { deviceLinks in
if deviceLinks . contains ( where : { $0 . master . hexEncodedPublicKey = = hexEncodedPublicKey && $0 . slave . hexEncodedPublicKey = = getUserHexEncodedPublicKey ( ) } ) {
LokiFileServerAPI . getDeviceLinks ( associatedWith : getUserHexEncodedPublicKey ( ) ) . done ( on : DispatchQueue . main ) { slaveDeviceLinks in
// C h e c k t h a t t h e d e v i c e l i n k I S p r e s e n t o n t h e f i l e s e r v e r .
// N o t e t h a t t h e d e v i c e l i n k a s s e e n f r o m t h e m a s t e r d e v i c e ' s p e r s p e c t i v e h a s b e e n d e l e t e d a t t h i s p o i n t , b u t t h e
// d e v i c e l i n k a s s e e n f r o m t h e s l a v e p e r s p e c t i v e h a s n ' t .
if slaveDeviceLinks . contains ( where : {
$0 . master . hexEncodedPublicKey = = masterHexEncodedPublicKey && $0 . slave . hexEncodedPublicKey = = getUserHexEncodedPublicKey ( )
} ) {
for deviceLink in slaveDeviceLinks { // I n t h e o r y t h e r e s h o u l d o n l y b e o n e
LokiFileServerAPI . removeDeviceLink ( deviceLink ) // A t t e m p t t o c l e a n u p o n t h e f i l e s e r v e r
}
UserDefaults . standard [ . wasUnlinked ] = true
NotificationCenter . default . post ( name : . dataNukeRequested , object : nil )
}