-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: emojis sent from web not rendering #7594
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
Open
OtavioStasiak
wants to merge
17
commits into
develop
Choose a base branch
from
fix.emoji-not-rendering-as-expected
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11,503
β7,477
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a1977e5
fix: missing new emojis
OtavioStasiak fda8e8e
comment
OtavioStasiak 6c290a9
refactor: generate emoji data from emojibase (match web)
OtavioStasiak 0d03f39
Merge branch 'develop' into fix.emoji-not-rendering-as-expected
OtavioStasiak 7a25e1e
Merge branch 'develop' into fix.emoji-not-rendering-as-expected
OtavioStasiak 32e6169
refactor: pin emoji shortnames, drop the legacyShortnames.ts parser
OtavioStasiak 4cf37b3
efactor: import emoji tables directly and fold search into methods/emβ¦
OtavioStasiak aa98a0c
cleanup
OtavioStasiak 029e6e9
cleanup
OtavioStasiak 644142a
fix: make the composers : autocomplete alias-aware
OtavioStasiak 84315e1
ix: delete the whole emoji sequence on one backspace
OtavioStasiak 49c804c
Merge branch 'develop' into fix.emoji-not-rendering-as-expected
OtavioStasiak 7ccd50e
update docs
OtavioStasiak 4597ea4
update docs
OtavioStasiak dc148ad
update docs
OtavioStasiak cb134d4
Merge branch 'develop' into fix.emoji-not-rendering-as-expected
OtavioStasiak 2318869
fix: test
OtavioStasiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/containers/MessageComposer/helpers/lastGlyphLength.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { lastGlyphLength } from './lastGlyphLength'; | ||
|
|
||
| const at = (text: string) => lastGlyphLength(text, text.length); | ||
|
|
||
| describe('lastGlyphLength', () => { | ||
| it('counts a plain character as one code unit', () => { | ||
| expect(at('ab')).toBe(1); | ||
| }); | ||
|
|
||
| it('counts a surrogate pair as one glyph', () => { | ||
| expect(at('\u{1F6B2}')).toBe(2); | ||
| }); | ||
|
|
||
| it('counts a surrogate pair followed by a variation selector as one glyph', () => { | ||
| // What emojibase emits for :bike:, and what the old two-code-unit window missed. | ||
| expect(at('\u{1F6B2}οΈ')).toBe(3); | ||
| }); | ||
|
|
||
| it('counts a variation selector on a BMP base as one glyph', () => { | ||
| expect(at('β€οΈ')).toBe(2); | ||
| }); | ||
|
|
||
| it('counts a skin tone modifier as part of the glyph', () => { | ||
| expect(at('\u{1F44D}\u{1F3FD}')).toBe(4); | ||
| }); | ||
|
|
||
| it('counts a ZWJ sequence as one glyph', () => { | ||
| expect(at('\u{1F468}β\u{1F469}β\u{1F467}β\u{1F466}')).toBe(11); | ||
| }); | ||
|
|
||
| it('counts a ZWJ sequence ending in a variation selector as one glyph', () => { | ||
| expect(at('\u{1F93C}ββοΈ')).toBe(5); | ||
| }); | ||
|
|
||
| it('counts a keycap as one glyph', () => { | ||
| expect(at('1οΈβ£')).toBe(3); | ||
| }); | ||
|
|
||
| it('counts a flag as one glyph', () => { | ||
| expect(at('\u{1F1E7}\u{1F1F7}')).toBe(4); | ||
| }); | ||
|
|
||
| it('leaves text before the glyph alone', () => { | ||
| expect(lastGlyphLength('hi \u{1F6B2}οΈ there', 6)).toBe(3); | ||
| }); | ||
|
|
||
| it('returns zero at the start of the text', () => { | ||
| expect(lastGlyphLength('abc', 0)).toBe(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| const ZWJ = 0x200d; | ||
| const VARIATION_SELECTOR_16 = 0xfe0f; | ||
| const VARIATION_SELECTOR_15 = 0xfe0e; | ||
| const COMBINING_ENCLOSING_KEYCAP = 0x20e3; | ||
|
|
||
| const isSkinTone = (codePoint: number) => codePoint >= 0x1f3fb && codePoint <= 0x1f3ff; | ||
| const isRegionalIndicator = (codePoint: number) => codePoint >= 0x1f1e6 && codePoint <= 0x1f1ff; | ||
| const isAttachedToWhatPrecedesIt = (codePoint: number) => | ||
| codePoint === VARIATION_SELECTOR_16 || | ||
| codePoint === VARIATION_SELECTOR_15 || | ||
| codePoint === COMBINING_ENCLOSING_KEYCAP || | ||
| isSkinTone(codePoint); | ||
|
|
||
| const codePointBefore = (text: string, index: number) => { | ||
| const low = text.charCodeAt(index - 1); | ||
| if (low >= 0xdc00 && low <= 0xdfff && index >= 2) { | ||
| const high = text.charCodeAt(index - 2); | ||
| if (high >= 0xd800 && high <= 0xdbff) { | ||
| return { codePoint: text.codePointAt(index - 2) as number, size: 2 }; | ||
| } | ||
| } | ||
| return { codePoint: low, size: 1 }; | ||
| }; | ||
|
|
||
| // How many UTF-16 code units the character ending at `end` occupies, counting a whole emoji | ||
| // sequence as one. Backspace deletes that many, so a tap removes the glyph rather than an | ||
| // invisible modifier β emojibase emits fully-qualified sequences, so most emoji end in U+FE0F. | ||
| export const lastGlyphLength = (text: string, end: number): number => { | ||
| if (end <= 0) { | ||
| return 0; | ||
| } | ||
| let index = end; | ||
| let length = 0; | ||
| while (index > 0) { | ||
| const { codePoint, size } = codePointBefore(text, index); | ||
| index -= size; | ||
| length += size; | ||
|
|
||
| if (isAttachedToWhatPrecedesIt(codePoint)) { | ||
| continue; | ||
| } | ||
| if (index >= 1 && text.charCodeAt(index - 1) === ZWJ) { | ||
| index -= 1; | ||
| length += 1; | ||
| continue; | ||
| } | ||
| // Flags are a pair of regional indicators with nothing joining them. | ||
| if (isRegionalIndicator(codePoint) && index >= 2) { | ||
| const previous = codePointBefore(text, index); | ||
| if (isRegionalIndicator(previous.codePoint)) { | ||
| length += previous.size; | ||
| } | ||
|
OtavioStasiak marked this conversation as resolved.
|
||
| } | ||
| break; | ||
| } | ||
| return length; | ||
| }; | ||
33 changes: 33 additions & 0 deletions
33
app/containers/MessageComposer/hooks/useAutocomplete.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { renderHook, waitFor } from '@testing-library/react-native'; | ||
|
|
||
| import { useAutocomplete } from './useAutocomplete'; | ||
| import { type IAutocompleteEmoji } from '../interfaces'; | ||
|
|
||
| jest.mock('../../../lib/database', () => ({ | ||
| __esModule: true, | ||
| default: { active: { get: jest.fn(() => ({ query: jest.fn(() => ({ fetch: jest.fn().mockResolvedValue([]) })) })) } } | ||
| })); | ||
| jest.mock('../../../lib/methods/search', () => ({ searchLocal: jest.fn(), searchRemote: jest.fn() })); | ||
| jest.mock('../../../lib/services/restApi', () => ({ getCommandPreview: jest.fn(), getListCannedResponse: jest.fn() })); | ||
| jest.mock('../../../lib/hooks/usePermissions', () => ({ usePermissions: () => [false, false] })); | ||
| jest.mock('../../../lib/methods/helpers/log', () => ({ __esModule: true, default: jest.fn() })); | ||
|
|
||
| const names = async (text: string) => { | ||
| const { result } = renderHook(() => useAutocomplete({ text, type: ':', rid: 'rid', accessibilityFocusOnInput: () => null })); | ||
| await waitFor(() => expect(result.current.some(item => item.type === ':')).toBe(true)); | ||
| return (result.current as IAutocompleteEmoji[]).map(item => item.emoji); | ||
| }; | ||
|
|
||
| describe('useAutocomplete emoji suggestions', () => { | ||
| it('suggests an emoji by its listed shortname', async () => { | ||
| expect(await names('ocean')).toContain('ocean'); | ||
| }); | ||
|
|
||
| it('suggests an emoji typed by an alias, returning the listed shortname', async () => { | ||
| expect(await names('water_wave')).toContain('ocean'); | ||
| }); | ||
|
|
||
| it('matches case insensitively, like the emoji picker search', async () => { | ||
| expect(await names('Ocean')).toContain('ocean'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { aliasesByEmojiName, emojisByCategory, shortnameToUnicodeMap } from './data'; | ||
| import { emojis } from './emojis'; | ||
| import { legacyShortnameToUnicodeMap } from './legacyShortnamesMap'; | ||
| import pinnedShortnames from '../../../../scripts/pinned-shortnames'; | ||
|
|
||
| const bare = (unicode: string) => unicode.replace(/\uFE0F/g, ''); | ||
| const resolve = (name: string) => shortnameToUnicodeMap[`:${name}:`] ?? legacyShortnameToUnicodeMap[`:${name}:`]; | ||
|
|
||
| // The only seven glyphs that changed against the pre-emojibase map, all repairs of a missing joiner. | ||
| const JOINER_REPAIRS: [string, string][] = [ | ||
| [':kiss_mm:', 'π¨\u200Dβ€\uFE0F\u200Dπ\u200Dπ¨'], | ||
| [':couplekiss_mm:', 'π¨\u200Dβ€\uFE0F\u200Dπ\u200Dπ¨'], | ||
| [':kiss_ww:', 'π©\u200Dβ€\uFE0F\u200Dπ\u200Dπ©'], | ||
| [':couplekiss_ww:', 'π©\u200Dβ€\uFE0F\u200Dπ\u200Dπ©'], | ||
| [':kiss_woman_man:', 'π©\u200Dβ€\uFE0F\u200Dπ\u200Dπ¨'], | ||
| [':men_wrestling:', 'π€Ό\u200Dβ\uFE0F'], | ||
| [':women_wrestling:', 'π€Ό\u200Dβ\uFE0F'] | ||
| ]; | ||
|
|
||
| // The pins, spelled out so editing scripts/pinned-shortnames.js fails here and not only in the picker. | ||
| const PINNED_GLYPHS: [string, string][] = [ | ||
| [':beetle:', 'π'], | ||
| [':man_in_tuxedo:', 'π€΅'], | ||
| [':man_in_tuxedo_tone1:', 'π€΅π»'], | ||
| [':man_in_tuxedo_tone2:', 'π€΅πΌ'], | ||
| [':man_in_tuxedo_tone3:', 'π€΅π½'], | ||
| [':man_in_tuxedo_tone4:', 'π€΅πΎ'], | ||
| [':man_in_tuxedo_tone5:', 'π€΅πΏ'] | ||
| ]; | ||
|
|
||
| const UNLISTED_COMPONENTS = [ | ||
| ...Array.from({ length: 26 }, (_, i) => `regional_indicator_${String.fromCharCode(97 + i)}`), | ||
| 'digit_zero', | ||
| 'digit_one', | ||
| 'digit_two', | ||
| 'digit_three', | ||
| 'digit_four', | ||
| 'digit_five', | ||
| 'digit_six', | ||
| 'digit_seven', | ||
| 'digit_eight', | ||
| 'digit_nine', | ||
| 'asterisk_symbol', | ||
| 'pound_symbol' | ||
| ]; | ||
|
|
||
| describe('emoji data', () => { | ||
| it('resolves every listed emoji to a unicode character', () => { | ||
| const unresolved = emojis.filter(name => !shortnameToUnicodeMap[`:${name}:`]); | ||
| expect(unresolved).toEqual([]); | ||
| }); | ||
|
|
||
| it('lists every emoji exactly once', () => { | ||
| expect(emojis.length).toBe(new Set(emojis).size); | ||
| }); | ||
|
|
||
| it('keys aliases by a listed emoji name', () => { | ||
| const listed = new Set(emojis); | ||
| expect(Object.keys(aliasesByEmojiName).filter(name => !listed.has(name))).toEqual([]); | ||
| }); | ||
|
|
||
| it('resolves every alias to the same emoji as the name it belongs to', () => { | ||
|
OtavioStasiak marked this conversation as resolved.
|
||
| const mismatched = Object.keys(aliasesByEmojiName).filter(name => { | ||
| const expected = bare(shortnameToUnicodeMap[`:${name}:`]); | ||
| return aliasesByEmojiName[name].some(alias => bare(resolve(alias) ?? '') !== expected); | ||
| }); | ||
| expect(mismatched).toEqual([]); | ||
| }); | ||
|
OtavioStasiak marked this conversation as resolved.
|
||
|
|
||
| it('has no category with an empty emoji list', () => { | ||
| expect( | ||
| Object.keys(emojisByCategory).filter(key => emojisByCategory[key as keyof typeof emojisByCategory].length === 0) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('holds every pinned shortname at its pinned glyph', () => { | ||
| expect(Object.entries(pinnedShortnames)).toEqual(PINNED_GLYPHS); | ||
| const drifted = Object.keys(pinnedShortnames).filter( | ||
| shortname => shortnameToUnicodeMap[shortname] !== pinnedShortnames[shortname as keyof typeof pinnedShortnames] | ||
| ); | ||
| expect(drifted).toEqual([]); | ||
| }); | ||
|
|
||
| it('holds every repaired joiner glyph at the value this branch decided on', () => { | ||
| const drifted = JOINER_REPAIRS.filter(([shortname, unicode]) => shortnameToUnicodeMap[shortname] !== unicode); | ||
| expect(drifted).toEqual([]); | ||
| }); | ||
|
|
||
| it('never puts a variation selector before a skin tone modifier', () => { | ||
| const illFormed = [shortnameToUnicodeMap, legacyShortnameToUnicodeMap].flatMap(map => | ||
| Object.keys(map).filter(key => /\uFE0F[\u{1F3FB}-\u{1F3FF}]/u.test(map[key])) | ||
| ); | ||
| expect(illFormed).toEqual([]); | ||
| }); | ||
|
|
||
| it('resolves every unlisted component without listing it', () => { | ||
| expect(UNLISTED_COMPONENTS.filter(name => !resolve(name))).toEqual([]); | ||
| const listed = new Set(emojis); | ||
| expect(UNLISTED_COMPONENTS.filter(name => listed.has(name))).toEqual([]); | ||
| }); | ||
|
|
||
| it('keeps legacy shortnames out of the current map', () => { | ||
| expect(Object.keys(legacyShortnameToUnicodeMap).filter(key => key in shortnameToUnicodeMap)).toEqual([]); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.