From 08425853cf6123188ecdef49d898a7ec0fc88f1e Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 2 Feb 2017 17:42:06 -0500 Subject: [PATCH] re-use shared call strings // FREEBIE --- .../UserNotificationsAdaptee.swift | 11 ++++++----- Signal/src/UserInterface/Strings.swift | 18 ++++++++++-------- Signal/src/environment/NotificationsManager.m | 8 ++++---- Signal/src/network/PushManager.m | 18 +++++++++--------- .../translations/en.lproj/Localizable.strings | 6 ++---- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift b/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift index 62aca5054..135583cb4 100644 --- a/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift +++ b/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift @@ -1,5 +1,6 @@ -// Created by Michael Kirk on 12/23/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// /** * TODO This is currently unused code. I started implenting new notifications as UserNotifications rather than the deprecated @@ -41,7 +42,7 @@ struct AppNotifications { switch type { case .callBack: return UNNotificationAction(identifier: "org.whispersystems.signal.AppNotifications.Action.callBack", - title: Strings.Calls.callBackButtonTitle, + title: CallStrings.callBackButtonTitle, options: .authenticationRequired) } } @@ -100,9 +101,9 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot let notificationBody = { () -> String in switch previewType { case .noNameNoPreview: - return Strings.Calls.missedCallNotificationBody + return CallStrings.missedCallNotificationBody case .nameNoPreview, .namePreview: - let format = Strings.Calls.missedCallNotificationBodyWithCallerName + let format = CallStrings.missedCallNotificationBodyWithCallerName return String(format: format, callerName) }}() diff --git a/Signal/src/UserInterface/Strings.swift b/Signal/src/UserInterface/Strings.swift index 89bcc532f..02ceeef35 100644 --- a/Signal/src/UserInterface/Strings.swift +++ b/Signal/src/UserInterface/Strings.swift @@ -1,12 +1,14 @@ -// Created by Michael Kirk on 12/29/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// import Foundation -@objc class Strings: NSObject { - @objc class Calls: 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}}") - } +/** + * Strings re-used in multiple places should be added here. + */ +@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}}") } diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 181a64e55..ab85c5364 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -61,7 +61,7 @@ notification.soundName = @"NewMessage.aifc"; switch (self.notificationPreviewType) { case NotificationNoNameNoPreview: { - notification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"MISSED_CALL", nil)]; + notification.alertBody = [CallStrings missedCallNotificationBody]; break; } case NotificationNamePreview: @@ -69,7 +69,7 @@ notification.userInfo = @{ Signal_Call_UserInfo_Key : cThread.contactIdentifier }; notification.category = Signal_CallBack_Category; notification.alertBody = - [NSString stringWithFormat:NSLocalizedString(@"MSGVIEW_MISSED_CALL", nil), [thread name]]; + [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], [thread name]]; break; } } @@ -130,13 +130,13 @@ NSString *alertMessage; switch (self.notificationPreviewType) { case NotificationNoNameNoPreview: { - alertMessage = [NSString stringWithFormat:NSLocalizedString(@"MISSED_CALL", @"notification body")]; + alertMessage = [CallStrings missedCallNotificationBody]; break; } case NotificationNameNoPreview: case NotificationNamePreview: { alertMessage = - [NSString stringWithFormat:NSLocalizedString(@"MSGVIEW_MISSED_CALL", @"notification body"), callerName]; + [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], callerName]; break; } } diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 516b24239..8dd563b87 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -489,17 +489,17 @@ - (UIUserNotificationCategory *)userNotificationsRPCallBackCategory { - UIMutableUserNotificationAction *action_accept = [UIMutableUserNotificationAction new]; - action_accept.identifier = Signal_CallBack_Identifier; - action_accept.title = NSLocalizedString(@"CALLBACK_BUTTON_TITLE", @""); - action_accept.activationMode = UIUserNotificationActivationModeForeground; - action_accept.destructive = NO; - action_accept.authenticationRequired = NO; + UIMutableUserNotificationAction *callBackAction = [UIMutableUserNotificationAction new]; + callBackAction.identifier = Signal_CallBack_Identifier; + callBackAction.title = [CallStrings callBackButtonTitle]; + callBackAction.activationMode = UIUserNotificationActivationModeForeground; + callBackAction.destructive = NO; + callBackAction.authenticationRequired = NO; UIMutableUserNotificationCategory *callCategory = [UIMutableUserNotificationCategory new]; callCategory.identifier = Signal_CallBack_Category; - [callCategory setActions:@[ action_accept ] forContext:UIUserNotificationActionContextMinimal]; - [callCategory setActions:@[ action_accept ] forContext:UIUserNotificationActionContextDefault]; + [callCategory setActions:@[ callBackAction ] forContext:UIUserNotificationActionContextMinimal]; + [callCategory setActions:@[ callBackAction ] forContext:UIUserNotificationActionContextDefault]; return callCategory; } @@ -544,7 +544,7 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager { UIMutableUserNotificationAction *callBackAction = [UIMutableUserNotificationAction new]; callBackAction.identifier = PushManagerActionsCallBack; - callBackAction.title = NSLocalizedString(@"CALLBACK_BUTTON_TITLE", @""); + callBackAction.title = [CallStrings callBackButtonTitle]; callBackAction.activationMode = UIUserNotificationActivationModeForeground; callBackAction.destructive = NO; callBackAction.authenticationRequired = YES; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 4a8d2dc9a..c744c3565 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -445,8 +445,7 @@ /* {{number of minutes}} embedded in strings, e.g. 'Alice updated disappearing messages expiration to {{5 minutes}}'. See other *_TIME_AMOUNT strings */ "MINUTES_TIME_AMOUNT" = "%u minutes"; -/* notification body - notification title */ +/* notification title */ "MISSED_CALL" = "Missed call"; /* Alert body @@ -457,8 +456,7 @@ Alert title when camera is not authorized */ "MISSING_CAMERA_PERMISSION_TITLE" = "Signal needs to access your camera."; -/* notification body - notification title. Embeds {{Caller's Name}} */ +/* notification title. Embeds {{Caller's Name}} */ "MSGVIEW_MISSED_CALL" = "Missed call from %@."; /* No comment provided by engineer. */