Review fixes.

pull/14/head
Mikunj 6 years ago
parent 38b698a531
commit e714d9b3ab

@ -30,13 +30,13 @@ public class CreatePreKeysOperation: OWSOperation {
/// Loki: We don't generate PreKeyRecords here. /// 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. /// 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:`). /// 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() let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord()
signedPreKeyRecord.markAsAcceptedByService() signedPreKeyRecord.markAsAcceptedByService()
self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id)
Logger.debug("done") Logger.debug("[CreatePreKeysOperation] done")
self.reportSuccess() self.reportSuccess()
/* Loki: Original Code /* Loki: Original Code

@ -52,7 +52,7 @@ public class RefreshPreKeysOperation: OWSOperation {
TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearPreKeyUpdateFailureCount()
TSPreKeyManager.clearSignedPreKeyRecords() TSPreKeyManager.clearSignedPreKeyRecords()
Logger.debug("done") Logger.debug("[PreKeyRefreshOperation] done")
self.reportSuccess() self.reportSuccess()
} }

@ -37,7 +37,7 @@ public class RotateSignedPreKeyOperation: OWSOperation {
TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearPreKeyUpdateFailureCount()
TSPreKeyManager.clearSignedPreKeyRecords() TSPreKeyManager.clearSignedPreKeyRecords()
Logger.debug("done") Logger.debug("[RotateSignedKeyOperation] done")
self.reportSuccess() self.reportSuccess()
} }

@ -18,12 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
Get the PreKeyRecord associated with the given contact. 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. @param pubKey The hex encoded public key of the contact.
@return The record associated with the contact. @return The record associated with the contact.
*/ */
- (PreKeyRecord *)getPreKeyForContact:(NSString *)pubKey; - (PreKeyRecord *)getOrCreatePreKeyForContact:(NSString *)pubKey;
# pragma mark - PreKeyBundle # pragma mark - PreKeyBundle

@ -20,12 +20,12 @@
return preKeyId > 0; return preKeyId > 0;
} }
- (PreKeyRecord *)getPreKeyForContact:(NSString *)pubKey { - (PreKeyRecord *)getOrCreatePreKeyForContact:(NSString *)pubKey {
OWSAssertDebug(pubKey.length > 0); OWSAssertDebug(pubKey.length > 0);
int preKeyId = [self.dbReadWriteConnection intForKey:pubKey inCollection:LokiPreKeyContactCollection]; int preKeyId = [self.dbReadWriteConnection intForKey:pubKey inCollection:LokiPreKeyContactCollection];
// If we don't have an id then generate and store a new one // If we don't have an id then generate and store a new one
if (preKeyId < 1) { if (preKeyId <= 0) {
return [self generateAndStorePreKeyForContact:pubKey]; return [self generateAndStorePreKeyForContact:pubKey];
} }
@ -46,7 +46,7 @@
[self storePreKeyRecords:records]; [self storePreKeyRecords:records];
OWSAssertDebug(records.count > 0); OWSAssertDebug(records.count > 0);
PreKeyRecord *record = [records firstObject]; PreKeyRecord *record = records.firstObject;
[self.dbReadWriteConnection setInt:record.Id forKey:pubKey inCollection:LokiPreKeyContactCollection]; [self.dbReadWriteConnection setInt:record.Id forKey:pubKey inCollection:LokiPreKeyContactCollection];
return record; return record;
@ -58,7 +58,7 @@
// Check prekeys to make sure we have them for this function // Check prekeys to make sure we have them for this function
[TSPreKeyManager checkPreKeys]; [TSPreKeyManager checkPreKeys];
ECKeyPair *_Nullable myKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair]; ECKeyPair *_Nullable myKeyPair = OWSIdentityManager.sharedManager.identityKeyPair;
OWSAssertDebug(myKeyPair); OWSAssertDebug(myKeyPair);
SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey]; SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey];
@ -66,8 +66,8 @@
OWSFailDebug(@"Signed prekey is null"); OWSFailDebug(@"Signed prekey is null");
} }
PreKeyRecord *preKey = [self getPreKeyForContact:pubKey]; PreKeyRecord *preKey = [self getOrCreatePreKeyForContact:pubKey];
uint32_t registrationId = [[TSAccountManager sharedInstance] getOrGenerateRegistrationId]; uint32_t registrationId = [TSAccountManager.sharedInstance getOrGenerateRegistrationId];
PreKeyBundle *bundle = [[PreKeyBundle alloc] initWithRegistrationId:registrationId PreKeyBundle *bundle = [[PreKeyBundle alloc] initWithRegistrationId:registrationId
deviceId:OWSDevicePrimaryDeviceId deviceId:OWSDevicePrimaryDeviceId

Loading…
Cancel
Save