diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift index 44bc97903..52fbd8e1b 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift @@ -84,14 +84,18 @@ public final class LokiFileServerAPI : LokiDotNetAPI { return deviceLink } }) - }.map(on: DispatchQueue.global()) { deviceLinks in + }.then(on: DispatchQueue.global()) { deviceLinks -> Promise> in + let (promise, seal) = Promise>.pending() // Dispatch async on the main queue to avoid nested write transactions DispatchQueue.main.async { storage.dbReadWriteConnection.readWrite { transaction in storage.setDeviceLinks(deviceLinks, in: transaction) } + // We have to wait for the device links to be stored because a lot of our logic relies + // on them being in the database + seal.fulfill(deviceLinks) } - return deviceLinks + return promise } } } diff --git a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift index dad1d2f4b..27a288b6f 100644 --- a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift @@ -94,8 +94,7 @@ public final class SyncMessagesProtocol : NSObject { public static func isValidSyncMessage(_ envelope: SSKProtoEnvelope, in transaction: YapDatabaseReadTransaction) -> Bool { // The envelope source is set during UD decryption let hexEncodedPublicKey = envelope.source! - let linkedDeviceHexEncodedPublicKeys = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: getUserHexEncodedPublicKey(), in: transaction) - return linkedDeviceHexEncodedPublicKeys.contains(hexEncodedPublicKey) + return LokiDatabaseUtilities.isUserLinkedDevice(hexEncodedPublicKey, transaction: transaction) } // TODO: We should probably look at why sync messages are being duplicated rather than doing this diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 05f2deea8..9e938bc64 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1271,7 +1271,7 @@ NS_ASSUME_NONNULL_BEGIN }).catchOn(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(NSError *error) { dispatch_semaphore_signal(semaphore); }) retainUntilComplete]; - dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 8 * NSEC_PER_SEC)); + dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC)); } // FIXME: ========