diff --git a/src/components/messenger/list/index.tsx b/src/components/messenger/list/index.tsx index 3b26dbff3..26d2691cc 100644 --- a/src/components/messenger/list/index.tsx +++ b/src/components/messenger/list/index.tsx @@ -389,7 +389,7 @@ function addLastMessageMeta(state: RootState): any { return { ...conversation, mostRecentMessage, - messagePreview: getMessagePreview(mostRecentMessage, state), + messagePreview: getMessagePreview(mostRecentMessage, state, conversation.isOneOnOne), previewDisplayDate: previewDisplayDate(mostRecentMessage?.createdAt), }; }; diff --git a/src/lib/chat/chat-message.test.ts b/src/lib/chat/chat-message.test.ts index ce915c4f6..a68a05769 100644 --- a/src/lib/chat/chat-message.test.ts +++ b/src/lib/chat/chat-message.test.ts @@ -389,6 +389,30 @@ describe(getMessagePreview, () => { expect(preview).toEqual('Admin: System update or change occurred'); }); + + it('does not add prefix for one-on-one conversations', function () { + const state = new StoreBuilder().withCurrentUser({ id: 'current-user' }).build(); + + const preview = getMessagePreview( + { message: 'some message', sender: { userId: 'another-user', firstName: 'Jack' } } as Message, + state, + true // isOneOnOne + ); + + expect(preview).toEqual('some message'); + }); + + it('adds prefix for group conversations', function () { + const state = new StoreBuilder().withCurrentUser({ id: 'current-user' }).build(); + + const preview = getMessagePreview( + { message: 'some message', sender: { userId: 'another-user', firstName: 'Jack' } } as Message, + state, + false // isOneOnOne + ); + + expect(preview).toEqual('Jack: some message'); + }); }); describe(previewDisplayDate, () => { diff --git a/src/lib/chat/chat-message.ts b/src/lib/chat/chat-message.ts index 608ded8cf..087b71c9a 100644 --- a/src/lib/chat/chat-message.ts +++ b/src/lib/chat/chat-message.ts @@ -22,13 +22,13 @@ export function previewDisplayDate(timestamp: number, currentDate = moment()) { return messageDate.format('MMM D, YYYY'); } -export function getMessagePreview(message: Message, state: RootState) { +export function getMessagePreview(message: Message, state: RootState, isOneOnOne: boolean = false) { if (!message) { return 'Admin: System update or change occurred'; } if (message.sendStatus === MessageSendStatus.FAILED) { - return 'You: Failed to send'; + return isOneOnOne ? 'Failed to send' : 'You: Failed to send'; } if (message.isAdmin) { @@ -36,15 +36,21 @@ export function getMessagePreview(message: Message, state: RootState) { } if (message.isPost) { - let prefix = previewPrefix(message.sender, state); - return `${prefix}: shared a new post`; + let prefix = previewPrefix(message.sender, state, isOneOnOne); + return prefix ? `${prefix}: shared a new post` : 'shared a new post'; } - let prefix = previewPrefix(message.sender, state); - return `${prefix}: ${message.message || getMediaPreview(message)}`; + let prefix = previewPrefix(message.sender, state, isOneOnOne); + return prefix + ? `${prefix}: ${message.message || getMediaPreview(message)}` + : `${message.message || getMediaPreview(message)}`; } -function previewPrefix(sender: Message['sender'], state: RootState) { +function previewPrefix(sender: Message['sender'], state: RootState, isOneOnOne: boolean) { + if (isOneOnOne) { + return ''; + } + const user = currentUserSelector()(state); return sender.userId === user.id ? 'You' : sender.firstName; }