-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: Size of the single emoji in chat along with updated Emoji Regex #5039
Conversation
@deetergp I've added my changes and I am currently testing the coverage of the regex. The initial results look good with few exceptions. |
@deetergp PR updated. Please review. |
@deetergp PR updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the changes!
src/libs/Emoji/getEmojiUnicode.js
Outdated
* Get the unicode code of an emoji in base 16. | ||
* | ||
* @name emojiUnicode | ||
* @function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make these docs more consistent with the others in our app. Notably, @name
and @function
+ the repeated name before the description. We won't find these anywhere so I think better to not use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay noted.
src/libs/Emoji/getEmojiUnicode.js
Outdated
@@ -0,0 +1,38 @@ | |||
/* eslint radix: ["error", "as-needed"] */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we silencing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt
also accepts a second param radix
, which I've marked as-needed
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just add the radix?
src/libs/Emoji/getEmojiUnicode.js
Outdated
} | ||
|
||
if (input.length === 1) { | ||
return input.charCodeAt(0).toString().split(' ').map(val => parseInt(val).toString(16)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use _.map()
src/libs/Emoji/getEmojiUnicode.js
Outdated
for (let i = 0; i < input.length; i++) { | ||
if (input.charCodeAt(i) >= 0xd800 && input.charCodeAt(i) <= 0xdbff) { // high surrogate | ||
if (input.charCodeAt(i + 1) >= 0xdc00 && input.charCodeAt(i + 1) <= 0xdfff) { | ||
// low surrogate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a surrogate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the emojis are stored as two Unicodes. Hence we call each of the Unicode as high surrogate and low surrogate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it thanks. I'm not really familiar with this language - could we maybe add a comment that briefly explains what we mean when we refer to a "surrogate"?
src/libs/Emoji/getEmojiUnicode.js
Outdated
pairs.push(input.charCodeAt(i)); | ||
} | ||
} | ||
return pairs.map(val => parseInt(val).toString(16)).join(' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_.map()
src/libs/ValidationUtils.js
Outdated
@@ -2,6 +2,8 @@ import moment from 'moment'; | |||
import CONST from '../CONST'; | |||
import {showBankAccountFormValidationError, showBankAccountErrorModal} from './actions/BankAccounts'; | |||
import {translateLocal} from './translate'; | |||
import getEmojiUnicode from './Emoji/getEmojiUnicode'; | |||
import trimEmojiUnicode from './Emoji/trimEmojiUnicode'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably these could be combined into a single file called EmojiUtils.js
or something? We don't enforce one file per method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay noted
src/libs/ValidationUtils.js
Outdated
return message.length === matchedEmoji.length; | ||
const matchedUnicode = getEmojiUnicode(matchedEmoji); | ||
const currentMessageUnicode = trimEmojiUnicode(getEmojiUnicode(message)); | ||
return matchedUnicode === currentMessageUnicode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure when isSingleEmoji()
was added - but it doesn't belongs in this file. ValidationUtils
is for validating user input into a form field not to check if something is an emoji. Let's please move it somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay should I move it to EmojiUtils
, that I'll create for the above functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works for me! Thanks!
…ngle-emoji-size
…ngle-emoji-size
@marcaaron PR updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks for the changes!
src/libs/EmojiUtils.js
Outdated
@@ -0,0 +1,76 @@ | |||
/* eslint radix: ["error", "as-needed"] */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just add the radix here.. is it something other than 10
? That's what we do everywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, with Emojis you can’t be sure that the you’ll get an integer with base 10. This could be because copy pasting emojis from other apps. If you see the code, we are splitting a string and it could start with 0x too.
Added radix.
🚀 Deployed to staging by @marcaaron in version: 1.0.97-2 🚀
|
This has been deployed to production and is now subject to a 7-day regression period. |
🚀 Deployed to production by @francoisl in version: 1.0.98-1 🚀
|
@deetergp I've updated my changes with the regex changes and a unit test to verify all the emojis in our dataset.
Details
isSingleEmoji
functionFixed Issues
$ #4543
Tests
QA Steps
Tested On
Screenshots
Web
Mobile Web
Desktop
iOS
Android