From e9e0c75ed8d208fe2b480f8308ca840208a9736c Mon Sep 17 00:00:00 2001 From: Daisy Date: Wed, 29 Jul 2026 11:55:53 +0100 Subject: [PATCH] Properly format PMP replies --- .changeset/properly_format_pmp_replies.md | 5 +++++ src/app/components/message/Reply.tsx | 25 +++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .changeset/properly_format_pmp_replies.md diff --git a/.changeset/properly_format_pmp_replies.md b/.changeset/properly_format_pmp_replies.md new file mode 100644 index 000000000..1ba3ec239 --- /dev/null +++ b/.changeset/properly_format_pmp_replies.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Properly format PMP replies diff --git a/src/app/components/message/Reply.tsx b/src/app/components/message/Reply.tsx index ccafd4c11..66cf450c2 100644 --- a/src/app/components/message/Reply.tsx +++ b/src/app/components/message/Reply.tsx @@ -62,6 +62,8 @@ import * as css from './Reply.css'; import { LinePlaceholder } from './placeholder'; import { ReactionKeyInline } from './ReactionKeyInline'; import { M_POLL_START, M_TEXT } from 'matrix-js-sdk'; +import type { PerMessageProfileBeeperFormat } from '$hooks/usePerMessageProfile'; +import { convertBeeperFormatToOurPerMessageProfile } from '$hooks/usePerMessageProfile'; const ROOM_REPLY_TIMELINE_EVENT_TYPES = new Set([ EventType.RoomMessage as string, @@ -259,6 +261,20 @@ export const Reply = as<'div', ReplyProps>( : rawContent; const { body, formatted_body: formattedBody, format } = contentForPreview; + + // get pmp from message + const beeperProfile = rawContent['com.beeper.per_message_profile'] as + | PerMessageProfileBeeperFormat + | undefined; + const pmp = beeperProfile + ? convertBeeperFormatToOurPerMessageProfile(beeperProfile) + : undefined; + + // strip the PMP fallback if it's there, to avoid displaying the PMP name twice + const formattedBodyStripped: string = pmp + ? formattedBody?.replace(/^]*>.*?<\/strong>/, '') + : formattedBody; + const extensibleContent = contentForPreview[M_TEXT.name] as | string | { body: string } @@ -307,7 +323,7 @@ export const Reply = as<'div', ReplyProps>( const badEncryption = replyEvent?.getContent().msgtype === 'm.bad.encrypted'; const mentionClickHandler = useMentionClickHandler(room.roomId); const isFormattedReply = - format === 'org.matrix.custom.html' && typeof formattedBody === 'string'; + format === 'org.matrix.custom.html' && typeof formattedBodyStripped === 'string'; const hasPlainTextReply = typeof body === 'string' && body !== ''; const hasExtensibleBody = typeof extensibleBody === 'string' && extensibleBody !== ''; // An encrypted event that hasn't been decrypted yet (keys pending) has an @@ -334,8 +350,8 @@ export const Reply = as<'div', ReplyProps>( image = timelineIcon(ListBullets); if (question) bodyJSX = `'s poll asking ${(question[M_TEXT.name] as string) ?? question?.body ?? ''}`; - } else if (isFormattedReply && formattedBody !== '') { - const sanitizedHtml = sanitizeReplyFormattedPreview(formattedBody); + } else if (isFormattedReply && formattedBodyStripped !== '') { + const sanitizedHtml = sanitizeReplyFormattedPreview(formattedBodyStripped); if (shouldParseReplyFormattedPreview(sanitizedHtml)) { const parserOpts = getReactCustomHtmlParser(mx, room.roomId, { settingsLinkBaseUrl, @@ -496,7 +512,8 @@ export const Reply = as<'div', ReplyProps>( eventType !== EventType.RoomMember && ( - {getMemberDisplayName(room, sender, nicknames) ?? + {pmp?.name ?? + getMemberDisplayName(room, sender, nicknames) ?? cachedProfiles[sender]?.displayName ?? getMxIdLocalPart(sender)}