|
|
|
@ -155,9 +155,9 @@ public final class SyncMessagesProtocol : NSObject {
|
|
|
|
|
public static func handleContactSyncMessageIfNeeded(_ syncMessage: SSKProtoSyncMessage, wrappedIn envelope: SSKProtoEnvelope, using transaction: YapDatabaseReadWriteTransaction) {
|
|
|
|
|
// The envelope source is set during UD decryption
|
|
|
|
|
let hexEncodedPublicKey = envelope.source!
|
|
|
|
|
guard let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: getUserHexEncodedPublicKey(), in: transaction) else { return }
|
|
|
|
|
let wasSentByMasterDevice = (masterHexEncodedPublicKey == hexEncodedPublicKey)
|
|
|
|
|
guard wasSentByMasterDevice, let contacts = syncMessage.contacts, let contactsAsData = contacts.data, contactsAsData.count > 0 else { return }
|
|
|
|
|
let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: hexEncodedPublicKey, in: transaction)
|
|
|
|
|
let wasSentByLinkedDevice = linkedDevices.contains(hexEncodedPublicKey)
|
|
|
|
|
guard wasSentByLinkedDevice, let contacts = syncMessage.contacts, let contactsAsData = contacts.data, contactsAsData.count > 0 else { return }
|
|
|
|
|
print("[Loki] Contact sync message received.")
|
|
|
|
|
handleContactSyncMessageData(contactsAsData, using: transaction)
|
|
|
|
|
}
|
|
|
|
|