diff --git a/src/app/components/RenderMessageContent.test.tsx b/src/app/components/RenderMessageContent.test.tsx index 2eb3fbf319..c4c12c511f 100644 --- a/src/app/components/RenderMessageContent.test.tsx +++ b/src/app/components/RenderMessageContent.test.tsx @@ -222,4 +222,14 @@ describe('RenderMessageContent', () => { expect(screen.getByTestId('poll-event')).toBeInTheDocument(); }); + + it('renders a per-message profile emote without a formatted body', () => { + renderMessageWithContent({ + msgtype: MsgType.Emote, + body: 'Bob: waves', + 'com.beeper.per_message_profile': { id: 'bob', displayname: 'Bob' }, + }); + + expect(screen.getByText('waves')).toBeInTheDocument(); + }); }); diff --git a/src/app/components/RenderMessageContent.tsx b/src/app/components/RenderMessageContent.tsx index d8da91dd7e..9e96cc540b 100644 --- a/src/app/components/RenderMessageContent.tsx +++ b/src/app/components/RenderMessageContent.tsx @@ -449,8 +449,12 @@ function RenderMessageContentInternal({ const strippedContent = pmp ? { ...content, - formatted_body: stripPerMessageProfileFormattedBody(content['formatted_body'] as string), - body: stripPerMessageProfilePlainBody(content['body'] as string), + ...(typeof content['formatted_body'] === 'string' + ? { formatted_body: stripPerMessageProfileFormattedBody(content['formatted_body']) } + : {}), + ...(typeof content['body'] === 'string' + ? { body: stripPerMessageProfilePlainBody(content['body']) } + : {}), } : content; diff --git a/src/app/persona/projection.ts b/src/app/persona/projection.ts index b7b5ae0beb..98f3f5dce5 100644 --- a/src/app/persona/projection.ts +++ b/src/app/persona/projection.ts @@ -123,6 +123,8 @@ export function stripPerMessageProfilePlainBody(formatted_body: string, profile? return formatted_body.replace(/^.*?: /, ''); } -export function stripPerMessageProfileFormattedBody(formatted_body: string): string { - return formatted_body.replace(/^]*>.*?<\/strong>/, ''); +export function stripPerMessageProfileFormattedBody( + formatted_body: string | undefined +): string | undefined { + return formatted_body?.replace(/^]*>.*?<\/strong>/, ''); }