Enable setting tags by Premium users.

This commit is contained in:
levlam 2024-02-01 22:40:55 +03:00
parent db4bd6b133
commit 32eba3c7d1
3 changed files with 25 additions and 16 deletions

View File

@ -1247,7 +1247,7 @@ messageReplyInfo reply_count:int32 recent_replier_ids:vector<MessageSender> 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<MessageSender> = 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<messageReaction> 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<availableReaction> recent_reactions:vector<availableReaction> popular_reactions:vector<availableReaction> allow_custom_emoji:Bool are_tags:Bool unavailability_reason:ReactionUnavailabilityReason = AvailableReactions;

View File

@ -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<td_api::object_ptr<td_api::availableReactions>> 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_;
}

View File

@ -435,13 +435,17 @@ td_api::object_ptr<td_api::availableReactions> 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<ReactionType> recent_reactions;
vector<ReactionType> 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<td_api::availableReactions> 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<td_api::availableReaction>(reaction_type.get_reaction_type_object(), false));
reaction_objects.push_back(td_api::make_object<td_api::availableReaction>(
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<td_api::availableReactions> ReactionManager::get_sorted_avail
}
};
if (show_premium) {
if (top_reactions.size() > 2 * static_cast<size_t>(row_size)) {
if (!is_tag && top_reactions.size() > 2 * static_cast<size_t>(row_size)) {
top_reactions.resize(2 * static_cast<size_t>(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);
}