Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-html-formatting-on-long-messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: minor
---

Re-introduced custom HTML formatting for long messages
19 changes: 5 additions & 14 deletions src/app/components/message/MsgTypeRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
[customBody, body]
);

const safeCustomBody = useMemo(() => {
if (!customBody) return undefined;
if (customBody.length > 8000) {
const imageTags = customBody.match(/<img[^>]*>/g);
return imageTags ? imageTags.join(' ') : undefined;
}
return customBody;
}, [customBody]);

const isForwarded = useMemo(() => {
const forwardMeta = content['moe.sable.message.forward'];
return typeof forwardMeta === 'object';
Expand All @@ -122,20 +113,20 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
const isJumbo = useMemo(() => {
if (!trimmedBody || trimmedBody.length >= 500) return false;
if (
(unwrappedPerMessageProfileMessage ?? safeCustomBody)?.match(
(unwrappedPerMessageProfileMessage ?? customBody)?.match(
/^(<img[^>]*data-mx-emoticon[^>]*\/>){1,20}$/i
)
)
return true;
if (!JUMBO_EMOJI_REG.test(trimmedBody)) return false;

if (trimmedBody.includes(':')) {
const hasImage = safeCustomBody && /<img[^>]*>/i.test(safeCustomBody);
const hasImage = customBody && /<img[^>]*>/i.test(customBody);
if (!hasImage) return false;
}

return true;
}, [unwrappedPerMessageProfileMessage, trimmedBody, safeCustomBody]);
}, [unwrappedPerMessageProfileMessage, trimmedBody, customBody]);

if (!body && !customBody) return <BrokenContent body={customBody ?? body} />;

Expand Down Expand Up @@ -175,13 +166,13 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
return (
<>
<MessageTextBody
preWrap={typeof safeCustomBody !== 'string'}
preWrap={typeof customBody !== 'string'}
jumboEmoji={isJumbo ? jumboEmojiSize : 'none'}
style={style}
>
{renderBody({
body: trimmedBody,
customBody: safeCustomBody,
customBody: typeof customBody === 'string' ? customBody : undefined,
})}
{edited && <MessageEditedContent />}
</MessageTextBody>
Expand Down
Loading