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] Message_AllowedMaxSize fails for emoji sequences #10431

Merged
merged 17 commits into from
Jun 12, 2018

Conversation

c0dzilla
Copy link
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
Copy link
Contributor

cardoso commented Apr 11, 2018

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
Copy link
Member

@sampaiodiego sampaiodiego left a comment

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
Copy link
Contributor Author

c0dzilla commented Apr 17, 2018

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

@cardoso
Copy link
Contributor

cardoso commented Apr 19, 2018

@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
Member

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

@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
Copy link
Contributor Author

c0dzilla commented May 31, 2018

@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
Copy link
Member

@ggazzo ggazzo left a comment

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
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
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 😅

@@ -554,7 +554,13 @@ this.ChatMessages = class ChatMessages {
}

isMessageTooLong(message) {
return message && message.length > this.messageMaxSize;
const adjustedMessage = message.replace(/:\w+:/gm, (match) => {
Copy link
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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants