From b9afcbb70c1125c3c0b715ae5550853d2b453b60 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 22 Jan 2024 20:03:05 +0300 Subject: [PATCH] Support reaction tags in getMessageAvailableReactions. --- td/telegram/MessagesManager.cpp | 12 +++++++++++- td/telegram/MessagesManager.h | 2 ++ td/telegram/ReactionManager.cpp | 6 ++++++ td/telegram/ReactionManager.h | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 50cec02a6..7bea70292 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -22622,6 +22622,11 @@ Result> MessagesManager::get_mess get_message_active_reactions(d, m), row_size); } +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_); +} + ChatReactions MessagesManager::get_message_available_reactions(const Dialog *d, const Message *m, bool disallow_custom_for_non_premium) { CHECK(d != nullptr); @@ -22656,7 +22661,12 @@ ChatReactions MessagesManager::get_message_available_reactions(const Dialog *d, } if (active_reactions.allow_all_regular_) { - active_reactions.reaction_types_ = active_reaction_types_; + if (can_add_message_tag(d->dialog_id, m->reactions.get())) { + active_reactions.reaction_types_ = td_->reaction_manager_->get_default_tag_reactions(); + disallow_custom_for_non_premium = true; + } else { + active_reactions.reaction_types_ = active_reaction_types_; + } active_reactions.allow_all_regular_ = false; } if (can_use_reactions && m->reactions != nullptr) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 17cd6ae43..f0133a9fe 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2520,6 +2520,8 @@ class MessagesManager final : public Actor { void set_dialog_message_ttl(Dialog *d, MessageTtl message_ttl); + bool can_add_message_tag(DialogId dialog_id, const MessageReactions *reactions) const; + ChatReactions get_message_available_reactions(const Dialog *d, const Message *m, bool disallow_custom_for_non_premium); diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index dc806ab32..dd700828f 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -359,6 +359,12 @@ void ReactionManager::clear_recent_reactions(Promise &&promise) { td_->create_handler(std::move(promise))->send(); } +vector ReactionManager::get_default_tag_reactions() { + load_reaction_list(ReactionListType::DefaultTag); + + return get_reaction_list(ReactionListType::DefaultTag).reaction_types_; +} + void ReactionManager::reload_reactions() { if (G()->close_flag() || reactions_.are_being_reloaded_) { return; diff --git a/td/telegram/ReactionManager.h b/td/telegram/ReactionManager.h index f30ac7182..91b6d337a 100644 --- a/td/telegram/ReactionManager.h +++ b/td/telegram/ReactionManager.h @@ -51,6 +51,8 @@ class ReactionManager final : public Actor { void clear_recent_reactions(Promise &&promise); + vector get_default_tag_reactions(); + void reload_reactions(); void reload_reaction_list(ReactionListType reaction_list_type);