From 6450f5a531ad118ce57473545e54a1e35a505dfd Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 7 Aug 2024 16:48:06 +0300 Subject: [PATCH] Add and use MessageReactions::are_empty(). --- td/telegram/MessageReaction.cpp | 4 ++++ td/telegram/MessageReaction.h | 2 ++ td/telegram/MessagesManager.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index a762f6314..7ef3347eb 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -509,6 +509,10 @@ StringBuilder &operator<<(StringBuilder &string_builder, const UnreadMessageReac << unread_reaction.sender_dialog_id_ << ']'; } +bool MessageReactions::are_empty() const { + return reactions_.empty() && pending_paid_reactions_ == 0; +} + unique_ptr MessageReactions::get_message_reactions( Td *td, telegram_api::object_ptr &&reactions, bool is_bot) { if (reactions == nullptr || is_bot) { diff --git a/td/telegram/MessageReaction.h b/td/telegram/MessageReaction.h index 91434dfc4..2d61fcbec 100644 --- a/td/telegram/MessageReaction.h +++ b/td/telegram/MessageReaction.h @@ -165,6 +165,8 @@ struct MessageReactions { MessageReactions() = default; + bool are_empty() const; + static unique_ptr get_message_reactions( Td *td, telegram_api::object_ptr &&reactions, bool is_bot); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 9c139b3d1..5c511ce6e 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6567,7 +6567,7 @@ td_api::object_ptr MessagesManager::get_message_ DialogId dialog_id, const Message *m) const { bool is_visible_reply_info = is_visible_message_reply_info(dialog_id, m); bool has_reactions = - m->reactions != nullptr && !m->reactions->reactions_.empty() && is_visible_message_reactions(dialog_id, m); + m->reactions != nullptr && !m->reactions->are_empty() && is_visible_message_reactions(dialog_id, m); if (m->view_count == 0 && m->forward_count == 0 && !is_visible_reply_info && !has_reactions) { return nullptr; } @@ -7744,8 +7744,8 @@ void MessagesManager::hide_dialog_message_reactions(Dialog *d) { CHECK(!td_->auth_manager_->is_bot()); auto dialog_type = d->dialog_id.get_type(); CHECK(dialog_type == DialogType::Chat || dialog_type == DialogType::Channel); - auto message_ids = find_dialog_messages( - d, [](const Message *m) { return m->reactions != nullptr && !m->reactions->reactions_.empty(); }); + auto message_ids = + find_dialog_messages(d, [](const Message *m) { return m->reactions != nullptr && !m->reactions->are_empty(); }); for (auto message_id : message_ids) { Message *m = get_message(d, message_id); CHECK(m != nullptr); @@ -22588,7 +22588,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id bool MessagesManager::can_add_message_tag(DialogId dialog_id, const MessageReactions *reactions) const { return dialog_id == td_->dialog_manager_->get_my_dialog_id() && - (reactions == nullptr || reactions->reactions_.empty() || reactions->are_tags_); + (reactions == nullptr || reactions->are_empty() || reactions->are_tags_); } Result> MessagesManager::get_message_available_reactions(