Fix device unlinking order of operations

pull/70/head
Niels Andriesse 5 years ago
parent c2de6f9f88
commit 164aeb4142

@ -138,10 +138,17 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey
guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return } guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return }
let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)! let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)!
ThreadUtil.enqueue(unlinkDeviceMessage) SSKEnvironment.shared.messageSender.send(unlinkDeviceMessage, success: {
let storage = OWSPrimaryStorage.shared() let storage = OWSPrimaryStorage.shared()
storage.dbReadWriteConnection.readWrite { transaction in storage.dbReadWriteConnection.readWrite { transaction in
storage.archiveAllSessions(forContact: linkedDeviceHexEncodedPublicKey, protocolContext: transaction) storage.deleteAllSessions(forContact: linkedDeviceHexEncodedPublicKey, protocolContext: transaction)
}
}) { _ in
print("[Loki] Failed to send unlink device message.")
let storage = OWSPrimaryStorage.shared()
storage.dbReadWriteConnection.readWrite { transaction in
storage.deleteAllSessions(forContact: linkedDeviceHexEncodedPublicKey, protocolContext: transaction)
}
} }
self?.updateDeviceLinks() self?.updateDeviceLinks()
}.catch { [weak self] _ in }.catch { [weak self] _ in

Loading…
Cancel
Save