React with thumbs up.

This commit is contained in:
Matthew Chen 2020-08-03 10:25:08 -03:00
parent c735935ad5
commit 1ba6d84003
7 changed files with 50 additions and 1 deletions

View File

@ -131,6 +131,33 @@ class NotificationActionHandler {
thread.markAllAsRead(updateStorageService: true, transaction: transaction)
}
}
func reactWithThumbsUp(userInfo: [AnyHashable: Any]) throws -> Promise<Void> {
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 {

View File

@ -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)
}
}
}

View File

@ -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";

View File

@ -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"
}
}
}

View File

@ -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: [])
}
}

View File

@ -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")

View File

@ -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)