diff --git a/lib/shared/messages/create-sub-thread-message-spec.js b/lib/shared/messages/create-sub-thread-message-spec.js --- a/lib/shared/messages/create-sub-thread-message-spec.js +++ b/lib/shared/messages/create-sub-thread-message-spec.js @@ -18,11 +18,11 @@ import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import { ET, type EntityText } from '../../utils/entity-text'; +import { notifTextsForSubthreadCreation } from '../notif-utils'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type NotificationTextsParams, type GeneratesNotifsParams, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -129,20 +129,19 @@ async notificationTexts( messageInfos: $ReadOnlyArray, threadInfo: ThreadInfo, - params: NotificationTextsParams, ): Promise { const messageInfo = assertSingleMessageInfo(messageInfos); invariant( messageInfo.type === messageTypes.CREATE_SUB_THREAD, 'messageInfo should be messageTypes.CREATE_SUB_THREAD!', ); - return params.notifTextForSubthreadCreation( - messageInfo.creator, - messageInfo.childThreadInfo.type, - threadInfo, - messageInfo.childThreadInfo.name, - messageInfo.childThreadInfo.uiName, - ); + return notifTextsForSubthreadCreation({ + creator: messageInfo.creator, + threadType: messageInfo.childThreadInfo.type, + parentThreadInfo: threadInfo, + childThreadName: messageInfo.childThreadInfo.name, + childThreadUIName: messageInfo.childThreadInfo.uiName, + }); }, generatesNotifs: async ( diff --git a/lib/shared/messages/create-thread-message-spec.js b/lib/shared/messages/create-thread-message-spec.js --- a/lib/shared/messages/create-thread-message-spec.js +++ b/lib/shared/messages/create-thread-message-spec.js @@ -20,12 +20,12 @@ type EntityText, pluralizeEntityText, } from '../../utils/entity-text'; -import { stringForUser } from '../user-utils'; +import { notifTextsForSubthreadCreation } from '../notif-utils'; +import { threadNoun } from '../thread-utils'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type NotificationTextsParams, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -142,29 +142,36 @@ async notificationTexts( messageInfos: $ReadOnlyArray, threadInfo: ThreadInfo, - params: NotificationTextsParams, ): Promise { const messageInfo = assertSingleMessageInfo(messageInfos); invariant( messageInfo.type === messageTypes.CREATE_THREAD, 'messageInfo should be messageTypes.CREATE_THREAD!', ); + + const threadType = messageInfo.initialThreadState.type; const parentThreadInfo = messageInfo.initialThreadState.parentThreadInfo; + const threadName = messageInfo.initialThreadState.name; + if (parentThreadInfo) { - return params.notifTextForSubthreadCreation( - messageInfo.creator, - messageInfo.initialThreadState.type, + return notifTextsForSubthreadCreation({ + creator: messageInfo.creator, + threadType, parentThreadInfo, - messageInfo.initialThreadState.name, - threadInfo.uiName, - ); + childThreadName: threadName, + childThreadUIName: threadInfo.uiName, + }); } - const prefix = stringForUser(messageInfo.creator); - const body = 'created a new chat'; - let merged = `${prefix} ${body}`; - if (messageInfo.initialThreadState.name) { - merged += ` called "${messageInfo.initialThreadState.name}"`; + + const creator = ET.user({ userInfo: messageInfo.creator }); + const prefix = ET`${creator}`; + + const body = `created a new ${threadNoun(threadType)}`; + let merged = ET`${prefix} ${body}`; + if (threadName) { + merged = ET`${merged} called "${threadName}"`; } + return { merged, body, diff --git a/lib/shared/messages/message-spec.js b/lib/shared/messages/message-spec.js --- a/lib/shared/messages/message-spec.js +++ b/lib/shared/messages/message-spec.js @@ -11,7 +11,7 @@ } from '../../types/message-types'; import type { RawUnsupportedMessageInfo } from '../../types/messages/unsupported'; import type { NotifTexts } from '../../types/notif-types'; -import type { ThreadInfo, ThreadType } from '../../types/thread-types'; +import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import type { EntityText } from '../../utils/entity-text'; import { type ParserRules } from '../markdown'; @@ -45,13 +45,6 @@ export type NotificationTextsParams = { +notifThreadName: (threadInfo: ThreadInfo) => string, - +notifTextForSubthreadCreation: ( - creator: RelativeUserInfo, - threadType: ThreadType, - parentThreadInfo: ThreadInfo, - childThreadName: ?string, - childThreadUIName: string, - ) => NotifTexts, +notificationTexts: ( messageInfos: $ReadOnlyArray, threadInfo: ThreadInfo, diff --git a/lib/shared/notif-utils.js b/lib/shared/notif-utils.js --- a/lib/shared/notif-utils.js +++ b/lib/shared/notif-utils.js @@ -24,7 +24,6 @@ import { robotextForMessageInfo } from './message-utils'; import { messageSpecs } from './messages/message-specs'; import { threadNoun } from './thread-utils'; -import { stringForUser } from './user-utils'; async function notifTextsForMessageInfo( messageInfos: MessageInfo[], @@ -92,29 +91,43 @@ }; } -const notifTextForSubthreadCreation = ( - creator: RelativeUserInfo, - threadType: ThreadType, - parentThreadInfo: ThreadInfo, - childThreadName: ?string, - childThreadUIName: string, -) => { - const prefix = stringForUser(creator); +type NotifTextsForSubthreadCreationInput = { + +creator: RelativeUserInfo, + +threadType: ThreadType, + +parentThreadInfo: ThreadInfo, + +childThreadName: ?string, + +childThreadUIName: EntityText | string, +}; +function notifTextsForSubthreadCreation( + input: NotifTextsForSubthreadCreationInput, +): NotifTexts { + const { + creator, + threadType, + parentThreadInfo, + childThreadName, + childThreadUIName, + } = input; + + const prefix = ET`${ET.user({ userInfo: creator })}`; + let body = `created a new ${threadNoun(threadType)}`; if (parentThreadInfo.name) { - body += ` in ${parentThreadInfo.name}`; + body = ET`${body} in ${parentThreadInfo.name}`; } - let merged = `${prefix} ${body}`; + + let merged = ET`${prefix} ${body}`; if (childThreadName) { - merged += ` called "${childThreadName}"`; + merged = ET`${merged} called "${childThreadName}"`; } + return { merged, body, title: childThreadUIName, prefix, }; -}; +} function notifThreadName(threadInfo: ThreadInfo): string { if (threadInfo.name) { @@ -158,7 +171,6 @@ threadInfo, { notifThreadName, - notifTextForSubthreadCreation, notificationTexts: innerNotificationTexts, }, ); @@ -240,6 +252,7 @@ notifRobotextForMessageInfo, notifTextsForMessageInfo, notifTextsForEntryCreationOrEdit, + notifTextsForSubthreadCreation, notifCollapseKeyForRawMessageInfo, mergePrefixIntoBody, };