Fix issue where the app doesn't wait for device links to be stored

pull/187/head
nielsandriesse 5 years ago
parent dd69ef236d
commit f10cc65187

@ -84,14 +84,18 @@ public final class LokiFileServerAPI : LokiDotNetAPI {
return deviceLink return deviceLink
} }
}) })
}.map(on: DispatchQueue.global()) { deviceLinks in }.then(on: DispatchQueue.global()) { deviceLinks -> Promise<Set<DeviceLink>> in
let (promise, seal) = Promise<Set<DeviceLink>>.pending()
// Dispatch async on the main queue to avoid nested write transactions // Dispatch async on the main queue to avoid nested write transactions
DispatchQueue.main.async { DispatchQueue.main.async {
storage.dbReadWriteConnection.readWrite { transaction in storage.dbReadWriteConnection.readWrite { transaction in
storage.setDeviceLinks(deviceLinks, in: transaction) 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
} }
} }
} }

@ -94,8 +94,7 @@ public final class SyncMessagesProtocol : NSObject {
public static func isValidSyncMessage(_ envelope: SSKProtoEnvelope, in transaction: YapDatabaseReadTransaction) -> Bool { public static func isValidSyncMessage(_ envelope: SSKProtoEnvelope, in transaction: YapDatabaseReadTransaction) -> Bool {
// The envelope source is set during UD decryption // The envelope source is set during UD decryption
let hexEncodedPublicKey = envelope.source! let hexEncodedPublicKey = envelope.source!
let linkedDeviceHexEncodedPublicKeys = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: getUserHexEncodedPublicKey(), in: transaction) return LokiDatabaseUtilities.isUserLinkedDevice(hexEncodedPublicKey, transaction: transaction)
return linkedDeviceHexEncodedPublicKeys.contains(hexEncodedPublicKey)
} }
// TODO: We should probably look at why sync messages are being duplicated rather than doing this // TODO: We should probably look at why sync messages are being duplicated rather than doing this

@ -1271,7 +1271,7 @@ NS_ASSUME_NONNULL_BEGIN
}).catchOn(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(NSError *error) { }).catchOn(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(NSError *error) {
dispatch_semaphore_signal(semaphore); dispatch_semaphore_signal(semaphore);
}) retainUntilComplete]; }) 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: ======== // FIXME: ========

Loading…
Cancel
Save