Page MenuHomePhorge

D6937.1765211105.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D6937.1765211105.diff

diff --git a/lib/shared/messages/create-sidebar-message-spec.js b/lib/shared/messages/create-sidebar-message-spec.js
--- a/lib/shared/messages/create-sidebar-message-spec.js
+++ b/lib/shared/messages/create-sidebar-message-spec.js
@@ -29,7 +29,7 @@
type EntityText,
pluralizeEntityText,
} from '../../utils/entity-text.js';
-import { isMentioned } from '../mention-utils.js';
+import { notifTextsForSidebarCreation } from '../notif-utils.js';
import { hasMinCodeVersion } from '../version-utils.js';
export const createSidebarMessageSpec: MessageSpec<
@@ -182,45 +182,27 @@
threadInfo: ThreadInfo,
params: NotificationTextsParams,
): Promise<NotifTexts> {
- const firstMessageInfo = messageInfos[0];
+ const createSidebarMessageInfo = messageInfos[0];
invariant(
- firstMessageInfo.type === messageTypes.CREATE_SIDEBAR,
- 'firstMessageInfo should be messageTypes.CREATE_SIDEBAR!',
+ createSidebarMessageInfo.type === messageTypes.CREATE_SIDEBAR,
+ 'first MessageInfo should be messageTypes.CREATE_SIDEBAR!',
);
- const creator = ET.user({ userInfo: firstMessageInfo.creator });
- const prefix = ET`${creator}`;
-
- const initialName = firstMessageInfo.initialThreadState.name;
- const sourceMessageAuthorPossessive = ET.user({
- userInfo: firstMessageInfo.sourceMessageAuthor,
- possessive: true,
- });
-
- let body = `started a thread in response to `;
- body = ET`${body} ${sourceMessageAuthorPossessive} message`;
-
- const { username } = params.notifTargetUserInfo;
-
+ let sidebarSourceMessageInfo;
const secondMessageInfo = messageInfos[1];
if (
- username &&
secondMessageInfo &&
- secondMessageInfo.type === messageTypes.SIDEBAR_SOURCE &&
- secondMessageInfo.sourceMessage.type === messageTypes.TEXT &&
- isMentioned(username, secondMessageInfo.sourceMessage.text)
+ secondMessageInfo.type === messageTypes.SIDEBAR_SOURCE
) {
- body = ET`${body} that tagged you`;
- } else if (initialName) {
- body = ET`${body} "${initialName}"`;
+ sidebarSourceMessageInfo = secondMessageInfo;
}
- return {
- merged: ET`${prefix} ${body}`,
- body,
- title: threadInfo.uiName,
- prefix,
- };
+ return notifTextsForSidebarCreation({
+ createSidebarMessageInfo,
+ sidebarSourceMessageInfo,
+ threadInfo,
+ params,
+ });
},
notificationCollapseKey(rawMessageInfo: RawCreateSidebarMessageInfo): string {
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
@@ -2,7 +2,9 @@
import invariant from 'invariant';
+import { isMentioned } from './mention-utils.js';
import { robotextForMessageInfo } from './message-utils.js';
+import type { NotificationTextsParams } from './messages/message-spec.js';
import { messageSpecs } from './messages/message-specs.js';
import { threadNoun } from './thread-utils.js';
import {
@@ -11,8 +13,10 @@
type RobotextMessageInfo,
type MessageType,
type MessageData,
+ type SidebarSourceMessageInfo,
messageTypes,
} from '../types/message-types.js';
+import type { CreateSidebarMessageInfo } from '../types/messages/create-sidebar.js';
import type { NotifTexts, ResolvedNotifTexts } from '../types/notif-types.js';
import type { ThreadInfo, ThreadType } from '../types/thread-types.js';
import type { RelativeUserInfo, UserInfo } from '../types/user-types.js';
@@ -136,6 +140,55 @@
};
}
+type NotifTextsForSidebarCreationInput = {
+ +createSidebarMessageInfo: CreateSidebarMessageInfo,
+ +sidebarSourceMessageInfo?: ?SidebarSourceMessageInfo,
+ +threadInfo: ThreadInfo,
+ +params: NotificationTextsParams,
+};
+function notifTextsForSidebarCreation(
+ input: NotifTextsForSidebarCreationInput,
+): NotifTexts {
+ const {
+ sidebarSourceMessageInfo,
+ createSidebarMessageInfo,
+ threadInfo,
+ params,
+ } = input;
+
+ const creator = ET.user({ userInfo: createSidebarMessageInfo.creator });
+ const prefix = ET`${creator}`;
+
+ const initialName = createSidebarMessageInfo.initialThreadState.name;
+ const sourceMessageAuthorPossessive = ET.user({
+ userInfo: createSidebarMessageInfo.sourceMessageAuthor,
+ possessive: true,
+ });
+
+ let body = `started a thread in response to `;
+ body = ET`${body} ${sourceMessageAuthorPossessive} message`;
+
+ const { username } = params.notifTargetUserInfo;
+
+ if (
+ username &&
+ sidebarSourceMessageInfo &&
+ sidebarSourceMessageInfo.sourceMessage.type === messageTypes.TEXT &&
+ isMentioned(username, sidebarSourceMessageInfo.sourceMessage.text)
+ ) {
+ body = ET`${body} that tagged you`;
+ } else if (initialName) {
+ body = ET`${body} "${initialName}"`;
+ }
+
+ return {
+ merged: ET`${prefix} ${body}`,
+ body,
+ title: threadInfo.uiName,
+ prefix,
+ };
+}
+
function mostRecentMessageInfoType(
messageInfos: $ReadOnlyArray<MessageInfo>,
): MessageType {
@@ -257,6 +310,7 @@
notifTextsForMessageInfo,
notifTextsForEntryCreationOrEdit,
notifTextsForSubthreadCreation,
+ notifTextsForSidebarCreation,
getNotifCollapseKey,
mergePrefixIntoBody,
};

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 8, 4:25 PM (4 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5849150
Default Alt Text
D6937.1765211105.diff (5 KB)

Event Timeline