Skip to content

Fix: Size of the single emoji in chat along with updated Emoji Regex#5039

Merged
marcaaron merged 18 commits into
Expensify:mainfrom
mananjadhav:fix/single-emoji-size
Sep 13, 2021
Merged

Fix: Size of the single emoji in chat along with updated Emoji Regex#5039
marcaaron merged 18 commits into
Expensify:mainfrom
mananjadhav:fix/single-emoji-size

Conversation

@mananjadhav

@mananjadhav mananjadhav commented Sep 2, 2021

Copy link
Copy Markdown
Collaborator

@deetergp I've updated my changes with the regex changes and a unit test to verify all the emojis in our dataset.

Details

  • Changed isSingleEmoji function
  • Replaced Emoji Regex

Fixed Issues

$ #4543

Tests

  1. Tested different variants of the Emojis with single length and surrogate pairs
  2. Tested emojis with skin tone.
  3. Tested with composite emojis such as Family
  4. Tested text-based Emojis

QA Steps

  1. Go to any Chat
  2. Enter one emoji per message.
  3. Size of the Emoji should be larger similar to other apps like Whatsapp, etc.
  4. It should work for all variations.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Screenshot 2021-09-08 at 5 47 53 PM

Mobile Web

Screenshot 2021-09-08 at 5 47 43 PM

Screenshot 2021-09-08 at 5 47 29 PM

Screenshot 2021-09-08 at 5 47 19 PM

Desktop

Screenshot 2021-09-08 at 6 00 29 PM

Screenshot 2021-09-08 at 6 00 20 PM

iOS

Screenshot 2021-09-08 at 5 55 51 PM

Screenshot 2021-09-08 at 5 55 37 PM

Android

Screenshot 2021-09-08 at 6 08 21 PM

Screenshot 2021-09-08 at 6 08 09 PM

Screenshot 2021-09-08 at 6 07 54 PM

Screenshot 2021-09-08 at 6 07 36 PM

@mananjadhav

Copy link
Copy Markdown
Collaborator Author

@deetergp I've added my changes and I am currently testing the coverage of the regex. The initial results look good with few exceptions.

image

image

@mananjadhav mananjadhav changed the title Fix single emoji size in chat Fix: Size of the single emoji in chat along with updated Emoji Regex Sep 8, 2021
@mananjadhav mananjadhav marked this pull request as ready for review September 8, 2021 12:32
@mananjadhav mananjadhav requested a review from a team as a code owner September 8, 2021 12:32
@MelvinBot MelvinBot requested review from marcaaron and removed request for a team September 8, 2021 12:32
@mananjadhav

Copy link
Copy Markdown
Collaborator Author

@deetergp PR updated. Please review.

Comment thread src/libs/Emoji/getEmojiUnicode.js Outdated
Comment thread src/CONST.js Outdated
Comment thread src/libs/Emoji/getEmojiUnicode.js Outdated
@mananjadhav

Copy link
Copy Markdown
Collaborator Author

@deetergp PR updated

deetergp
deetergp previously approved these changes Sep 9, 2021

@deetergp deetergp left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread src/libs/Emoji/getEmojiUnicode.js Outdated
* Get the unicode code of an emoji in base 16.
*
* @name emojiUnicode
* @function

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay noted.

Comment thread src/libs/Emoji/getEmojiUnicode.js Outdated
@@ -0,0 +1,38 @@
/* eslint radix: ["error", "as-needed"] */

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Collaborator Author

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.

Copy link
Copy Markdown
Contributor

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?

Comment thread src/libs/Emoji/getEmojiUnicode.js Outdated
}

if (input.length === 1) {
return input.charCodeAt(0).toString().split(' ').map(val => parseInt(val).toString(16))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use _.map()

Comment thread 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is a surrogate?

Copy link
Copy Markdown
Collaborator Author

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

https://thekevinscott.com/emojis-in-javascript/

Copy link
Copy Markdown
Contributor

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"?

Comment thread src/libs/Emoji/getEmojiUnicode.js Outdated
pairs.push(input.charCodeAt(i));
}
}
return pairs.map(val => parseInt(val).toString(16)).join(' ');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_.map()

Comment thread src/libs/ValidationUtils.js Outdated
import {showBankAccountFormValidationError, showBankAccountErrorModal} from './actions/BankAccounts';
import {translateLocal} from './translate';
import getEmojiUnicode from './Emoji/getEmojiUnicode';
import trimEmojiUnicode from './Emoji/trimEmojiUnicode';

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay noted

Comment thread src/libs/ValidationUtils.js Outdated
return message.length === matchedEmoji.length;
const matchedUnicode = getEmojiUnicode(matchedEmoji);
const currentMessageUnicode = trimEmojiUnicode(getEmojiUnicode(message));
return matchedUnicode === currentMessageUnicode;

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

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?

Copy link
Copy Markdown
Contributor

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!

Comment thread tests/unit/EmojiRegexTest.js
@mananjadhav

Copy link
Copy Markdown
Collaborator Author

@marcaaron PR updated.

deetergp
deetergp previously approved these changes Sep 10, 2021

@deetergp deetergp left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread src/libs/EmojiUtils.js Outdated
@@ -0,0 +1,76 @@
/* eslint radix: ["error", "as-needed"] */

Copy link
Copy Markdown
Contributor

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.

@mananjadhav mananjadhav Sep 11, 2021

Copy link
Copy Markdown
Collaborator Author

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.

@marcaaron marcaaron merged commit 04bf0ce into Expensify:main Sep 13, 2021
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.0.97-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@botify

botify commented Sep 15, 2021

Copy link
Copy Markdown

This has been deployed to production and is now subject to a 7-day regression period.
If no regressions arise, payment will be issued on 2021-09-22. 🎊

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by @francoisl in version: 1.0.98-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

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.

5 participants