Add get_animated_emoji_stickers.

This commit is contained in:
levlam 2021-09-17 16:58:20 +03:00
parent 055e02f9c0
commit 6d21161f70
2 changed files with 30 additions and 22 deletions

View File

@ -4058,6 +4058,18 @@ int StickersManager::get_emoji_number(Slice emoji) {
return emoji[0] - '0'; return emoji[0] - '0';
} }
vector<FileId> StickersManager::get_animated_emoji_stickers(const StickerSet *sticker_set, const string &emoji) const {
vector<FileId> result;
for (auto sticker_id : sticker_set->sticker_ids) {
auto s = get_sticker(sticker_id);
CHECK(s != nullptr);
if (remove_emoji_modifiers(s->alt) == emoji) {
result.push_back(sticker_id);
}
}
return result;
}
void StickersManager::choose_animated_emoji_click_sticker(const StickerSet *sticker_set, string message_text, void StickersManager::choose_animated_emoji_click_sticker(const StickerSet *sticker_set, string message_text,
FullMessageId full_message_id, double start_time, FullMessageId full_message_id, double start_time,
Promise<td_api::object_ptr<td_api::sticker>> &&promise) { Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
@ -4067,18 +4079,15 @@ void StickersManager::choose_animated_emoji_click_sticker(const StickerSet *stic
return promise.set_error(Status::Error(400, "Message is not an animated emoji message")); return promise.set_error(Status::Error(400, "Message is not an animated emoji message"));
} }
auto all_sticker_ids = get_animated_emoji_stickers(sticker_set, message_text);
vector<std::pair<int, FileId>> found_stickers; vector<std::pair<int, FileId>> found_stickers;
for (auto sticker_id : sticker_set->sticker_ids) { for (auto sticker_id : all_sticker_ids) {
auto s = get_sticker(sticker_id); auto it = sticker_set->sticker_emojis_map_.find(sticker_id);
CHECK(s != nullptr); if (it != sticker_set->sticker_emojis_map_.end()) {
if (remove_emoji_modifiers(s->alt) == message_text) { for (auto &emoji : it->second) {
auto it = sticker_set->sticker_emojis_map_.find(sticker_id); auto number = get_emoji_number(emoji);
if (it != sticker_set->sticker_emojis_map_.end()) { if (number > 0) {
for (auto &emoji : it->second) { found_stickers.emplace_back(number, sticker_id);
auto number = get_emoji_number(emoji);
if (number > 0) {
found_stickers.emplace_back(number, sticker_id);
}
} }
} }
} }
@ -4225,18 +4234,15 @@ void StickersManager::send_update_animated_emoji_clicked(const StickerSet *stick
return; return;
} }
auto all_sticker_ids = get_animated_emoji_stickers(sticker_set, emoji);
std::unordered_map<int, FileId> sticker_ids; std::unordered_map<int, FileId> sticker_ids;
for (auto sticker_id : sticker_set->sticker_ids) { for (auto sticker_id : all_sticker_ids) {
auto s = get_sticker(sticker_id); auto it = sticker_set->sticker_emojis_map_.find(sticker_id);
CHECK(s != nullptr); if (it != sticker_set->sticker_emojis_map_.end()) {
if (remove_emoji_modifiers(s->alt) == emoji) { for (auto &sticker_emoji : it->second) {
auto it = sticker_set->sticker_emojis_map_.find(sticker_id); auto number = get_emoji_number(sticker_emoji);
if (it != sticker_set->sticker_emojis_map_.end()) { if (number > 0) {
for (auto &sticker_emoji : it->second) { sticker_ids[number] = sticker_id;
auto number = get_emoji_number(sticker_emoji);
if (number > 0) {
sticker_ids[number] = sticker_id;
}
} }
} }
} }

View File

@ -592,6 +592,8 @@ class StickersManager final : public Actor {
static int get_emoji_number(Slice emoji); static int get_emoji_number(Slice emoji);
vector<FileId> get_animated_emoji_stickers(const StickerSet *sticker_set, const string &emoji) const;
void choose_animated_emoji_click_sticker(const StickerSet *sticker_set, string message_text, void choose_animated_emoji_click_sticker(const StickerSet *sticker_set, string message_text,
FullMessageId full_message_id, double start_time, FullMessageId full_message_id, double start_time,
Promise<td_api::object_ptr<td_api::sticker>> &&promise); Promise<td_api::object_ptr<td_api::sticker>> &&promise);