From e714d9b3ab0e838b662b998979de4ee9b9c2fb83 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 14 May 2019 09:50:28 +1000 Subject: [PATCH] Review fixes. --- .../src/Account/CreatePreKeysOperation.swift | 4 ++-- .../src/Account/PreKeyRefreshOperation.swift | 2 +- .../src/Account/RotateSignedKeyOperation.swift | 2 +- .../src/Loki/Extensions/OWSPrimaryStorage+Loki.h | 4 ++-- .../src/Loki/Extensions/OWSPrimaryStorage+Loki.m | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift index cf4381568..b4fed8e50 100644 --- a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift +++ b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift @@ -30,13 +30,13 @@ public class CreatePreKeysOperation: OWSOperation { /// Loki: We don't generate PreKeyRecords here. /// This is because we need the records to be linked to a contact since we don't have a central server. /// It is done automatically when we generate a PreKeyBundle to send to a contact (`generatePreKeyBundleForContact:`). - /// You can use `getPreKeyForContact:` to generate one if needed. + /// You can use `getOrCreatePreKeyForContact:` to generate one if needed. let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() signedPreKeyRecord.markAsAcceptedByService() self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) - Logger.debug("done") + Logger.debug("[CreatePreKeysOperation] done") self.reportSuccess() /* Loki: Original Code diff --git a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift index 672728516..0e177b6dc 100644 --- a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift +++ b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift @@ -52,7 +52,7 @@ public class RefreshPreKeysOperation: OWSOperation { TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearSignedPreKeyRecords() - Logger.debug("done") + Logger.debug("[PreKeyRefreshOperation] done") self.reportSuccess() } diff --git a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift index a72ad8ce6..31b437568 100644 --- a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift +++ b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift @@ -37,7 +37,7 @@ public class RotateSignedPreKeyOperation: OWSOperation { TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearSignedPreKeyRecords() - Logger.debug("done") + Logger.debug("[RotateSignedKeyOperation] done") self.reportSuccess() } diff --git a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h index 0ccc9a7ff..db91f0f9a 100644 --- a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h +++ b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h @@ -18,12 +18,12 @@ NS_ASSUME_NONNULL_BEGIN /** Get the PreKeyRecord associated with the given contact. - If the record doesn't exist then this will generate a new one. + If the record doesn't exist then this will create a new one. @param pubKey The hex encoded public key of the contact. @return The record associated with the contact. */ -- (PreKeyRecord *)getPreKeyForContact:(NSString *)pubKey; +- (PreKeyRecord *)getOrCreatePreKeyForContact:(NSString *)pubKey; # pragma mark - PreKeyBundle diff --git a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m index a74f873c0..089b4ce46 100644 --- a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m +++ b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m @@ -20,12 +20,12 @@ return preKeyId > 0; } -- (PreKeyRecord *)getPreKeyForContact:(NSString *)pubKey { +- (PreKeyRecord *)getOrCreatePreKeyForContact:(NSString *)pubKey { OWSAssertDebug(pubKey.length > 0); int preKeyId = [self.dbReadWriteConnection intForKey:pubKey inCollection:LokiPreKeyContactCollection]; // If we don't have an id then generate and store a new one - if (preKeyId < 1) { + if (preKeyId <= 0) { return [self generateAndStorePreKeyForContact:pubKey]; } @@ -46,7 +46,7 @@ [self storePreKeyRecords:records]; OWSAssertDebug(records.count > 0); - PreKeyRecord *record = [records firstObject]; + PreKeyRecord *record = records.firstObject; [self.dbReadWriteConnection setInt:record.Id forKey:pubKey inCollection:LokiPreKeyContactCollection]; return record; @@ -58,7 +58,7 @@ // Check prekeys to make sure we have them for this function [TSPreKeyManager checkPreKeys]; - ECKeyPair *_Nullable myKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair]; + ECKeyPair *_Nullable myKeyPair = OWSIdentityManager.sharedManager.identityKeyPair; OWSAssertDebug(myKeyPair); SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey]; @@ -66,8 +66,8 @@ OWSFailDebug(@"Signed prekey is null"); } - PreKeyRecord *preKey = [self getPreKeyForContact:pubKey]; - uint32_t registrationId = [[TSAccountManager sharedInstance] getOrGenerateRegistrationId]; + PreKeyRecord *preKey = [self getOrCreatePreKeyForContact:pubKey]; + uint32_t registrationId = [TSAccountManager.sharedInstance getOrGenerateRegistrationId]; PreKeyBundle *bundle = [[PreKeyBundle alloc] initWithRegistrationId:registrationId deviceId:OWSDevicePrimaryDeviceId