From e3e7788219f546cb4c587d54e27a588515ae1d14 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 14 May 2019 13:39:07 +1000 Subject: [PATCH] Disable input if a friend request is pending --- .../ConversationView/Cells/OWSMessageCell.m | 12 +++--------- .../ConversationView/ConversationViewController.m | 7 +++++++ SignalMessaging/profiles/OWSProfileManager.m | 4 ++-- SignalMessaging/profiles/ProfileFetcherJob.swift | 4 ++-- .../src/Account/CreatePreKeysOperation.swift | 4 ++-- .../src/Account/PreKeyRefreshOperation.swift | 4 ++-- .../src/Account/RotateSignedKeyOperation.swift | 4 ++-- .../src/Loki/Extensions/OWSPrimaryStorage+Loki.h | 8 ++++---- .../src/Loki/Extensions/OWSPrimaryStorage+Loki.m | 4 ++-- .../src/Loki/Messages/OWSFriendRequestMessage.m | 2 +- .../src/Messages/Interactions/OWSEndSessionMessage.m | 4 ++-- SignalServiceKit/src/Messages/OWSMessageSender.m | 2 +- .../src/Storage/YapDatabaseConnection+OWS.m | 2 +- .../src/Storage/YapDatabaseTransaction+OWS.m | 2 +- 14 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 9e68b56b4..125344f10 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -217,15 +217,9 @@ NS_ASSUME_NONNULL_BEGIN } if (self.isFriendRequest) { - NSString *rawKind; - switch (self.friendRequestState) { - case TSThreadFriendRequestStateRequestReceived: - rawKind = @"incoming"; - break; - case TSThreadFriendRequestStateRequestSent: - rawKind = @"outgoing"; - break; - } + // At this point, self.friendRequestState should be either TSThreadFriendRequestStateRequestReceived, + // TSThreadFriendRequestStatePendingSend or TSThreadFriendRequestStateRequestSent + NSString *rawKind = self.friendRequestState == TSThreadFriendRequestStateRequestReceived ? @"incoming" : @"outgoing"; self.friendRequestView = [[FriendRequestView alloc] initWithRawKind:rawKind]; self.friendRequestView.message = self.message; self.friendRequestView.delegate = self.friendRequestViewDelegate; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 634825a04..d4520a9c9 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -627,6 +627,7 @@ typedef enum : NSUInteger { self.inputToolbar.inputToolbarDelegate = self; self.inputToolbar.inputTextViewDelegate = self; SET_SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, _inputToolbar); + [self updateIsInputToolbarInteractionEnabled]; self.loadMoreHeader = [UILabel new]; self.loadMoreHeader.text = NSLocalizedString(@"CONVERSATION_VIEW_LOADING_MORE_MESSAGES", @@ -1582,6 +1583,12 @@ typedef enum : NSUInteger { self.headerView.attributedSubtitle = subtitleText; } +#pragma mark - Updating + +- (void)updateIsInputToolbarInteractionEnabled { + // TODO: Listen to friend request updates and call this accordingly + [self.inputToolbar setUserInteractionEnabled:!self.thread.isPendingFriendRequest]; +} #pragma mark - Identity diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 22129168d..408150212 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -298,7 +298,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); OWSLogVerbose(@"Updating local profile on service with no avatar."); tryToUpdateService(nil, nil); - /* ========== Original Code =============== + /* ========== Original code =============== if (avatarImage) { // If we have a new avatar image, we must first: // @@ -538,7 +538,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); // Loki: We don't need to make any server calls so succeed automatically successBlock(); - /* ============ Original Code ============ + /* ============ Original code ============ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData *_Nullable encryptedPaddedName = [self encryptProfileNameWithUnpaddedName:localProfileName]; diff --git a/SignalMessaging/profiles/ProfileFetcherJob.swift b/SignalMessaging/profiles/ProfileFetcherJob.swift index 4682b9c9b..94ab032ad 100644 --- a/SignalMessaging/profiles/ProfileFetcherJob.swift +++ b/SignalMessaging/profiles/ProfileFetcherJob.swift @@ -79,9 +79,9 @@ public class ProfileFetcherJob: NSObject { public func run(recipientIds: [String]) { AssertIsOnMainThread() - /* Loki: Original Code + /* Loki: Original code * Disabled as we don't have an endpoint for fetching profiles - * ========================= + * ================ guard CurrentAppContext().isMainApp else { // Only refresh profiles in the MainApp to decrease the chance of missed SN notifications // in the AppExtension for our users who choose not to verify contacts. diff --git a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift index b4fed8e50..76e7e9aee 100644 --- a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift +++ b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift @@ -39,8 +39,8 @@ public class CreatePreKeysOperation: OWSOperation { Logger.debug("[CreatePreKeysOperation] done") self.reportSuccess() - /* Loki: Original Code - * ================== + /* Loki: Original code + * ================ let identityKey: Data = self.identityKeyManager.identityKeyPair()!.publicKey let signedPreKeyRecord: SignedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() let preKeyRecords: [PreKeyRecord] = self.primaryStorage.generatePreKeyRecords() diff --git a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift index 0e177b6dc..9ae59add6 100644 --- a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift +++ b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift @@ -56,8 +56,8 @@ public class RefreshPreKeysOperation: OWSOperation { self.reportSuccess() } - /* Loki: Original Code - * ============= + /* Loki: Original code + * ================ firstly { self.accountServiceClient.getPreKeysCount() }.then(on: DispatchQueue.global()) { preKeysCount -> Promise in diff --git a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift index 31b437568..e38133a10 100644 --- a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift +++ b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift @@ -41,8 +41,8 @@ public class RotateSignedPreKeyOperation: OWSOperation { self.reportSuccess() } - /* Loki: Original Code - * ========= + /* Loki: Original code + * ================ let signedPreKeyRecord: SignedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) diff --git a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h index ffcee015b..66abe8625 100644 --- a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h +++ b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.h @@ -30,11 +30,11 @@ NS_ASSUME_NONNULL_BEGIN /** Generate a `PreKeyBundle` for the given contact. - This doesn't store the pre key bundle, and you shouldn't store this bundle. + This doesn't store the prekey bundle, and you shouldn't store this bundle. It's used for generating bundles to send to other users. @param pubKey The hex encoded public key of the contact. - @return A pre key bundle for the contact. + @return A prekey bundle for the contact. */ - (PreKeyBundle *)generatePreKeyBundleForContact:(NSString *)pubKey; @@ -42,14 +42,14 @@ NS_ASSUME_NONNULL_BEGIN 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 prekey bundle or `nil` if it doesn't exist. */ - (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey; /** Set the `PreKeyBundle` for the given contact. - @param bundle The pre key bundle. + @param bundle The prekey bundle. @param transaction A `YapDatabaseReadWriteTransaction`. @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 a120e43ce..3f68de6c8 100644 --- a/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m +++ b/SignalServiceKit/src/Loki/Extensions/OWSPrimaryStorage+Loki.m @@ -39,7 +39,7 @@ return [self generateAndStorePreKeyForContact:pubKey]; } - // Load the pre key otherwise just generate a new one + // Load the prekey otherwise just generate a new one @try { return [self throws_loadPreKey:preKeyId]; } @catch (NSException *exception) { @@ -71,7 +71,7 @@ ECKeyPair *_Nullable keyPair = self.identityManager.identityKeyPair; OWSAssertDebug(keyPair); - SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey]; + SignedPreKeyRecord *_Nullable signedPreKey = self.currentSignedPreKey; if (!signedPreKey) { OWSFailDebug(@"Signed prekey is null"); } diff --git a/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m b/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m index 30cabf6e3..a44b1e121 100644 --- a/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m +++ b/SignalServiceKit/src/Loki/Messages/OWSFriendRequestMessage.m @@ -11,7 +11,7 @@ PreKeyBundle *bundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId]; SSKProtoPrekeyBundleMessageBuilder *preKeyBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:bundle]; - // Build the pre key bundle message + // Build the prekey bundle message NSError *error; SSKProtoPrekeyBundleMessage *_Nullable message = [preKeyBuilder buildAndReturnError:&error]; if (error || !message) { diff --git a/SignalServiceKit/src/Messages/Interactions/OWSEndSessionMessage.m b/SignalServiceKit/src/Messages/Interactions/OWSEndSessionMessage.m index 46b010ca7..d59b584dd 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSEndSessionMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/OWSEndSessionMessage.m @@ -51,10 +51,10 @@ NS_ASSUME_NONNULL_BEGIN - (SSKProtoContentBuilder *)contentBuilder:(SignalRecipient *)recipient { SSKProtoContentBuilder *builder = [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 + // Build the prekey bundle message NSError *error; SSKProtoPrekeyBundleMessage *_Nullable message = [preKeyBuilder buildAndReturnError:&error]; if (error || !message) { diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 092605e21..2a43dad6e 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1648,7 +1648,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; if (exception) { @throw exception; } - *============ + * ================ */ if (!bundle) { diff --git a/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m b/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m index 428444ca7..03dd59763 100644 --- a/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m +++ b/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m @@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable PreKeyBundle *)preKeyBundleForKey:(NSString *)key inCollection:(NSString *)collection { - return [self objectForKey:key inCollection:collection ofExpectedType:[PreKeyBundle class]]; + return [self objectForKey:key inCollection:collection ofExpectedType:PreKeyBundle.class]; } - (nullable SignedPreKeyRecord *)signedPreKeyRecordForKey:(NSString *)key inCollection:(NSString *)collection diff --git a/SignalServiceKit/src/Storage/YapDatabaseTransaction+OWS.m b/SignalServiceKit/src/Storage/YapDatabaseTransaction+OWS.m index 0fbd9f64e..6f7f25a45 100644 --- a/SignalServiceKit/src/Storage/YapDatabaseTransaction+OWS.m +++ b/SignalServiceKit/src/Storage/YapDatabaseTransaction+OWS.m @@ -72,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable PreKeyBundle *)preKeyBundleForKey:(NSString *)key inCollection:(NSString *)collection { - return [self objectForKey:key inCollection:collection ofExpectedType:[PreKeyBundle class]]; + return [self objectForKey:key inCollection:collection ofExpectedType:PreKeyBundle.class]; } - (nullable SignedPreKeyRecord *)signedPreKeyRecordForKey:(NSString *)key inCollection:(NSString *)collection