Do not store sticker <-> emoji correspondence for bots.

GitOrigin-RevId: a631b0a288629c317402338d54bc8f3a7b027a09
This commit is contained in:
levlam 2019-12-30 06:35:53 +03:00
parent d327618102
commit c3e7958020

View File

@ -1611,6 +1611,7 @@ void StickersManager::on_get_messages_sticker_set(int64 sticker_set_id,
std::unordered_map<int64, FileId> document_id_to_sticker_id; std::unordered_map<int64, FileId> document_id_to_sticker_id;
s->sticker_ids.clear(); s->sticker_ids.clear();
bool is_bot = td_->auth_manager_->is_bot();
for (auto &document_ptr : documents) { for (auto &document_ptr : documents) {
auto sticker_id = on_get_sticker_document(std::move(document_ptr), false); auto sticker_id = on_get_sticker_document(std::move(document_ptr), false);
if (!sticker_id.second.is_valid()) { if (!sticker_id.second.is_valid()) {
@ -1618,32 +1619,36 @@ void StickersManager::on_get_messages_sticker_set(int64 sticker_set_id,
} }
s->sticker_ids.push_back(sticker_id.second); s->sticker_ids.push_back(sticker_id.second);
document_id_to_sticker_id.insert(sticker_id); if (!is_bot) {
document_id_to_sticker_id.insert(sticker_id);
}
} }
if (static_cast<int>(s->sticker_ids.size()) != s->sticker_count) { if (static_cast<int>(s->sticker_ids.size()) != s->sticker_count) {
LOG(ERROR) << "Wrong sticker set size specified"; LOG(ERROR) << "Wrong sticker set size specified";
s->sticker_count = static_cast<int>(s->sticker_ids.size()); s->sticker_count = static_cast<int>(s->sticker_ids.size());
} }
s->emoji_stickers_map_.clear(); if (!is_bot) {
s->sticker_emojis_map_.clear(); s->emoji_stickers_map_.clear();
for (auto &pack : packs) { s->sticker_emojis_map_.clear();
vector<FileId> stickers; for (auto &pack : packs) {
stickers.reserve(pack->documents_.size()); vector<FileId> stickers;
for (int64 document_id : pack->documents_) { stickers.reserve(pack->documents_.size());
auto it = document_id_to_sticker_id.find(document_id); for (int64 document_id : pack->documents_) {
if (it == document_id_to_sticker_id.end()) { auto it = document_id_to_sticker_id.find(document_id);
LOG(ERROR) << "Can't find document with id " << document_id; if (it == document_id_to_sticker_id.end()) {
continue; LOG(ERROR) << "Can't find document with id " << document_id;
} continue;
}
stickers.push_back(it->second); stickers.push_back(it->second);
s->sticker_emojis_map_[it->second].push_back(pack->emoticon_); s->sticker_emojis_map_[it->second].push_back(pack->emoticon_);
} }
auto &sticker_ids = s->emoji_stickers_map_[remove_emoji_modifiers(pack->emoticon_)]; auto &sticker_ids = s->emoji_stickers_map_[remove_emoji_modifiers(pack->emoticon_)];
for (auto sticker_id : stickers) { for (auto sticker_id : stickers) {
if (std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id) == sticker_ids.end()) { if (std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id) == sticker_ids.end()) {
sticker_ids.push_back(sticker_id); sticker_ids.push_back(sticker_id);
}
} }
} }
} }