diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index 562a27fba..eb4027be4 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -250,6 +250,11 @@ bool operator<(const ReactionManager::SavedReactionTag &lhs, const ReactionManag return std::tie(lhs.count_, lhs.title_, lhs.reaction_type_) < std::tie(rhs.count_, rhs.title_, rhs.reaction_type_); } +StringBuilder &operator<<(StringBuilder &string_builder, const ReactionManager::SavedReactionTag &saved_reaction_tag) { + return string_builder << "SavedMessagesTag{" << saved_reaction_tag.reaction_type_ << '(' << saved_reaction_tag.title_ + << ") X " << saved_reaction_tag.count_ << '}'; +} + td_api::object_ptr ReactionManager::SavedReactionTags::get_saved_messages_tags_object() const { return td_api::make_object( @@ -265,6 +270,7 @@ void ReactionManager::SavedReactionTags::update_saved_messages_tags(const vector is_changed = false; for (const auto &old_tag : old_tags) { if (!td::contains(new_tags, old_tag)) { + CHECK(!old_tag.is_empty()); for (auto it = tags_.begin(); it != tags_.end(); ++it) { auto &tag = *it; if (tag.reaction_type_ == old_tag) { @@ -280,6 +286,7 @@ void ReactionManager::SavedReactionTags::update_saved_messages_tags(const vector } for (const auto &new_tag : new_tags) { if (!td::contains(old_tags, new_tag)) { + CHECK(!new_tag.is_empty()); is_changed = true; bool is_found = false; for (auto &tag : tags_) { @@ -841,6 +848,10 @@ void ReactionManager::on_get_saved_messages_tags( vector saved_reaction_tags; for (auto &tag : tags->tags_) { saved_reaction_tags.emplace_back(std::move(tag)); + if (!saved_reaction_tags.back().is_valid()) { + LOG(ERROR) << "Receive " << saved_reaction_tags.back(); + saved_reaction_tags.pop_back(); + } } std::sort(saved_reaction_tags.begin(), saved_reaction_tags.end()); tags_.hash_ = tags->hash_; diff --git a/td/telegram/ReactionManager.h b/td/telegram/ReactionManager.h index 8650b5a11..fbc9016e1 100644 --- a/td/telegram/ReactionManager.h +++ b/td/telegram/ReactionManager.h @@ -17,6 +17,7 @@ #include "td/utils/common.h" #include "td/utils/Promise.h" +#include "td/utils/StringBuilder.h" #include @@ -136,6 +137,10 @@ class ReactionManager final : public Actor { SavedReactionTag() = default; + bool is_valid() const { + return !reaction_type_.is_empty() && count_ > 0; + } + explicit SavedReactionTag(telegram_api::object_ptr &&tag); td_api::object_ptr get_saved_messages_tag_object() const; @@ -147,6 +152,8 @@ class ReactionManager final : public Actor { friend bool operator<(const SavedReactionTag &lhs, const SavedReactionTag &rhs); + friend StringBuilder &operator<<(StringBuilder &string_builder, const SavedReactionTag &saved_reaction_tag); + struct SavedReactionTags { vector tags_; int64 hash_ = 0;