[FIX] Message_AllowedMaxSize fails for emoji sequences#10431
Conversation
6a0d1fe to
0c9dfc2
Compare
0c9dfc2 to
d458112
Compare
|
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. |
sampaiodiego
left a comment
There was a problem hiding this comment.
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.
595f344 to
e2c5d13
Compare
|
@sampaiodiego I've converted emoji unicodes to shortnames using |
|
@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. |
|
Here is a possible solution https://stackoverflow.com/a/46085089 |
| // converting emoji unicodes to shortnames if present | ||
| let adjustedMessage = emojione.toShort(message.msg); | ||
|
|
||
| adjustedMessage = adjustedMessage.replace(/:\w+:/gm, (match) => { |
There was a problem hiding this comment.
Why is this part still needed? 🤔
|
Why not use |
|
Also, I think Unit Tests will be a good idea here 👍 Testing cases like the one pointed out in the issue
|
|
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). |
d157709 to
61b6c28
Compare
99812f1 to
ba74537
Compare
|
@sampaiodiego @graywolf336 please have a look :) |
3f0119c to
1f3bd47
Compare
ggazzo
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
this test on 'message' should not be done before?
There was a problem hiding this comment.
Yeah, sorry about that 😅
|
|
||
| isMessageTooLong(message) { | ||
| return message && message.length > this.messageMaxSize; | ||
| const adjustedMessage = message.replace(/:\w+:/gm, (match) => { |
There was a problem hiding this comment.
I think we have this replace in two places... maybe use an export/import? (:
728ca2f to
2053ec1
Compare
|
@ggazzo I've made the changes |
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

now works and has effective size 10.