From 1ba6d8400327ee35efea896f5cdee53e8da37c77 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 3 Aug 2020 10:25:08 -0300 Subject: [PATCH] React with thumbs up. --- Signal/src/NotificationActionHandler.swift | 27 +++++++++++++++++++ .../src/UserNotificationActionHandler.swift | 2 ++ .../translations/en.lproj/Localizable.strings | 3 +++ .../Notifications/AppNotifications.swift | 9 ++++++- .../UserNotificationsAdaptee.swift | 4 +++ SignalMessaging/Views/CommonStrings.swift | 3 +++ SignalServiceKit/src/Util/FeatureFlags.swift | 3 +++ 7 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Signal/src/NotificationActionHandler.swift b/Signal/src/NotificationActionHandler.swift index 3f886b686a..832ecff19d 100644 --- a/Signal/src/NotificationActionHandler.swift +++ b/Signal/src/NotificationActionHandler.swift @@ -131,6 +131,33 @@ class NotificationActionHandler { thread.markAllAsRead(updateStorageService: true, transaction: transaction) } } + + func reactWithThumbsUp(userInfo: [AnyHashable: Any]) throws -> Promise { + guard let threadId = userInfo[AppNotificationUserInfoKey.threadId] as? String else { + throw NotificationError.failDebug("threadId was unexpectedly nil") + } + guard let messageId = userInfo[AppNotificationUserInfoKey.messageId] as? String else { + throw NotificationError.failDebug("messageId was unexpectedly nil") + } + + return databaseStorage.write(.promise) { transaction in + guard let thread = TSThread.anyFetch(uniqueId: threadId, transaction: transaction) else { + throw NotificationError.failDebug("unable to find thread with id: \(threadId)") + } + guard let interaction = TSInteraction.anyFetch(uniqueId: messageId, transaction: transaction) else { + throw NotificationError.failDebug("unable to find interaction with id: \(messageId)") + } + guard let incomingMessage = interaction as? TSIncomingMessage else { + throw NotificationError.failDebug("Unexpected interaction type.") + } + + ReactionManager.localUserReacted(to: incomingMessage, emoji: "👍", isRemoving: false, transaction: transaction) + + let hasPendingMessageRequest = thread.hasPendingMessageRequest(transaction: transaction.unwrapGrdbWrite) + let readCircumstance: OWSReadCircumstance = (hasPendingMessageRequest ? .readOnThisDeviceWhilePendingMessageRequest : .readOnThisDevice) + incomingMessage.markAsRead(atTimestamp: NSDate.ows_millisecondTimeStamp(), thread: thread, circumstance: readCircumstance, transaction: transaction) + } + } } extension ThreadUtil { diff --git a/Signal/src/UserNotificationActionHandler.swift b/Signal/src/UserNotificationActionHandler.swift index b2aba852b9..36246d302b 100644 --- a/Signal/src/UserNotificationActionHandler.swift +++ b/Signal/src/UserNotificationActionHandler.swift @@ -66,6 +66,8 @@ public class UserNotificationActionHandler: NSObject { return try actionHandler.reply(userInfo: userInfo, replyText: textInputResponse.userText) case .showThread: return try actionHandler.showThread(userInfo: userInfo) + case .reactWithThumbsUp: + return try actionHandler.reactWithThumbsUp(userInfo: userInfo) } } } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 2e2cb1e9b0..e6aa44b7a6 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -3059,6 +3059,9 @@ /* Notification action button title */ "PUSH_MANAGER_MARKREAD" = "Mark as Read"; +/* Notification action button title for 'react with thumbs up.' */ +"PUSH_MANAGER_REACT_WITH_THUMBS_UP" = "React with 👍"; + /* Notification action button title */ "PUSH_MANAGER_REPLY" = "Reply"; diff --git a/SignalMessaging/Notifications/AppNotifications.swift b/SignalMessaging/Notifications/AppNotifications.swift index 8d36c6bb37..cd7be5464c 100644 --- a/SignalMessaging/Notifications/AppNotifications.swift +++ b/SignalMessaging/Notifications/AppNotifications.swift @@ -40,6 +40,7 @@ public enum AppNotificationAction: CaseIterable { case markAsRead case reply case showThread + case reactWithThumbsUp } public struct AppNotificationUserInfoKey { @@ -80,7 +81,11 @@ extension AppNotificationCategory { var actions: [AppNotificationAction] { switch self { case .incomingMessageWithActions: - return [.markAsRead, .reply] + if DebugFlags.reactWithThumbsUpFromLockscreen { + return [.reply, .reactWithThumbsUp] + } else { + return [.markAsRead, .reply] + } case .incomingMessageWithoutActions: return [] case .incomingMessageFromNoLongerVerifiedIdentity: @@ -118,6 +123,8 @@ extension AppNotificationAction { return "Signal.AppNotifications.Action.reply" case .showThread: return "Signal.AppNotifications.Action.showThread" + case .reactWithThumbsUp: + return "Signal.AppNotifications.Action.reactWithThumbsUp" } } } diff --git a/SignalMessaging/Notifications/UserNotificationsAdaptee.swift b/SignalMessaging/Notifications/UserNotificationsAdaptee.swift index 5983966216..efe20a9b51 100644 --- a/SignalMessaging/Notifications/UserNotificationsAdaptee.swift +++ b/SignalMessaging/Notifications/UserNotificationsAdaptee.swift @@ -52,6 +52,10 @@ public class UserNotificationConfig { return UNNotificationAction(identifier: action.identifier, title: CallStrings.showThreadButtonTitle, options: [.foreground]) + case .reactWithThumbsUp: + return UNNotificationAction(identifier: action.identifier, + title: MessageStrings.reactWithThumbsUpNotificationAction, + options: []) } } diff --git a/SignalMessaging/Views/CommonStrings.swift b/SignalMessaging/Views/CommonStrings.swift index 9e1df05e4b..0683776f6d 100644 --- a/SignalMessaging/Views/CommonStrings.swift +++ b/SignalMessaging/Views/CommonStrings.swift @@ -94,6 +94,9 @@ public class MessageStrings: NSObject { @objc static public let markAsReadNotificationAction = NSLocalizedString("PUSH_MANAGER_MARKREAD", comment: "Notification action button title") + @objc + static public let reactWithThumbsUpNotificationAction = NSLocalizedString("PUSH_MANAGER_REACT_WITH_THUMBS_UP", comment: "Notification action button title for 'react with thumbs up.'") + @objc static public let sendButton = NSLocalizedString("SEND_BUTTON_TITLE", comment: "Label for the button to send a message") diff --git a/SignalServiceKit/src/Util/FeatureFlags.swift b/SignalServiceKit/src/Util/FeatureFlags.swift index c2d94ab0b6..20929f02be 100644 --- a/SignalServiceKit/src/Util/FeatureFlags.swift +++ b/SignalServiceKit/src/Util/FeatureFlags.swift @@ -413,6 +413,9 @@ public class DebugFlags: BaseFlags { @objc public static let forceVersionedProfiles = build.includes(.beta) + @objc + public static let reactWithThumbsUpFromLockscreen = build.includes(.qa) + public static func buildFlagMap() -> [String: Any] { BaseFlags.buildFlagMap(for: DebugFlags.self) { (key: String) -> Any? in DebugFlags.value(forKey: key)