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

[NO QA] Support new frequentlyUsedEmoji format #43734

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type EmojiPickerListItem = EmojiSpacer | Emoji | HeaderEmoji;
type EmojiPickerList = EmojiPickerListItem[];
type ReplacedEmoji = {text: string; emojis: Emoji[]; cursorPosition?: number};

const findEmojiByName = (name: string): Emoji => Emojis.emojiNameTable[name];

const findEmojiByCode = (code: string): Emoji => Emojis.emojiCodeTableWithSkinTones[code];

let frequentlyUsedEmojis: FrequentlyUsedEmoji[] = [];
Onyx.connect({
key: ONYXKEYS.FREQUENTLY_USED_EMOJIS,
Expand All @@ -29,17 +33,20 @@ Onyx.connect({
frequentlyUsedEmojis =
val
?.map((item) => {
const emoji = Emojis.emojiCodeTableWithSkinTones[item.code];
return {...emoji, count: item.count, lastUpdatedAt: item.lastUpdatedAt};
let emoji = item;
if (!item.code) {
emoji = {...emoji, ...findEmojiByName(item.name)};
}
if (!item.name) {
emoji = {...emoji, ...findEmojiByCode(item.code)};
}
const emojiWithSkinTones = Emojis.emojiCodeTableWithSkinTones[emoji.code];
return {...emojiWithSkinTones, count: item.count, lastUpdatedAt: item.lastUpdatedAt};
Copy link
Contributor

@suneox suneox Jul 31, 2024

Choose a reason for hiding this comment

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

emojiWithSkinTones can be undefined, but this change always returns an object, so the filter below doesn't work and introduced this bug

})
.filter((emoji): emoji is FrequentlyUsedEmoji => !!emoji) ?? [];
},
});

const findEmojiByName = (name: string): Emoji => Emojis.emojiNameTable[name];

const findEmojiByCode = (code: string): Emoji => Emojis.emojiCodeTableWithSkinTones[code];

const getEmojiName = (emoji: Emoji, lang: Locale = CONST.LOCALES.DEFAULT): string => {
if (!emoji) {
return '';
Expand Down Expand Up @@ -210,7 +217,20 @@ function mergeEmojisWithFrequentlyUsedEmojis(emojis: PickerEmojis): EmojiPickerL
return addSpacesToEmojiCategories(emojis);
}

const mergedEmojis = [Emojis.categoryFrequentlyUsed, ...frequentlyUsedEmojis, ...emojis];
const formattedFrequentlyUsedEmojis = frequentlyUsedEmojis.map((frequentlyUsedEmoji: Emoji): Emoji => {
// Frequently used emojis in the old format will have name/types/code stored with them
// The back-end may not always have both, so we'll need to fill them in.
if (!('code' in (frequentlyUsedEmoji as FrequentlyUsedEmoji))) {
return findEmojiByName(frequentlyUsedEmoji.name);
}
if (!('name' in (frequentlyUsedEmoji as FrequentlyUsedEmoji))) {
return findEmojiByCode(frequentlyUsedEmoji.code);
}

return frequentlyUsedEmoji;
});

const mergedEmojis = [Emojis.categoryFrequentlyUsed, ...formattedFrequentlyUsedEmojis, ...emojis];
return addSpacesToEmojiCategories(mergedEmojis);
}

Expand Down
Loading