Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Prevent user pills containing only emoji from embiggening #2907

Merged
merged 5 commits into from
Apr 17, 2019

Conversation

anoadragon453
Copy link
Member

Fixes element-hq/element-web#8035

Emoji-only messages shouldn't have a formatted body. User pill messages do. We can exploit this to prevent user-pill username messages from being blown up.

image

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a more reliable way to detect mentions. The pill itself is well-specified: https://matrix.org/docs/spec/client_server/r0.4.0.html#user-room-and-group-mentions

@anoadragon453
Copy link
Member Author

anoadragon453 commented Apr 10, 2019 via email

@turt2live
Copy link
Member

turt2live commented Apr 10, 2019

if the formatted_body contains just emoji though, we should be rendering it big too.

@anoadragon453
Copy link
Member Author

In practice Riot web doesn't do this, but you're right, other clients might. In that case we can just check to embiggen if:

  • formatted_body doesn't exist
  • formatted_body does exist, but it == body

@turt2live
Copy link
Member

I'd argue that wrapped emoji and such also count as "just emoji". Things like:

  • <p>😄😄😄</p>
  • 😄&nbsp;😄&nbsp;😄
  • <span>😄😄😄</span>
  • etc

@anoadragon453
Copy link
Member Author

Right then, if that's the case then we're quickly going to be chasing a theoretical edge case and we should just mitigate the tangible problem for now.

We could be relatively specific and check if a message contains just an <a> then don't embiggen.

@turt2live
Copy link
Member

honestly I'd look for formatted_body.includes("https://matrix.to/") instead.

@anoadragon453
Copy link
Member Author

That works too.

src/HtmlUtils.js Outdated
emojiBody = match && match[0] && match[0].length === contentBodyTrimmed.length
// Prevent user pills expanding for users with only emoji in
// their username
&& !content.formatted_body.includes("https://matrix.to/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need a (content.formatted_body && !content.formatted_body.includes(...)) here just in case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, very good point.

src/HtmlUtils.js Outdated
@@ -519,7 +519,7 @@ export function bodyToHtml(content, highlights, opts={}) {
emojiBody = match && match[0] && match[0].length === contentBodyTrimmed.length
// Prevent user pills expanding for users with only emoji in
// their username
&& !content.formatted_body.includes("https://matrix.to/");
&& (content.formatted_body && !content.formatted_body.includes("https://matrix.to/"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I might be a liar, sorry. Should be !formatted || !includes because otherwise it'll give false positives

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the logic here? With || it'll no longer check whether formatted_body is undefined and thus fail on the includes check if it is.

Did you mean:

... && (!content.formatted_body || (content.formatted_body && content.formatted_body.includes(...)))

?

@turt2live turt2live self-requested a review April 16, 2019 03:21
@turt2live turt2live merged commit 9f494fc into develop Apr 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All-Emoji nicknames in pills become large if they are the only message content
2 participants