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