Use checks to catch wrong custom_emoji_to_sticker_id_ cache.

This commit is contained in:
levlam 2022-09-05 20:26:10 +03:00
parent 41a5e84d1c
commit 8d6a83433f

View File

@ -1737,13 +1737,11 @@ StickerType StickersManager::get_sticker_type(FileId file_id) const {
bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const { bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const {
auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id); auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
const Sticker *s = get_sticker(sticker_id); if (!sticker_id.is_valid()) {
if (s == nullptr) {
if (sticker_id.is_valid()) {
LOG(ERROR) << "Failed to find custom emoji sticker " << sticker_id;
}
return default_result; return default_result;
} }
const Sticker *s = get_sticker(sticker_id);
CHECK(s != nullptr);
return s->is_premium_; return s->is_premium_;
} }
@ -5557,13 +5555,17 @@ td_api::object_ptr<td_api::stickers> StickersManager::get_custom_emoji_stickers_
vector<int64> reload_document_ids; vector<int64> reload_document_ids;
for (auto document_id : document_ids) { for (auto document_id : document_ids) {
auto file_id = custom_emoji_to_sticker_id_.get(document_id); auto file_id = custom_emoji_to_sticker_id_.get(document_id);
auto sticker = get_sticker_object(file_id); if (file_id.is_valid()) {
if (sticker != nullptr && sticker->type_->get_id() == td_api::stickerTypeCustomEmoji::ID) {
auto s = get_sticker(file_id); auto s = get_sticker(file_id);
CHECK(s != nullptr);
CHECK(s->type_ == StickerType::CustomEmoji);
if (s->emoji_receive_date_ < update_before_date && !s->is_being_reloaded_) { if (s->emoji_receive_date_ < update_before_date && !s->is_being_reloaded_) {
s->is_being_reloaded_ = true; s->is_being_reloaded_ = true;
reload_document_ids.push_back(document_id); reload_document_ids.push_back(document_id);
} }
auto sticker = get_sticker_object(file_id);
CHECK(sticker != nullptr);
stickers.push_back(std::move(sticker)); stickers.push_back(std::move(sticker));
} }
} }
@ -6813,10 +6815,11 @@ void StickersManager::move_sticker_set_to_top_by_custom_emoji_ids(const vector<i
return; return;
} }
const auto *s = get_sticker(sticker_id); const auto *s = get_sticker(sticker_id);
if (s == nullptr || !s->set_id_.is_valid()) { CHECK(s != nullptr);
CHECK(s->type_ == StickerType::CustomEmoji);
if (!s->set_id_.is_valid()) {
return; return;
} }
CHECK(s->type_ == StickerType::CustomEmoji);
if (s->set_id_ != sticker_set_id) { if (s->set_id_ != sticker_set_id) {
if (sticker_set_id.is_valid()) { if (sticker_set_id.is_valid()) {
return; return;