diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js --- a/lib/shared/message-utils.js +++ b/lib/shared/message-utils.js @@ -31,7 +31,7 @@ } from '../types/messages/reaction'; import { type ThreadInfo } from '../types/thread-types'; import type { UserInfos } from '../types/user-types'; -import type { EntityText } from '../utils/entity-text'; +import { type EntityText, entityTextToRawString } from '../utils/entity-text'; import { codeBlockRegex, type ParserRules } from './markdown'; import { messageSpecs } from './messages/message-specs'; import { threadIsGroupChat } from './thread-utils'; @@ -361,22 +361,26 @@ markdownRules: ParserRules, viewerContext?: GetMessageTitleViewerContext = 'individual_viewer', ): string { + let entityText; const { messageTitle } = messageSpecs[messageInfo.type]; - return messageTitle({ - messageInfo, - threadInfo, - markdownRules, - viewerContext, + if (!messageTitle) { + invariant( + messageInfo.type !== messageTypes.TEXT && + messageInfo.type !== messageTypes.IMAGES && + messageInfo.type !== messageTypes.MULTIMEDIA && + messageInfo.type !== messageTypes.REACTION, + 'messageTitle can only be auto-generated for RobotextMessageInfo', + ); + entityText = robotextForMessageInfo(messageInfo, threadInfo); + } else { + entityText = messageTitle({ messageInfo, threadInfo, markdownRules }); + } + return entityTextToRawString(entityText, { + threadID: threadInfo.id, + ignoreViewer: viewerContext === 'global_viewer', }); } -function removeCreatorAsViewer(messageInfo: Info): Info { - return { - ...messageInfo, - creator: { ...messageInfo.creator, isViewer: false }, - }; -} - function mergeThreadMessageInfos( first: ThreadMessageInfo, second: ThreadMessageInfo, @@ -522,7 +526,6 @@ createMessageReply, getMostRecentNonLocalMessageID, getMessageTitle, - removeCreatorAsViewer, mergeThreadMessageInfos, useMessagePreview, }; diff --git a/lib/shared/messages/add-members-message-spec.js b/lib/shared/messages/add-members-message-spec.js --- a/lib/shared/messages/add-members-message-spec.js +++ b/lib/shared/messages/add-members-message-spec.js @@ -19,17 +19,11 @@ ET, type EntityText, pluralizeEntityText, - entityTextToRawString, } from '../../utils/entity-text'; import { values } from '../../utils/objects'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import type { CreateMessageInfoParams, MessageSpec, - MessageTitleParam, NotificationTextsParams, } from './message-spec'; import { joinResult } from './utils'; @@ -49,27 +43,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: AddMembersMessageInfo = (messageInfo: AddMembersMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - validMessageInfo = { - ...validMessageInfo, - addedMembers: validMessageInfo.addedMembers.map(item => ({ - ...item, - isViewer: false, - })), - }; - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawAddMembersMessageInfo { return { type: messageTypes.ADD_MEMBERS, diff --git a/lib/shared/messages/change-role-message-spec.js b/lib/shared/messages/change-role-message-spec.js --- a/lib/shared/messages/change-role-message-spec.js +++ b/lib/shared/messages/change-role-message-spec.js @@ -19,18 +19,12 @@ ET, type EntityText, pluralizeEntityText, - entityTextToRawString, } from '../../utils/entity-text'; import { values } from '../../utils/objects'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, type RobotextParams, } from './message-spec'; @@ -54,27 +48,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: ChangeRoleMessageInfo = (messageInfo: ChangeRoleMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - validMessageInfo = { - ...validMessageInfo, - members: validMessageInfo.members.map(item => ({ - ...item, - isViewer: false, - })), - }; - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawChangeRoleMessageInfo { const content = JSON.parse(row.content); return { diff --git a/lib/shared/messages/change-settings-message-spec.js b/lib/shared/messages/change-settings-message-spec.js --- a/lib/shared/messages/change-settings-message-spec.js +++ b/lib/shared/messages/change-settings-message-spec.js @@ -16,21 +16,12 @@ import { assertThreadType } from '../../types/thread-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; +import { ET, type EntityText } from '../../utils/entity-text'; import { validHexColorRegex } from '../account-utils'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import { threadLabel } from '../thread-utils'; import { pushTypes, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, } from './message-spec'; import { joinResult } from './utils'; @@ -52,20 +43,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: ChangeSettingsMessageInfo = (messageInfo: ChangeSettingsMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawChangeSettingsMessageInfo { const content = JSON.parse(row.content); const field = Object.keys(content)[0]; diff --git a/lib/shared/messages/create-entry-message-spec.js b/lib/shared/messages/create-entry-message-spec.js --- a/lib/shared/messages/create-entry-message-spec.js +++ b/lib/shared/messages/create-entry-message-spec.js @@ -16,20 +16,11 @@ import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import { prettyDate } from '../../utils/date-utils'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { ET, type EntityText } from '../../utils/entity-text'; import { stringForUser } from '../user-utils'; import { pushTypes, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, } from './message-spec'; import { joinResult } from './utils'; @@ -53,20 +44,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: CreateEntryMessageInfo = (messageInfo: CreateEntryMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawCreateEntryMessageInfo { const content = JSON.parse(row.content); return { 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 @@ -21,19 +21,13 @@ ET, type EntityText, pluralizeEntityText, - entityTextToRawString, } from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import { stringForUser } from '../user-utils'; import { hasMinCodeVersion } from '../version-utils'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type MessageTitleParam, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -55,36 +49,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: CreateSidebarMessageInfo = (messageInfo: CreateSidebarMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - validMessageInfo = { - ...validMessageInfo, - sourceMessageAuthor: { - ...validMessageInfo.sourceMessageAuthor, - isViewer: false, - }, - initialThreadState: { - ...validMessageInfo.initialThreadState, - otherMembers: validMessageInfo.initialThreadState.otherMembers.map( - item => ({ - ...item, - isViewer: false, - }), - ), - }, - }; - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawCreateSidebarMessageInfo { const { sourceMessageAuthorID, ...initialThreadState } = JSON.parse( row.content, 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 @@ -17,20 +17,11 @@ import { threadPermissions, threadTypes } from '../../types/thread-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { ET, type EntityText } from '../../utils/entity-text'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, type GeneratesNotifsParams, } from './message-spec'; @@ -51,20 +42,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: CreateSubthreadMessageInfo = (messageInfo: CreateSubthreadMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): ?RawCreateSubthreadMessageInfo { const subthreadPermissions = row.subthread_permissions; if (!permissionLookup(subthreadPermissions, threadPermissions.KNOW_OF)) { 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 @@ -19,18 +19,12 @@ ET, type EntityText, pluralizeEntityText, - entityTextToRawString, } from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import { stringForUser } from '../user-utils'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -50,32 +44,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: CreateThreadMessageInfo = (messageInfo: CreateThreadMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - validMessageInfo = { - ...validMessageInfo, - initialThreadState: { - ...validMessageInfo.initialThreadState, - otherMembers: validMessageInfo.initialThreadState.otherMembers.map( - item => ({ - ...item, - isViewer: false, - }), - ), - }, - }; - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawCreateThreadMessageInfo { return { type: messageTypes.CREATE_THREAD, diff --git a/lib/shared/messages/delete-entry-message-spec.js b/lib/shared/messages/delete-entry-message-spec.js --- a/lib/shared/messages/delete-entry-message-spec.js +++ b/lib/shared/messages/delete-entry-message-spec.js @@ -16,20 +16,11 @@ import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import { prettyDate } from '../../utils/date-utils'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { ET, type EntityText } from '../../utils/entity-text'; import { stringForUser } from '../user-utils'; import { pushTypes, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -53,20 +44,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: DeleteEntryMessageInfo = (messageInfo: DeleteEntryMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawDeleteEntryMessageInfo { const content = JSON.parse(row.content); return { diff --git a/lib/shared/messages/edit-entry-message-spec.js b/lib/shared/messages/edit-entry-message-spec.js --- a/lib/shared/messages/edit-entry-message-spec.js +++ b/lib/shared/messages/edit-entry-message-spec.js @@ -16,20 +16,11 @@ import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import { prettyDate } from '../../utils/date-utils'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { ET, type EntityText } from '../../utils/entity-text'; import { stringForUser } from '../user-utils'; import { pushTypes, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, } from './message-spec'; import { joinResult } from './utils'; @@ -53,20 +44,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: EditEntryMessageInfo = (messageInfo: EditEntryMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawEditEntryMessageInfo { const content = JSON.parse(row.content); return { diff --git a/lib/shared/messages/join-thread-message-spec.js b/lib/shared/messages/join-thread-message-spec.js --- a/lib/shared/messages/join-thread-message-spec.js +++ b/lib/shared/messages/join-thread-message-spec.js @@ -15,23 +15,11 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; +import { ET, type EntityText } from '../../utils/entity-text'; import { values } from '../../utils/objects'; import { pluralize } from '../../utils/text-utils'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import { stringForUser } from '../user-utils'; -import type { - MessageSpec, - MessageTitleParam, - NotificationTextsParams, -} from './message-spec'; +import type { MessageSpec, NotificationTextsParams } from './message-spec'; import { joinResult } from './utils'; export const joinThreadMessageSpec: MessageSpec< @@ -62,20 +50,6 @@ return rawJoinThreadMessageInfo; }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: JoinThreadMessageInfo = (messageInfo: JoinThreadMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - createMessageInfo( rawMessageInfo: RawJoinThreadMessageInfo, creator: RelativeUserInfo, diff --git a/lib/shared/messages/leave-thread-message-spec.js b/lib/shared/messages/leave-thread-message-spec.js --- a/lib/shared/messages/leave-thread-message-spec.js +++ b/lib/shared/messages/leave-thread-message-spec.js @@ -15,23 +15,11 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; +import { ET, type EntityText } from '../../utils/entity-text'; import { values } from '../../utils/objects'; import { pluralize } from '../../utils/text-utils'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import { stringForUser } from '../user-utils'; -import type { - MessageSpec, - MessageTitleParam, - NotificationTextsParams, -} from './message-spec'; +import type { MessageSpec, NotificationTextsParams } from './message-spec'; import { joinResult } from './utils'; export const leaveThreadMessageSpec: MessageSpec< @@ -62,20 +50,6 @@ return rawLeaveThreadMessageInfo; }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: LeaveThreadMessageInfo = (messageInfo: LeaveThreadMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - createMessageInfo( rawMessageInfo: RawLeaveThreadMessageInfo, creator: RelativeUserInfo, 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 @@ -16,13 +16,11 @@ import type { RelativeUserInfo } from '../../types/user-types'; import type { EntityText } from '../../utils/entity-text'; import { type ParserRules } from '../markdown'; -import type { GetMessageTitleViewerContext } from '../message-utils'; export type MessageTitleParam = { +messageInfo: Info, +threadInfo: ThreadInfo, +markdownRules: ParserRules, - +viewerContext?: GetMessageTitleViewerContext, }; export type RawMessageInfoFromServerDBRowParams = { @@ -80,7 +78,7 @@ export type MessageSpec = { +messageContentForServerDB?: (data: Data | RawInfo) => string, +messageContentForClientDB?: (data: RawInfo) => string, - +messageTitle: (param: MessageTitleParam) => string, + +messageTitle?: (param: MessageTitleParam) => EntityText, +rawMessageInfoFromServerDBRow?: ( row: Object, params: RawMessageInfoFromServerDBRowParams, diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js --- a/lib/shared/messages/multimedia-message-spec.js +++ b/lib/shared/messages/multimedia-message-spec.js @@ -18,7 +18,6 @@ MessageInfo, RawMessageInfo, RawMultimediaMessageInfo, - MultimediaMessageInfo, ClientDBMessageInfo, } from '../../types/message-types'; import type { @@ -36,14 +35,12 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; +import { ET } from '../../utils/entity-text'; import { translateClientDBMediaInfosToMedia, translateClientDBMediaInfoToImage, } from '../../utils/message-ops-utils'; -import { - createMediaMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { createMediaMessageInfo } from '../message-utils'; import { threadIsGroupChat } from '../thread-utils'; import { stringForUser } from '../user-utils'; import { hasMinCodeVersion } from '../version-utils'; @@ -128,15 +125,10 @@ messageTitle({ messageInfo, - viewerContext, }: MessageTitleParam) { - let validMessageInfo: MultimediaMessageInfo = (messageInfo: MultimediaMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - const creator = stringForUser(validMessageInfo.creator); - const preview = multimediaMessagePreview(validMessageInfo); - return `${creator} ${preview}`; + const creator = ET.user({ userInfo: messageInfo.creator }); + const preview = multimediaMessagePreview(messageInfo); + return ET`${creator} ${preview}`; }, rawMessageInfoFromServerDBRow( 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 @@ -18,7 +18,7 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { removeCreatorAsViewer } from '../message-utils'; +import { ET } from '../../utils/entity-text'; import { threadIsGroupChat } from '../thread-utils'; import { stringForUser } from '../user-utils'; import { hasMinCodeVersion } from '../version-utils'; @@ -53,21 +53,13 @@ }); }, - messageTitle({ - messageInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: ReactionMessageInfo = (messageInfo: ReactionMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - - const creator = stringForUser(validMessageInfo.creator); + messageTitle({ messageInfo }: MessageTitleParam) { + const creator = ET.user({ userInfo: messageInfo.creator }); const preview = - validMessageInfo.action === 'add_reaction' + messageInfo.action === 'add_reaction' ? 'reacted to a message' : 'unreacted to a message'; - return `${creator} ${preview}`; + return ET`${creator} ${preview}`; }, rawMessageInfoFromServerDBRow(row: Object): RawReactionMessageInfo { diff --git a/lib/shared/messages/remove-members-message-spec.js b/lib/shared/messages/remove-members-message-spec.js --- a/lib/shared/messages/remove-members-message-spec.js +++ b/lib/shared/messages/remove-members-message-spec.js @@ -19,17 +19,11 @@ ET, type EntityText, pluralizeEntityText, - entityTextToRawString, } from '../../utils/entity-text'; import { values } from '../../utils/objects'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; import type { CreateMessageInfoParams, MessageSpec, - MessageTitleParam, NotificationTextsParams, } from './message-spec'; import { joinResult } from './utils'; @@ -49,27 +43,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: RemoveMembersMessageInfo = (messageInfo: RemoveMembersMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - validMessageInfo = { - ...validMessageInfo, - removedMembers: validMessageInfo.removedMembers.map(item => ({ - ...item, - isViewer: false, - })), - }; - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawRemoveMembersMessageInfo { return { type: messageTypes.REMOVE_MEMBERS, diff --git a/lib/shared/messages/restore-entry-message-spec.js b/lib/shared/messages/restore-entry-message-spec.js --- a/lib/shared/messages/restore-entry-message-spec.js +++ b/lib/shared/messages/restore-entry-message-spec.js @@ -16,20 +16,11 @@ import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; import { prettyDate } from '../../utils/date-utils'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { ET, type EntityText } from '../../utils/entity-text'; import { stringForUser } from '../user-utils'; import { pushTypes, type MessageSpec, - type MessageTitleParam, type NotificationTextsParams, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -53,20 +44,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: RestoreEntryMessageInfo = (messageInfo: RestoreEntryMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawRestoreEntryMessageInfo { const content = JSON.parse(row.content); return { diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -16,6 +16,7 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; +import { ET } from '../../utils/entity-text'; import { type ASTNode, type SingleASTNode, @@ -94,7 +95,7 @@ const ast = stripSpoilersFromMarkdownAST( parser(text, { disableAutoBlockNewlines: true }), ); - return getFirstNonQuotedRawLine(ast).trim(); + return ET`${getFirstNonQuotedRawLine(ast).trim()}`; }, rawMessageInfoFromServerDBRow( diff --git a/lib/shared/messages/unsupported-message-spec.js b/lib/shared/messages/unsupported-message-spec.js --- a/lib/shared/messages/unsupported-message-spec.js +++ b/lib/shared/messages/unsupported-message-spec.js @@ -11,20 +11,8 @@ UnsupportedMessageInfo, } from '../../types/messages/unsupported'; import type { RelativeUserInfo } from '../../types/user-types'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; -import { - pushTypes, - type MessageSpec, - type MessageTitleParam, -} from './message-spec'; +import { ET, type EntityText } from '../../utils/entity-text'; +import { pushTypes, type MessageSpec } from './message-spec'; export const unsupportedMessageSpec: MessageSpec< null, @@ -77,20 +65,6 @@ }; }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: UnsupportedMessageInfo = (messageInfo: UnsupportedMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - robotext(messageInfo: UnsupportedMessageInfo): EntityText { if (messageInfo.dontPrefixCreator) { return ET`${messageInfo.robotext}`; diff --git a/lib/shared/messages/update-relationship-message-spec.js b/lib/shared/messages/update-relationship-message-spec.js --- a/lib/shared/messages/update-relationship-message-spec.js +++ b/lib/shared/messages/update-relationship-message-spec.js @@ -17,22 +17,13 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { - ET, - type EntityText, - entityTextToRawString, -} from '../../utils/entity-text'; -import { - robotextForMessageInfo, - removeCreatorAsViewer, -} from '../message-utils'; +import { ET, type EntityText } from '../../utils/entity-text'; import { stringForUser } from '../user-utils'; import { hasMinCodeVersion } from '../version-utils'; import { pushTypes, type CreateMessageInfoParams, type MessageSpec, - type MessageTitleParam, } from './message-spec'; import { assertSingleMessageInfo } from './utils'; @@ -54,24 +45,6 @@ return this.messageContentForServerDB(data); }, - messageTitle({ - messageInfo, - threadInfo, - viewerContext, - }: MessageTitleParam) { - let validMessageInfo: UpdateRelationshipMessageInfo = (messageInfo: UpdateRelationshipMessageInfo); - if (viewerContext === 'global_viewer') { - validMessageInfo = removeCreatorAsViewer(validMessageInfo); - validMessageInfo = { - ...validMessageInfo, - target: { ...validMessageInfo.target, isViewer: false }, - }; - } - return entityTextToRawString( - robotextForMessageInfo(validMessageInfo, threadInfo), - ); - }, - rawMessageInfoFromServerDBRow(row: Object): RawUpdateRelationshipMessageInfo { const content = JSON.parse(row.content); return { diff --git a/lib/utils/entity-text.js b/lib/utils/entity-text.js --- a/lib/utils/entity-text.js +++ b/lib/utils/entity-text.js @@ -235,28 +235,36 @@ return name; } -function getNameForUserEntity(entity: UserEntity): string { - const str = stringForUser(entity); - const { isViewer, possessive } = entity; - if (!possessive) { +function getNameForUserEntity( + entity: UserEntity, + ignoreViewer: ?boolean, +): string { + const isViewer = entity.isViewer && !ignoreViewer; + const hackedEntity = { ...entity, isViewer }; + const str = stringForUser(hackedEntity); + if (!hackedEntity.possessive) { return str; } return makePossessive({ str, isViewer }); } +type EntityTextToRawStringParams = { + +threadID?: ?string, + +ignoreViewer?: ?boolean, +}; function entityTextToRawString( entityText: EntityText, - threadID: ?string, + params?: EntityTextToRawStringParams, ): string { const textParts = entityText.map(entity => { if (typeof entity === 'string') { return entity; } else if (entity.type === 'thread') { - return getNameForThreadEntity(entity, threadID); + return getNameForThreadEntity(entity, params?.threadID); } else if (entity.type === 'color') { return entity.hex; } else if (entity.type === 'user') { - return getNameForUserEntity(entity); + return getNameForUserEntity(entity, params?.ignoreViewer); } else { invariant( false, diff --git a/native/chat/chat-item-height-measurer.react.js b/native/chat/chat-item-height-measurer.react.js --- a/native/chat/chat-item-height-measurer.react.js +++ b/native/chat/chat-item-height-measurer.react.js @@ -30,7 +30,8 @@ if (messageInfo.type === messageTypes.TEXT) { return messageInfo.text; } else if (item.robotext) { - return entityTextToRawString(item.robotext, item.messageInfo.threadID); + const { threadID } = item.messageInfo; + return entityTextToRawString(item.robotext, { threadID }); } return null; }; diff --git a/native/chat/inner-robotext-message.react.js b/native/chat/inner-robotext-message.react.js --- a/native/chat/inner-robotext-message.react.js +++ b/native/chat/inner-robotext-message.react.js @@ -26,7 +26,7 @@ return ( - {entityTextToRawString(robotext, threadID)} + {entityTextToRawString(robotext, { threadID })} );