Disallow adding new reactions in supergroup if can't send messages there.

This commit is contained in:
levlam 2022-08-07 12:48:36 +03:00
parent 36803d8d28
commit ae14546613

View File

@ -24332,8 +24332,19 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
return {}; return {};
} }
bool is_premium = G()->shared_config().get_option_boolean("is_premium"); bool can_use_reactions = true;
if (d->dialog_id.get_type() == DialogType::Channel) {
auto channel_id = d->dialog_id.get_channel_id();
if (td_->contacts_manager_->is_megagroup_channel(channel_id) &&
!td_->contacts_manager_->get_channel_status(channel_id).is_member() &&
can_send_message(d->dialog_id).is_error()) {
can_use_reactions = false;
}
}
vector<AvailableReaction> result; vector<AvailableReaction> result;
if (can_use_reactions) {
bool is_premium = G()->shared_config().get_option_boolean("is_premium");
int64 reactions_uniq_max = G()->shared_config().get_option_integer("reactions_uniq_max", 11); int64 reactions_uniq_max = G()->shared_config().get_option_integer("reactions_uniq_max", 11);
bool can_add_new_reactions = bool can_add_new_reactions =
m->reactions == nullptr || static_cast<int64>(m->reactions->reactions_.size()) < reactions_uniq_max; m->reactions == nullptr || static_cast<int64>(m->reactions->reactions_.size()) < reactions_uniq_max;
@ -24345,11 +24356,13 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
result.emplace_back(active_reaction.reaction_, !is_premium && active_reaction.is_premium_ && !is_set); result.emplace_back(active_reaction.reaction_, !is_premium && active_reaction.is_premium_ && !is_set);
} }
} }
}
if (m->reactions != nullptr) { if (m->reactions != nullptr) {
for (const auto &reaction : m->reactions->reactions_) { for (const auto &reaction : m->reactions->reactions_) {
if (reaction.is_chosen() && if (reaction.is_chosen() &&
get_reaction_type(result, reaction.get_reaction()) == AvailableReactionType::Unavailable) { get_reaction_type(result, reaction.get_reaction()) == AvailableReactionType::Unavailable) {
CHECK(get_reaction_type(active_reactions_, reaction.get_reaction()) == AvailableReactionType::Unavailable); CHECK(!can_use_reactions ||
get_reaction_type(active_reactions_, reaction.get_reaction()) == AvailableReactionType::Unavailable);
result.emplace_back(reaction.get_reaction(), false); result.emplace_back(reaction.get_reaction(), false);
} }
} }