From 3eb7e9271e45471e65b24fb5f586bbe77aa57f49 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 6 Jul 2018 17:55:37 -0600 Subject: [PATCH 1/2] Fix: second reply from lockscreen doesn't send // FREEBIE --- Signal/src/AppDelegate.m | 23 ++++++----------------- Signal/src/network/PushManager.h | 4 +++- Signal/src/network/PushManager.m | 32 ++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index be9a3d338..7c03e61fd 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -69,7 +69,6 @@ static NSTimeInterval launchStartedAt; @property (nonatomic) BOOL hasInitialRootViewController; @property (nonatomic) BOOL areVersionMigrationsComplete; @property (nonatomic) BOOL didAppLaunchFail; -@property (nonatomic) BOOL hasReceivedLocalNotification; @end @@ -539,8 +538,10 @@ static NSTimeInterval launchStartedAt; [self handleActivation]; }]; - // We want to process up to one local notification per activation, so clear the flag. - self.hasReceivedLocalNotification = NO; + // There is a sequence of actions a user can take where we present a conversation from a notification + // multiple times, producing an undesirable "stack" of multiple conversation view controllers. + // So we ensure that we only present conversations once per activate. + [PushManager sharedManager].hasPresentedConversationSinceLastDeactivation = NO; // Clear all notifications whenever we become active. // When opening the app from a notification, @@ -909,13 +910,6 @@ static NSTimeInterval launchStartedAt; return; } - // Don't process more than one local notification per activation. - if (self.hasReceivedLocalNotification) { - OWSFail(@"%@ %s ignoring redundant local notification.", self.logTag, __PRETTY_FUNCTION__); - return; - } - self.hasReceivedLocalNotification = YES; - DDLogInfo(@"%@ %s %@", self.logTag, __PRETTY_FUNCTION__, notification); [AppStoreRating preventPromptAtNextTest]; @@ -956,6 +950,8 @@ static NSTimeInterval launchStartedAt; withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler { + DDLogInfo(@"%@ handling action with identifier: %@", self.logTag, identifier); + OWSAssertIsOnMainThread(); if (self.didAppLaunchFail) { @@ -963,13 +959,6 @@ static NSTimeInterval launchStartedAt; return; } - // Don't process more than one local notification per activation. - if (self.hasReceivedLocalNotification) { - OWSFail(@"%@ %s ignoring redundant local notification.", self.logTag, __PRETTY_FUNCTION__); - return; - } - self.hasReceivedLocalNotification = YES; - // The docs for handleActionWithIdentifier:... state: // "You must call [completionHandler] at the end of your method.". // Nonetheless, it is presumably safe to call the completion handler diff --git a/Signal/src/network/PushManager.h b/Signal/src/network/PushManager.h index e0dffff55..dc2e0c282 100644 --- a/Signal/src/network/PushManager.h +++ b/Signal/src/network/PushManager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -37,6 +37,8 @@ typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken) */ @interface PushManager : NSObject +@property (nonatomic) BOOL hasPresentedConversationSinceLastDeactivation; + - (instancetype)init NS_UNAVAILABLE; + (PushManager *)sharedManager; diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 37859c532..f8aeb6913 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -134,7 +134,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe DDLogInfo(@"%@ received content-available push", self.logTag); // If we want to re-introduce silent pushes we can remove this assert. - OWSFail(@"Unexpected content-available push."); + OWSProdLogAndFail(@"Unexpected content-available push."); [AppReadiness runNowOrWhenAppIsReady:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ @@ -143,6 +143,20 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe }]; } +- (void)presentOncePerActivationConversationWithThreadId:(NSString *)threadId +{ + if (self.hasPresentedConversationSinceLastDeactivation) { + OWSProdLogAndFail(@"%@ in %s refusing to present conversation: %@ multiple times.", + self.logTag, + __PRETTY_FUNCTION__, + threadId); + return; + } + + self.hasPresentedConversationSinceLastDeactivation = YES; + [SignalApp.sharedApp presentConversationForThreadId:threadId]; +} + - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { OWSAssertIsOnMainThread(); @@ -151,9 +165,9 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe NSString *_Nullable threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; if (threadId) { - [SignalApp.sharedApp presentConversationForThreadId:threadId]; + [self presentOncePerActivationConversationWithThreadId:threadId]; } else { - OWSFail(@"%@ threadId was unexpectedly nil in %s", self.logTag, __PRETTY_FUNCTION__); + OWSProdLogAndFail(@"%@ threadId was unexpectedly nil in %s", self.logTag, __PRETTY_FUNCTION__); } // We only want to receive a single local notification per launch. @@ -259,18 +273,20 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; if (threadId) { - [SignalApp.sharedApp presentConversationForThreadId:threadId]; + [self presentOncePerActivationConversationWithThreadId:threadId]; } else { - OWSFail(@"%@ threadId was unexpectedly nil in action with identifier: %@", self.logTag, identifier); + OWSProdLogAndFail( + @"%@ threadId was unexpectedly nil in action with identifier: %@", self.logTag, identifier); } completionHandler(); } else { - OWSFail(@"%@ Unhandled action with identifier: %@", self.logTag, identifier); + OWSProdLogAndFail(@"%@ Unhandled action with identifier: %@", self.logTag, identifier); NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; if (threadId) { - [SignalApp.sharedApp presentConversationForThreadId:threadId]; + [self presentOncePerActivationConversationWithThreadId:threadId]; } else { - OWSFail(@"%@ threadId was unexpectedly nil in action with identifier: %@", self.logTag, identifier); + OWSProdLogAndFail( + @"%@ threadId was unexpectedly nil in action with identifier: %@", self.logTag, identifier); } completionHandler(); } From 46b835b501268734c90a2003984fb0b696f5bbf2 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 6 Jul 2018 17:59:54 -0600 Subject: [PATCH 2/2] "Bump build to 2.27.1.4." --- Signal/Signal-Info.plist | 2 +- SignalShareExtension/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 33fc34f67..2746a0351 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -38,7 +38,7 @@ CFBundleVersion - 2.27.1.3 + 2.27.1.4 ITSAppUsesNonExemptEncryption LOGS_EMAIL diff --git a/SignalShareExtension/Info.plist b/SignalShareExtension/Info.plist index d863dedda..9a264ae41 100644 --- a/SignalShareExtension/Info.plist +++ b/SignalShareExtension/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 2.27.1 CFBundleVersion - 2.27.1.3 + 2.27.1.4 ITSAppUsesNonExemptEncryption NSAppTransportSecurity