From b9b81ca8ef682754e5848f9f033f847dbbc6bcad Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 21 Mar 2017 13:21:31 -0400 Subject: [PATCH] Honor call privacy settings in call notifications. // FREEBIE --- Signal/src/Models/OWSCall.m | 2 +- .../Notifications/UserNotificationsAdaptee.swift | 5 +++-- Signal/src/UserInterface/Strings.swift | 3 ++- Signal/src/environment/NotificationsManager.m | 10 ++++++---- Signal/translations/en.lproj/Localizable.strings | 5 ++++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Signal/src/Models/OWSCall.m b/Signal/src/Models/OWSCall.m index 1e033b485..a6f967879 100644 --- a/Signal/src/Models/OWSCall.m +++ b/Signal/src/Models/OWSCall.m @@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *detailString; switch (status) { case kCallMissed: - detailString = [NSString stringWithFormat:NSLocalizedString(@"MSGVIEW_MISSED_CALL", nil), name]; + detailString = [NSString stringWithFormat:NSLocalizedString(@"MSGVIEW_MISSED_CALL_WITH_NAME", nil), name]; break; case kCallIncoming: detailString = [NSString stringWithFormat:NSLocalizedString(@"MSGVIEW_RECEIVED_CALL", nil), name]; diff --git a/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift b/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift index 135583cb4..744e0c69f 100644 --- a/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift +++ b/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift @@ -103,8 +103,9 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot case .noNameNoPreview: return CallStrings.missedCallNotificationBody case .nameNoPreview, .namePreview: - let format = CallStrings.missedCallNotificationBodyWithCallerName - return String(format: format, callerName) + return (Environment.getCurrent().preferences.isCallKitPrivacyEnabled() + ? CallStrings.missedCallNotificationBodyWithoutCallerName + : String(format: CallStrings.missedCallNotificationBodyWithCallerName, callerName)) }}() content.body = notificationBody diff --git a/Signal/src/UserInterface/Strings.swift b/Signal/src/UserInterface/Strings.swift index 1419ff4ee..9efc38da5 100644 --- a/Signal/src/UserInterface/Strings.swift +++ b/Signal/src/UserInterface/Strings.swift @@ -10,6 +10,7 @@ import Foundation @objc class CallStrings: NSObject { static let callBackButtonTitle = NSLocalizedString("CALLBACK_BUTTON_TITLE", comment: "notification action") static let missedCallNotificationBody = NSLocalizedString("MISSED_CALL", comment: "notification title") - static let missedCallNotificationBodyWithCallerName = NSLocalizedString("MSGVIEW_MISSED_CALL", comment: "notification title. Embeds {{Caller's Name}}") + static let missedCallNotificationBodyWithCallerName = NSLocalizedString("MSGVIEW_MISSED_CALL_WITH_NAME", comment: "notification title. Embeds {{Caller's Name}}") + static let missedCallNotificationBodyWithoutCallerName = NSLocalizedString("MSGVIEW_MISSED_CALL_WITHOUT_NAME", comment: "notification title.") static let callStatusFormat = NSLocalizedString("CALL_STATUS_FORMAT", comment: "embeds {{Call Status}} in call screen label. For ongoing calls, {{Call Status}} is a seconds timer like 01:23, otherwise {{Call Status}} is a short text like 'Ringing', 'Busy', or 'Failed Call'") } diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index ab85c5364..bc47f6d4f 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -68,8 +68,9 @@ case NotificationNameNoPreview: { notification.userInfo = @{ Signal_Call_UserInfo_Key : cThread.contactIdentifier }; notification.category = Signal_CallBack_Category; - notification.alertBody = - [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], [thread name]]; + notification.alertBody = ([[Environment getCurrent].preferences isCallKitPrivacyEnabled] + ? [CallStrings missedCallNotificationBodyWithoutCallerName] + : [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], [thread name]]); break; } } @@ -135,8 +136,9 @@ } case NotificationNameNoPreview: case NotificationNamePreview: { - alertMessage = - [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], callerName]; + alertMessage = ([[Environment getCurrent].preferences isCallKitPrivacyEnabled] + ? [CallStrings missedCallNotificationBodyWithoutCallerName] + : [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], callerName]); break; } } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 1c46c5a1f..8574c829d 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -520,7 +520,10 @@ "MISSING_CAMERA_PERMISSION_TITLE" = "Signal needs to access your camera."; /* notification title. Embeds {{Caller's Name}} */ -"MSGVIEW_MISSED_CALL" = "Missed call from %@."; +"MSGVIEW_MISSED_CALL_WITH_NAME" = "Missed call from %@."; + +/* notification title. */ +"MSGVIEW_MISSED_CALL_WITHOUT_NAME" = "Missed call from Signal User."; /* No comment provided by engineer. */ "MSGVIEW_RECEIVED_CALL" = "You received a call from %@.";