Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix big emoji in replies #10932

Merged
merged 4 commits into from
May 18, 2023
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
18 changes: 10 additions & 8 deletions src/HtmlUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,23 +571,16 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
});
safeBody = phtml.html();
}
if (bodyHasEmoji) {
safeBody = formatEmojis(safeBody, true).join("");
}
} else if (highlighter) {
safeBody = highlighter.applyHighlights(escapeHtml(plainBody), safeHighlights!).join("");
}
} finally {
delete sanitizeParams.textFilter;
}

const contentBody = safeBody ?? strippedBody;
if (opts.returnString) {
return contentBody;
}

let emojiBody = false;
if (!opts.disableBigEmoji && bodyHasEmoji) {
const contentBody = safeBody ?? strippedBody;
let contentBodyTrimmed = contentBody !== undefined ? contentBody.trim() : "";

// Remove zero width joiner, zero width spaces and other spaces in body
Expand All @@ -607,6 +600,15 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
(!content.formatted_body.includes("http:") && !content.formatted_body.includes("https:")));
}

if (isFormattedBody && bodyHasEmoji && safeBody) {
// This has to be done after the emojiBody check above as to not break big emoji on replies
safeBody = formatEmojis(safeBody, true).join("");
}

if (opts.returnString) {
return safeBody ?? strippedBody;
}

const className = classNames({
"mx_EventTile_body": true,
"mx_EventTile_bigEmoji": emojiBody,
Expand Down
25 changes: 25 additions & 0 deletions test/HtmlUtils-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,29 @@ describe("bodyToHtml", () => {

expect(html).toMatchInlineSnapshot(`"<span class="mx_EventTile_searchHighlight">test</span> foo &lt;b&gt;bar"`);
});

it("should generate big emoji for an emoji-only reply to a message", () => {
const { asFragment } = render(
bodyToHtml(
{
"body": "> <@sender1:server> Test\n\n🥰",
"format": "org.matrix.custom.html",
"formatted_body":
'<mx-reply><blockquote><a href="https://matrix.to/#/!roomId:server/$eventId">In reply to</a> <a href="https://matrix.to/#/@sender1:server">@sender1:server</a><br>Test</blockquote></mx-reply>🥰',
"m.relates_to": {
"m.in_reply_to": {
event_id: "$eventId",
},
},
"msgtype": "m.text",
},
[],
{
stripReplyFallback: true,
},
) as ReactElement,
);

expect(asFragment()).toMatchSnapshot();
});
});
17 changes: 17 additions & 0 deletions test/__snapshots__/HtmlUtils-test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`bodyToHtml should generate big emoji for an emoji-only reply to a message 1`] = `
<DocumentFragment>
<span
class="mx_EventTile_body mx_EventTile_bigEmoji"
dir="auto"
>
<span
class="mx_Emoji"
title=":smiling_face_with_3_hearts:"
>
🥰
</span>
</span>
</DocumentFragment>
`;
Loading