From 141fa8e2cc3910ff51d43fb9d0de70a2435d17d5 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 13 May 2019 15:13:50 +1000 Subject: [PATCH] Do KeyOperations on the global thread. --- .../src/Account/PreKeyRefreshOperation.swift | 33 ++++++++++--------- .../Account/RotateSignedKeyOperation.swift | 23 +++++++------ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift index c883b6b3c..672728516 100644 --- a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift +++ b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift @@ -35,23 +35,26 @@ public class RefreshPreKeysOperation: OWSOperation { Logger.debug("skipping - not registered") return } - - guard self.primaryStorage.currentSignedPrekeyId() == nil else { - Logger.debug("Already have a signed prekey set") + + // Loki: Doing this on the global queue because they do it at the bottom + DispatchQueue.global().async { + guard self.primaryStorage.currentSignedPrekeyId() == nil else { + Logger.debug("Already have a signed prekey set") + self.reportSuccess() + return + } + + let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() + signedPreKeyRecord.markAsAcceptedByService() + self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) + self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) + + TSPreKeyManager.clearPreKeyUpdateFailureCount() + TSPreKeyManager.clearSignedPreKeyRecords() + + Logger.debug("done") self.reportSuccess() - return } - - let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() - signedPreKeyRecord.markAsAcceptedByService() - self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) - self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) - - TSPreKeyManager.clearPreKeyUpdateFailureCount() - TSPreKeyManager.clearSignedPreKeyRecords() - - Logger.debug("done") - self.reportSuccess() /* Loki: Original Code * ============= diff --git a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift index a004fdaf2..a72ad8ce6 100644 --- a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift +++ b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift @@ -27,16 +27,19 @@ public class RotateSignedPreKeyOperation: OWSOperation { return } - let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() - signedPreKeyRecord.markAsAcceptedByService() - self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) - self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) - - TSPreKeyManager.clearPreKeyUpdateFailureCount() - TSPreKeyManager.clearSignedPreKeyRecords() - - Logger.debug("done") - self.reportSuccess() + // Loki: Doing this on the global queue because they do it at the bottom + DispatchQueue.global().async { + let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() + signedPreKeyRecord.markAsAcceptedByService() + self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) + self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) + + TSPreKeyManager.clearPreKeyUpdateFailureCount() + TSPreKeyManager.clearSignedPreKeyRecords() + + Logger.debug("done") + self.reportSuccess() + } /* Loki: Original Code * =========