Skip to content

[FIX] Message_AllowedMaxSize fails for emoji sequences#10431

Merged
ggazzo merged 17 commits into
RocketChat:developfrom
c0dzilla:max-msg-size-emoji
Jun 12, 2018
Merged

[FIX] Message_AllowedMaxSize fails for emoji sequences#10431
ggazzo merged 17 commits into
RocketChat:developfrom
c0dzilla:max-msg-size-emoji

Conversation

@c0dzilla

Copy link
Copy Markdown
Contributor

Closes #10422

This pr ensures emojis are treated as single characters when determining if message size exceeds allowed limit, for better experience.

Taking same example as mentioned in issue, if max allowed size is 10
image

now works and has effective size 10.

@c0dzilla c0dzilla force-pushed the max-msg-size-emoji branch 2 times, most recently from 6a0d1fe to 0c9dfc2 Compare April 11, 2018 20:36
@c0dzilla c0dzilla force-pushed the max-msg-size-emoji branch from 0c9dfc2 to d458112 Compare April 11, 2018 20:43
@cardoso

cardoso commented Apr 11, 2018

Copy link
Copy Markdown
Member

Is this working only for :shortname: ?

Or is it covering also the case where the user types the actual "👨‍👨‍👧‍👦" emoji instead of its :shortname: . From the iOS emoji keyboard for instance.

When I said emoji sequences I meant unicode sequences.

@theorenck theorenck added this to the 0.64.0 milestone Apr 11, 2018
@theorenck theorenck requested a review from sampaiodiego April 11, 2018 22:31

@sampaiodiego sampaiodiego left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks @c0dzilla ..

looking at the code it is only taking care of :emojis: and not unicode ones.. can you please confirm that and make sure you have the same behavior for both (treating them as only one character)?

there is function called emojione.shortnameToUnicode that might help you.

@c0dzilla c0dzilla force-pushed the max-msg-size-emoji branch from 595f344 to e2c5d13 Compare April 17, 2018 20:18
@RocketChat RocketChat deleted a comment Apr 17, 2018
@RocketChat RocketChat deleted a comment Apr 17, 2018
@c0dzilla

c0dzilla commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

@sampaiodiego I've converted emoji unicodes to shortnames using toShort() while checking the length. I think it should handle that as well now.

@cardoso

cardoso commented Apr 19, 2018

Copy link
Copy Markdown
Member

@c0dzilla @sampaiodiego we need a better solution than this. Converting back to shortname would imply that this solution only works for unicode graphemes with a corresponding shortname, which is very limiting. The iOS App for instance has many more emojis than in the Web App.

We need a generic solution for counting unicode graphemes. From what I've searched, it's non-trivial in JS and we may need a new dependency, but I think it's worth it.

@theorenck theorenck modified the milestones: 0.64.0, 0.65.0 Apr 23, 2018
@rodrigok

Copy link
Copy Markdown
Member

Here is a possible solution https://stackoverflow.com/a/46085089

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 May 22, 2018 22:25 Inactive
// converting emoji unicodes to shortnames if present
let adjustedMessage = emojione.toShort(message.msg);

adjustedMessage = adjustedMessage.replace(/:\w+:/gm, (match) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this part still needed? 🤔

@graywolf336

Copy link
Copy Markdown
Contributor

Why not use Array.from instead of underscore's?

@cardoso

cardoso commented May 23, 2018

Copy link
Copy Markdown
Member

Also, I think Unit Tests will be a good idea here 👍

Testing cases like the one pointed out in the issue

"123456789👨‍👨‍👧‍👦" works with Message_AllowedMaxSize = 10

@c0dzilla

c0dzilla commented May 23, 2018

Copy link
Copy Markdown
Contributor Author

After having a look at https://news.ycombinator.com/item?id=13830177, it seems that converting string to array will not always give the right length(like for ❤️ it gives length 2 instead of 1).

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 May 23, 2018 08:19 Inactive
@c0dzilla c0dzilla force-pushed the max-msg-size-emoji branch from d157709 to 61b6c28 Compare May 23, 2018 08:21
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 May 23, 2018 08:21 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 May 30, 2018 13:20 Inactive
@c0dzilla c0dzilla force-pushed the max-msg-size-emoji branch from 99812f1 to ba74537 Compare May 30, 2018 13:40
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 May 30, 2018 13:41 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 May 31, 2018 06:02 Inactive
@c0dzilla

c0dzilla commented May 31, 2018

Copy link
Copy Markdown
Contributor Author

@sampaiodiego @graywolf336 please have a look :)

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 5, 2018 06:24 Inactive
@c0dzilla c0dzilla force-pushed the max-msg-size-emoji branch from 3f0119c to 1f3bd47 Compare June 5, 2018 14:05
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 5, 2018 14:05 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 6, 2018 06:27 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 11, 2018 20:49 Inactive
@ggazzo ggazzo temporarily deployed to rocket-chat-pr-10431 June 12, 2018 01:11 Inactive

@ggazzo ggazzo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I really liked your solution, but I got some points, please see if my questions make sense for you

}
return match;
});
return message && RocketChat.messageProperties(adjustedMessage).length > this.messageMaxSize;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this test on 'message' should not be done before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sorry about that 😅


isMessageTooLong(message) {
return message && message.length > this.messageMaxSize;
const adjustedMessage = message.replace(/:\w+:/gm, (match) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we have this replace in two places... maybe use an export/import? (:

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 12, 2018 15:05 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 12, 2018 15:13 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10431 June 12, 2018 16:42 Inactive
@c0dzilla

Copy link
Copy Markdown
Contributor Author

@ggazzo I've made the changes ☺️

@ggazzo ggazzo merged commit b681db6 into RocketChat:develop Jun 12, 2018
@rodrigok rodrigok mentioned this pull request Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants