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: Size of the single emoji in chat along with updated Emoji Regex #5039

Merged
merged 18 commits into from
Sep 13, 2021

Conversation

mananjadhav
Copy link
Collaborator

@mananjadhav mananjadhav commented Sep 2, 2021

@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
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
Collaborator Author

@deetergp PR updated. Please review.

src/libs/Emoji/getEmojiUnicode.js Outdated Show resolved Hide resolved
src/CONST.js Outdated Show resolved Hide resolved
src/libs/Emoji/getEmojiUnicode.js Outdated Show resolved Hide resolved
@mananjadhav
Copy link
Collaborator Author

@deetergp PR updated

deetergp
deetergp previously approved these changes Sep 9, 2021
Copy link
Contributor

@deetergp deetergp left a 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!

* Get the unicode code of an emoji in base 16.
*
* @name emojiUnicode
* @function
Copy link
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
Collaborator Author

Choose a reason for hiding this comment

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

Okay noted.

@@ -0,0 +1,38 @@
/* eslint radix: ["error", "as-needed"] */
Copy link
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
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
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?

}

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

Choose a reason for hiding this comment

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

Please use _.map()

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

pairs.push(input.charCodeAt(i));
}
}
return pairs.map(val => parseInt(val).toString(16)).join(' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

_.map()

@@ -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';
Copy link
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
Collaborator Author

Choose a reason for hiding this comment

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

Okay noted

return message.length === matchedEmoji.length;
const matchedUnicode = getEmojiUnicode(matchedEmoji);
const currentMessageUnicode = trimEmojiUnicode(getEmojiUnicode(message));
return matchedUnicode === currentMessageUnicode;
Copy link
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
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
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!

tests/unit/EmojiRegexTest.js Show resolved Hide resolved
@mananjadhav
Copy link
Collaborator Author

@marcaaron PR updated.

deetergp
deetergp previously approved these changes Sep 10, 2021
Copy link
Contributor

@deetergp deetergp left a 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!

@@ -0,0 +1,76 @@
/* eslint radix: ["error", "as-needed"] */
Copy link
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.

Copy link
Collaborator Author

@mananjadhav mananjadhav Sep 11, 2021

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
Contributor

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

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

@botify
Copy link

botify commented Sep 15, 2021

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