Match animated emoji without selectors.
This commit is contained in:
parent
d6df315769
commit
eff87996a5
@ -2004,23 +2004,28 @@ std::pair<FileId, int> StickersManager::get_animated_emoji_sticker(const Sticker
|
||||
return {};
|
||||
}
|
||||
|
||||
auto emoji_without_selectors = remove_emoji_selectors(emoji);
|
||||
// trying to find full emoji match
|
||||
for (const auto &sticker_id : it->second) {
|
||||
auto emoji_it = sticker_set->sticker_emojis_map_.find(sticker_id);
|
||||
CHECK(emoji_it != sticker_set->sticker_emojis_map_.end());
|
||||
if (td::contains(emoji_it->second, emoji)) {
|
||||
return {sticker_id, 0};
|
||||
for (auto &sticker_emoji : emoji_it->second) {
|
||||
if (remove_emoji_selectors(sticker_emoji) == emoji_without_selectors) {
|
||||
return {sticker_id, 0};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// trying to find match without Fitzpatrick modifiers
|
||||
int modifier_id = get_fitzpatrick_modifier(emoji);
|
||||
int modifier_id = get_fitzpatrick_modifier(emoji_without_selectors);
|
||||
if (modifier_id > 0) {
|
||||
for (const auto &sticker_id : it->second) {
|
||||
auto emoji_it = sticker_set->sticker_emojis_map_.find(sticker_id);
|
||||
CHECK(emoji_it != sticker_set->sticker_emojis_map_.end());
|
||||
if (td::contains(emoji_it->second, Slice(emoji).remove_suffix(4))) {
|
||||
return {sticker_id, modifier_id};
|
||||
for (auto &sticker_emoji : emoji_it->second) {
|
||||
if (remove_emoji_selectors(sticker_emoji) == Slice(emoji_without_selectors).remove_suffix(4)) {
|
||||
return {sticker_id, modifier_id};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -688,8 +688,7 @@ Slice remove_fitzpatrick_modifier(Slice emoji) {
|
||||
}
|
||||
|
||||
Slice remove_emoji_modifiers(Slice emoji) {
|
||||
static const Slice modifiers[] = {u8"\uFE0E" /* variation selector-15 */,
|
||||
u8"\uFE0F" /* variation selector-16 */,
|
||||
static const Slice modifiers[] = {u8"\uFE0F" /* variation selector-16 */,
|
||||
u8"\u200D\u2640" /* zero width joiner + female sign */,
|
||||
u8"\u200D\u2642" /* zero width joiner + male sign */,
|
||||
u8"\U0001F3FB" /* emoji modifier fitzpatrick type-1-2 */,
|
||||
@ -714,4 +713,21 @@ void remove_emoji_modifiers_in_place(string &emoji) {
|
||||
emoji.resize(remove_emoji_modifiers(emoji).size());
|
||||
}
|
||||
|
||||
string remove_emoji_selectors(Slice emoji) {
|
||||
if (!is_emoji(emoji)) {
|
||||
return emoji.str();
|
||||
}
|
||||
string str;
|
||||
for (size_t i = 0; i < emoji.size(); i++) {
|
||||
if (i + 3 <= emoji.size() && emoji[i] == '\xEF' && emoji[i + 1] == '\xB8' && emoji[i + 2] == '\x8F') {
|
||||
// skip \uFE0F
|
||||
i += 2;
|
||||
} else {
|
||||
str += emoji[i];
|
||||
}
|
||||
}
|
||||
CHECK(is_emoji(str));
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -26,4 +26,7 @@ Slice remove_emoji_modifiers(Slice emoji);
|
||||
// removes all emoji modifiers from the end of the string in place
|
||||
void remove_emoji_modifiers_in_place(string &emoji);
|
||||
|
||||
// removes all emoji selectors from the string if it is an emoji
|
||||
string remove_emoji_selectors(Slice emoji);
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user