diff --git a/lib/shared/messages/reaction-message-spec.js b/lib/shared/messages/reaction-message-spec.js --- a/lib/shared/messages/reaction-message-spec.js +++ b/lib/shared/messages/reaction-message-spec.js @@ -6,16 +6,26 @@ import { assertMessageType, messageTypes, + type MessageInfo, type ClientDBMessageInfo, type ReactionMessageData, type RawReactionMessageInfo, type ReactionMessageInfo, } from '../../types/message-types'; import type { RawUnsupportedMessageInfo } from '../../types/messages/unsupported'; +import type { NotifTexts } from '../../types/notif-types'; +import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import { messagePreviewText, removeCreatorAsViewer } from '../message-utils'; +import { threadIsGroupChat } from '../thread-utils'; +import { stringForUser } from '../user-utils'; import { hasMinCodeVersion } from '../version-utils'; -import type { MessageSpec, MessageTitleParam } from './message-spec'; +import type { + MessageSpec, + MessageTitleParam, + NotificationTextsParams, +} from './message-spec'; +import { assertSingleMessageInfo } from './utils'; export const reactionMessageSpec: MessageSpec< ReactionMessageData, @@ -150,5 +160,38 @@ return unwrapped; }, - generatesNotifs: false, + notificationTexts( + messageInfos: $ReadOnlyArray, + threadInfo: ThreadInfo, + params: NotificationTextsParams, + ): NotifTexts { + const messageInfo = assertSingleMessageInfo(messageInfos); + invariant( + messageInfo.type === messageTypes.REACTION, + 'messageInfo should be reaction type', + ); + + const userString = stringForUser(messageInfo.creator); + const body = + messageInfo.action === 'add_reaction' + ? 'liked a message' + : 'unliked a message'; + + let merged; + if (!threadInfo.name && !threadIsGroupChat(threadInfo)) { + merged = `${userString} ${body}`; + } else { + const threadName = params.notifThreadName(threadInfo); + merged = `${userString} ${body} in ${threadName}`; + } + + return { + merged, + body, + title: threadInfo.uiName, + prefix: userString, + }; + }, + + generatesNotifs: true, });