From f748fbd4cc512848f78384bbe0f0c42c393906d9 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 14 May 2019 10:39:26 +1000 Subject: [PATCH] Apply OCD --- .../Loki/Extensions/OWSPrimaryStorage+Loki.h | 18 +++++++++--------- .../Loki/Extensions/OWSPrimaryStorage+Loki.m | 17 +++++++---------- ...ProtoPrekeyBundleMessage+PreKeyBundle.swift | 17 +++++++++-------- .../Loki/Messages/OWSFriendRequestMessage.h | 2 +- .../Loki/Messages/OWSFriendRequestMessage.m | 2 +- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h index db91f0f9a..0afb932bf 100644 --- a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h +++ b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h @@ -6,18 +6,18 @@ NS_ASSUME_NONNULL_BEGIN @interface OWSPrimaryStorage (Loki) -# pragma mark - Prekey for contacts +# pragma mark - Prekey for Contact /** - Check if we have PreKeyRecord for the given contact. + Check if we have a `PreKeyRecord` for the given contact. - @param pubKey The hex encoded public ket of the contact. + @param pubKey The hex encoded public key of the contact. @return Whether we have a prekey or not. */ - (BOOL)hasPreKeyForContact:(NSString *)pubKey; /** - 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 create a new one. @param pubKey The hex encoded public key of the contact. @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN # pragma mark - PreKeyBundle /** - Generate a PreKeyBundle for the given contact. + Generate a `PreKeyBundle` for the given contact. This doesn't store the pre key bundle, and you shouldn't store this bundle. It's used for generating bundles to send to other users. @@ -38,15 +38,15 @@ NS_ASSUME_NONNULL_BEGIN - (PreKeyBundle *)generatePreKeyBundleForContact:(NSString *)pubKey; /** - Get the PreKeyBundle associated with the given contact. + Get the `PreKeyBundle` associated with the given contact. @param pubKey The hex encoded public key of the contact. - @return The pre key bundle or nil if it doesn't exist. + @return The pre key bundle or `nil` if it doesn't exist. */ - (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey; /** - Set the PreKeyBundle for the given contact. + Set the `PreKeyBundle` for the given contact. @param bundle The pre key bundle. @param pubKey The hex encoded public key of the contact. @@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey; /** - Remove the PreKeyBundle for the given contact. + Remove the `PreKeyBundle` for the given contact. @param pubKey The hex encoded public key of the contact. */ diff --git a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m index cc66d4d7e..30e09d50d 100644 --- a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m +++ b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m @@ -23,7 +23,7 @@ return TSAccountManager.sharedInstance; } -# pragma mark - Prekey for contacts +# pragma mark - Prekey for Contact - (BOOL)hasPreKeyForContact:(NSString *)pubKey { int preKeyId = [self.dbReadWriteConnection intForKey:pubKey inCollection:LokiPreKeyContactCollection]; @@ -68,8 +68,8 @@ // Check prekeys to make sure we have them for this function [TSPreKeyManager checkPreKeys]; - ECKeyPair *_Nullable myKeyPair = self.identityManager.identityKeyPair; - OWSAssertDebug(myKeyPair); + ECKeyPair *_Nullable keyPair = self.identityManager.identityKeyPair; + OWSAssertDebug(keyPair); SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey]; if (!signedPreKey) { @@ -86,13 +86,12 @@ signedPreKeyPublic:signedPreKey.keyPair.publicKey.prependKeyType signedPreKeyId:signedPreKey.Id signedPreKeySignature:signedPreKey.signature - identityKey:myKeyPair.publicKey.prependKeyType]; + identityKey:keyPair.publicKey.prependKeyType]; return bundle; } - (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey { - PreKeyBundle *bundle = [self.dbReadWriteConnection preKeyBundleForKey:pubKey inCollection:LokiPreKeyBundleCollection]; - return bundle; + return [self.dbReadWriteConnection preKeyBundleForKey:pubKey inCollection:LokiPreKeyBundleCollection]; } - (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey { @@ -101,10 +100,8 @@ inCollection:LokiPreKeyBundleCollection]; } -- (void)removePreKeyBundleForContact:(NSString *)pubKey -{ - [self.dbReadWriteConnection removeObjectForKey:pubKey - inCollection:LokiPreKeyBundleCollection]; +- (void)removePreKeyBundleForContact:(NSString *)pubKey { + [self.dbReadWriteConnection removeObjectForKey:pubKey inCollection:LokiPreKeyBundleCollection]; } @end diff --git a/SignalServiceKit/src/Loki/Extensions/SSKProtoPrekeyBundleMessage+PreKeyBundle.swift b/SignalServiceKit/src/Loki/Extensions/SSKProtoPrekeyBundleMessage+PreKeyBundle.swift index 9bd4da1f6..623846f8c 100644 --- a/SignalServiceKit/src/Loki/Extensions/SSKProtoPrekeyBundleMessage+PreKeyBundle.swift +++ b/SignalServiceKit/src/Loki/Extensions/SSKProtoPrekeyBundleMessage+PreKeyBundle.swift @@ -1,15 +1,16 @@ -public extension SSKProtoPrekeyBundleMessage { + +@objc public extension SSKProtoPrekeyBundleMessage { @objc public var preKeyBundle: PreKeyBundle? { let registrationId = TSAccountManager.sharedInstance().getOrGenerateRegistrationId() return PreKeyBundle(registrationId: Int32(registrationId), - deviceId: Int32(self.deviceID), - preKeyId: Int32(self.prekeyID), - preKeyPublic: self.prekey, - signedPreKeyPublic: self.signedKey, - signedPreKeyId: Int32(self.signedKeyID), - signedPreKeySignature: self.signature, - identityKey: self.identityKey) + deviceId: Int32(deviceID), + preKeyId: Int32(prekeyID), + preKeyPublic: prekey, + signedPreKeyPublic: signedKey, + signedPreKeyId: Int32(signedKeyID), + signedPreKeySignature: signature, + identityKey: identityKey) } @objc public class func builder(fromPreKeyBundle preKeyBundle: PreKeyBundle) -> SSKProtoPrekeyBundleMessageBuilder { diff --git a/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.h b/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.h index 7b7b6c23d..320b3662f 100644 --- a/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.h +++ b/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.h @@ -1,4 +1,4 @@ -#import +#import "SignalServiceKit.h" #import "TSOutgoingMessage.h" NS_ASSUME_NONNULL_BEGIN diff --git a/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m b/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m index f72a51f7b..30cabf6e3 100644 --- a/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m +++ b/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m @@ -8,7 +8,7 @@ - (SSKProtoContentBuilder *)contentBuilder:(SignalRecipient *)recipient { SSKProtoContentBuilder *contentBuilder = [super contentBuilder:recipient]; - PreKeyBundle *bundle = [[OWSPrimaryStorage sharedManager] generatePreKeyBundleForContact:recipient.recipientId]; + PreKeyBundle *bundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId]; SSKProtoPrekeyBundleMessageBuilder *preKeyBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:bundle]; // Build the pre key bundle message