From 32eba3c7d1d8560e49f52158009be0f4b8f078bf Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 1 Feb 2024 22:40:55 +0300 Subject: [PATCH] Enable setting tags by Premium users. --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/MessagesManager.cpp | 18 +++++++++++++----- td/telegram/ReactionManager.cpp | 19 ++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7113e01c6..89571cfeb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1247,7 +1247,7 @@ messageReplyInfo reply_count:int32 recent_replier_ids:vector last //@recent_sender_ids Identifiers of at most 3 recent message senders, added the reaction; available in private, basic group and supergroup chats messageReaction type:ReactionType total_count:int32 is_chosen:Bool used_sender_id:MessageSender recent_sender_ids:vector = MessageReaction; -//@description Contains a list of reactions added to a message @reactions List of added reactions @are_tags True, if the reactions are tags and Telegram Premium users can filter messages by them; currently, always false +//@description Contains a list of reactions added to a message @reactions List of added reactions @are_tags True, if the reactions are tags and Telegram Premium users can filter messages by them messageReactions reactions:vector are_tags:Bool = MessageReactions; @@ -4047,7 +4047,7 @@ availableReaction type:ReactionType needs_premium:Bool = AvailableReaction; //@recent_reactions List of recently used reactions //@popular_reactions List of popular reactions //@allow_custom_emoji True, if any custom emoji reaction can be added by Telegram Premium subscribers -//@are_tags True, if the reactions will be tags and the message can be found by them; currently, always false +//@are_tags True, if the reactions will be tags and the message can be found by them //@unavailability_reason The reason why the current user can't add reactions to the message, despite some other users can; may be null if none availableReactions top_reactions:vector recent_reactions:vector popular_reactions:vector allow_custom_emoji:Bool are_tags:Bool unavailability_reason:ReactionUnavailabilityReason = AvailableReactions; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a77b5d6ae..1e3efd64b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -22756,9 +22756,8 @@ 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 false; - // return dialog_id == td_->dialog_manager_->get_my_dialog_id() && - // (reactions == nullptr || reactions->reactions_.empty() || reactions->are_tags_); + return dialog_id == td_->dialog_manager_->get_my_dialog_id() && + (reactions == nullptr || reactions->reactions_.empty() || reactions->are_tags_); } Result> MessagesManager::get_message_available_reactions( @@ -22823,8 +22822,17 @@ ChatReactions MessagesManager::get_message_available_reactions(const Dialog *d, if (active_reactions.allow_all_regular_) { 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; + auto default_tag_reactions = td_->reaction_manager_->get_default_tag_reactions(); + active_reactions.reaction_types_ = default_tag_reactions; + if (td_->option_manager_->get_option_boolean("is_premium")) { + for (auto &reaction_type : active_reaction_types_) { + if (!td::contains(default_tag_reactions, reaction_type)) { + active_reactions.reaction_types_.push_back(reaction_type); + } + } + } else { + disallow_custom_for_non_premium = true; + } } else { active_reactions.reaction_types_ = active_reaction_types_; } diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index 5bd0f4666..378015aba 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -435,13 +435,17 @@ td_api::object_ptr ReactionManager::get_sorted_avail } bool is_premium = td_->option_manager_->get_option_boolean("is_premium"); - bool show_premium = is_premium; + bool show_premium = is_premium || is_tag; vector recent_reactions; vector top_reactions; if (is_tag) { top_reactions = get_reaction_list(ReactionListType::DefaultTag).reaction_types_; if (is_premium) { - append(top_reactions, get_reaction_list(ReactionListType::Top).reaction_types_); + for (auto &reaction_type : get_reaction_list(ReactionListType::Top).reaction_types_) { + if (!td::contains(top_reactions, reaction_type)) { + top_reactions.push_back(reaction_type); + } + } } } else { recent_reactions = get_reaction_list(ReactionListType::Recent).reaction_types_; @@ -482,8 +486,8 @@ td_api::object_ptr ReactionManager::get_sorted_avail if (reaction_type.is_custom_reaction()) { added_custom_reaction_types.insert(reaction_type); } - reaction_objects.push_back( - td_api::make_object(reaction_type.get_reaction_type_object(), false)); + reaction_objects.push_back(td_api::make_object( + reaction_type.get_reaction_type_object(), is_tag && !is_premium)); } else if (reaction_type.is_custom_reaction() && available_reactions.allow_all_custom_ && added_custom_reaction_types.insert(reaction_type).second) { // add implicitly available custom reaction @@ -495,14 +499,11 @@ td_api::object_ptr ReactionManager::get_sorted_avail } }; if (show_premium) { - if (top_reactions.size() > 2 * static_cast(row_size)) { + if (!is_tag && top_reactions.size() > 2 * static_cast(row_size)) { top_reactions.resize(2 * static_cast(row_size)); } add_reactions(top_reaction_objects, top_reactions); - - if (!recent_reactions.empty()) { - add_reactions(recent_reaction_objects, recent_reactions); - } + add_reactions(recent_reaction_objects, recent_reactions); } else { add_reactions(top_reaction_objects, top_reactions); }