From a462cba4522f3d39a54d24a2fadb23fb462a08a9 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 23 Jun 2017 13:55:21 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Don=E2=80=99t=20reply=20to=20=E2=80=9Cno=20?= =?UTF-8?q?longer=20verified=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/environment/NotificationsManager.m | 10 ++++-- Signal/src/network/PushManager.h | 1 + Signal/src/network/PushManager.m | 33 +++++++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index d137c2eef..88edf3359 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -263,8 +263,13 @@ } switch (self.notificationPreviewType) { - case NotificationNamePreview: - notification.category = Signal_Full_New_Message_Category; + case NotificationNamePreview: { + BOOL senderIsNoLongerVerified = + [OWSIdentityManager.sharedManager verificationStateForRecipientId:message.authorId] + == OWSVerificationStateNoLongerVerified; + + notification.category = (senderIsNoLongerVerified ? Signal_Full_New_Message_Category_No_Longer_Verified + : Signal_Full_New_Message_Category); notification.userInfo = @{Signal_Thread_UserInfo_Key : thread.uniqueId, Signal_Message_UserInfo_Key : message.uniqueId}; @@ -280,6 +285,7 @@ notification.alertBody = [NSString stringWithFormat:@"%@: %@", senderName, messageDescription]; } break; + } case NotificationNameNoPreview: { notification.userInfo = @{Signal_Thread_UserInfo_Key : thread.uniqueId}; if ([thread isGroupThread]) { diff --git a/Signal/src/network/PushManager.h b/Signal/src/network/PushManager.h index c319a3980..07bda7c21 100644 --- a/Signal/src/network/PushManager.h +++ b/Signal/src/network/PushManager.h @@ -14,6 +14,7 @@ extern NSString *const Signal_Thread_UserInfo_Key; extern NSString *const Signal_Message_UserInfo_Key; extern NSString *const Signal_Full_New_Message_Category; +extern NSString *const Signal_Full_New_Message_Category_No_Longer_Verified; extern NSString *const Signal_Message_Reply_Identifier; extern NSString *const Signal_Message_MarkAsRead_Identifier; diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 4d4adf650..7bd65cb7c 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -20,6 +20,8 @@ NSString *const Signal_Thread_UserInfo_Key = @"Signal_Thread_Id"; NSString *const Signal_Message_UserInfo_Key = @"Signal_Message_Id"; NSString *const Signal_Full_New_Message_Category = @"Signal_Full_New_Message"; +NSString *const Signal_Full_New_Message_Category_No_Longer_Verified = + @"Signal_Full_New_Message_Category_No_Longer_Verified"; NSString *const Signal_Message_Reply_Identifier = @"Signal_New_Message_Reply"; NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRead"; @@ -315,12 +317,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe } - (UIUserNotificationCategory *)fullNewMessageNotificationCategory { - UIMutableUserNotificationAction *action_markRead = [UIMutableUserNotificationAction new]; - action_markRead.identifier = Signal_Message_MarkAsRead_Identifier; - action_markRead.title = NSLocalizedString(@"PUSH_MANAGER_MARKREAD", nil); - action_markRead.destructive = NO; - action_markRead.authenticationRequired = NO; - action_markRead.activationMode = UIUserNotificationActivationModeBackground; + UIMutableUserNotificationAction *action_markRead = [self markAsReadAction]; UIMutableUserNotificationAction *action_reply = [UIMutableUserNotificationAction new]; action_reply.identifier = Signal_Message_Reply_Identifier; @@ -342,6 +339,29 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe return messageCategory; } +- (UIUserNotificationCategory *)fullNewMessageNoLongerVerifiedNotificationCategory +{ + UIMutableUserNotificationAction *action_markRead = [self markAsReadAction]; + + UIMutableUserNotificationCategory *messageCategory = [UIMutableUserNotificationCategory new]; + messageCategory.identifier = Signal_Full_New_Message_Category_No_Longer_Verified; + [messageCategory setActions:@[ action_markRead ] forContext:UIUserNotificationActionContextMinimal]; + [messageCategory setActions:@[ action_markRead ] forContext:UIUserNotificationActionContextDefault]; + + return messageCategory; +} + +- (UIMutableUserNotificationAction *)markAsReadAction +{ + UIMutableUserNotificationAction *action = [UIMutableUserNotificationAction new]; + action.identifier = Signal_Message_MarkAsRead_Identifier; + action.title = NSLocalizedString(@"PUSH_MANAGER_MARKREAD", nil); + action.destructive = NO; + action.authenticationRequired = NO; + action.activationMode = UIUserNotificationActivationModeBackground; + return action; +} + #pragma mark - Signal Calls NSString *const PushManagerCategoriesIncomingCall = @"PushManagerCategoriesIncomingCall"; @@ -437,6 +457,7 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationType)[self allNotificationTypes] categories:[NSSet setWithObjects:[self fullNewMessageNotificationCategory], + [self fullNewMessageNoLongerVerifiedNotificationCategory], [self signalIncomingCallCategory], [self signalMissedCallCategory], [self signalMissedCallWithNoLongerVerifiedIdentityChangeCategory], From e48d51d08496ef4fd3afdb554bb0078a934f5ec8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 23 Jun 2017 14:18:17 -0400 Subject: [PATCH 2/2] Respond to CR. // FREEBIE --- Signal/src/environment/NotificationsManager.m | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 88edf3359..13fd350b7 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -264,12 +264,20 @@ switch (self.notificationPreviewType) { case NotificationNamePreview: { - BOOL senderIsNoLongerVerified = - [OWSIdentityManager.sharedManager verificationStateForRecipientId:message.authorId] - == OWSVerificationStateNoLongerVerified; - notification.category = (senderIsNoLongerVerified ? Signal_Full_New_Message_Category_No_Longer_Verified - : Signal_Full_New_Message_Category); + // Don't reply from lockscreen if anyone in this conversation is + // "no longer verified". + BOOL isNoLongerVerified = NO; + for (NSString *recipientId in thread.recipientIdentifiers) { + if ([OWSIdentityManager.sharedManager verificationStateForRecipientId:recipientId] + == OWSVerificationStateNoLongerVerified) { + isNoLongerVerified = YES; + break; + } + } + + notification.category = (isNoLongerVerified ? Signal_Full_New_Message_Category_No_Longer_Verified + : Signal_Full_New_Message_Category); notification.userInfo = @{Signal_Thread_UserInfo_Key : thread.uniqueId, Signal_Message_UserInfo_Key : message.uniqueId};