diff --git a/.changeset/enhance_unsupportedcontent_and_brokencontent_to_display_message_body.md b/.changeset/enhance_unsupportedcontent_and_brokencontent_to_display_message_body.md new file mode 100644 index 00000000..983247a2 --- /dev/null +++ b/.changeset/enhance_unsupportedcontent_and_brokencontent_to_display_message_body.md @@ -0,0 +1,5 @@ +--- +sable: patch +--- + +Enhance UnsupportedContent and BrokenContent to display message body diff --git a/src/app/components/RenderMessageContent.tsx b/src/app/components/RenderMessageContent.tsx index 3c2ded07..93a697c6 100644 --- a/src/app/components/RenderMessageContent.tsx +++ b/src/app/components/RenderMessageContent.tsx @@ -366,7 +366,7 @@ function RenderMessageContentInternal({ mentionedUserIds={content?.['m.mentions']?.user_ids} /> ); - return ; + return ; } export const RenderMessageContent = memo(RenderMessageContentInternal); diff --git a/src/app/components/message/MsgTypeRenderers.tsx b/src/app/components/message/MsgTypeRenderers.tsx index 44b4b83c..edd1af26 100644 --- a/src/app/components/message/MsgTypeRenderers.tsx +++ b/src/app/components/message/MsgTypeRenderers.tsx @@ -52,18 +52,22 @@ export function RedactedContent({ reason }: RedactedContentProps) { ); } -export function UnsupportedContent() { +type BrokenContentProps = { + body?: string; +}; + +export function UnsupportedContent({ body }: BrokenContentProps) { return ( - + ); } -export function BrokenContent() { +export function BrokenContent({ body }: BrokenContentProps) { return ( - + ); } @@ -117,7 +121,7 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }: return true; }, [trimmedBody, safeCustomBody]); - if (!body) return ; + if (!body) return ; const urlsMatch = renderUrlsPreview && trimmedBody.match(URL_REG); const urls = urlsMatch ? [...new Set(urlsMatch)] : undefined; @@ -170,7 +174,9 @@ export function MEmote({ const { body, formatted_body: customBody } = content; const [jumboEmojiSize] = useSetting(settingsAtom, 'jumboEmojiSize'); - if (typeof body !== 'string') return ; + if (typeof body !== 'string') { + return ; + } const trimmedBody = trimReplyFromBody(body); const urlsMatch = renderUrlsPreview && trimmedBody.match(URL_REG); const urls = urlsMatch ? [...new Set(urlsMatch)] : undefined; @@ -205,7 +211,9 @@ export function MNotice({ edited, content, renderBody, renderUrlsPreview }: MNot const { body, formatted_body: customBody } = content; const [jumboEmojiSize] = useSetting(settingsAtom, 'jumboEmojiSize'); - if (typeof body !== 'string') return ; + if (typeof body !== 'string') { + return ; + } const trimmedBody = trimReplyFromBody(body); const urlsMatch = renderUrlsPreview && trimmedBody.match(URL_REG); const urls = urlsMatch ? [...new Set(urlsMatch)] : undefined; @@ -248,7 +256,7 @@ export function MImage({ content, renderImageContent, outlined }: MImageProps) { const imgInfo = content?.info; const mxcUrl = content.file?.url ?? content.url; if (typeof mxcUrl !== 'string') { - return ; + return ; } const MAX_SIZE = 400; const imgW = imgInfo?.w ?? MAX_SIZE; @@ -310,7 +318,7 @@ export function MVideo({ content, renderAsFile, renderVideoContent, outlined }: if (mxcUrl) { return renderAsFile(); } - return ; + return ; } const height = Math.min(scaleYDimension(videoInfo.w || 400, 400, videoInfo.h || 400), 400); @@ -379,7 +387,7 @@ export function MAudio({ content, renderAsFile, renderAudioContent, outlined }: if (mxcUrl) { return renderAsFile(); } - return ; + return ; } const filename = content.filename ?? content.body ?? 'Audio'; @@ -430,7 +438,7 @@ export function MFile({ content, renderFileContent, outlined }: MFileProps) { const mxcUrl = content.file?.url ?? content.url; if (typeof mxcUrl !== 'string') { - return ; + return ; } return ( @@ -461,8 +469,9 @@ type MLocationProps = { }; export function MLocation({ content }: MLocationProps) { const geoUri = content.geo_uri; - if (typeof geoUri !== 'string') return ; - + if (typeof geoUri !== 'string') { + return ; + } const location = parseGeoUri(geoUri); if (!location) return ; @@ -493,7 +502,7 @@ export function MSticker({ content, renderImageContent }: MStickerProps) { const imgInfo = content?.info; const mxcUrl = content.file?.url ?? content.url; if (typeof mxcUrl !== 'string') { - return ; + return ; } const height = scaleYDimension(imgInfo?.w || 152, 152, imgInfo?.h || 152); diff --git a/src/app/components/message/content/FallbackContent.tsx b/src/app/components/message/content/FallbackContent.tsx index 8156a5d0..9bd012a1 100644 --- a/src/app/components/message/content/FallbackContent.tsx +++ b/src/app/components/message/content/FallbackContent.tsx @@ -16,12 +16,16 @@ export const MessageDeletedContent = as<'div', { children?: never; reason?: stri ) ); -export const MessageUnsupportedContent = as<'div', { children?: never }>(({ ...props }, ref) => ( - - - Unsupported message - -)); +export const MessageUnsupportedContent = as<'div', { children?: never; body?: string }>( + ({ body, ...props }, ref) => ( + + + Unsupported message + {body && `: ${body}`} + {!body && ' (no body)'} + + ) +); export const MessageFailedContent = as<'div', { children?: never }>(({ ...props }, ref) => ( @@ -44,12 +48,17 @@ export const MessageNotDecryptedContent = as<'div', { children?: never }>(({ ... )); -export const MessageBrokenContent = as<'div', { children?: never }>(({ ...props }, ref) => ( - - - Broken message - -)); +// display body of the message if it is available, as it may give some clue about why the message is broken +export const MessageBrokenContent = as<'div', { children?: never; body?: string }>( + ({ body, ...props }, ref) => ( + + + Broken message + {body && `: ${body}`} + {!body && ' (no body)'} + + ) +); export const MessageEmptyContent = as<'div', { children?: never }>(({ ...props }, ref) => (