Add ChatReactions::is_allowed_reaction.

This commit is contained in:
levlam 2022-09-09 16:34:14 +03:00
parent a223067cd1
commit 89a1311c91
3 changed files with 11 additions and 1 deletions

View File

@ -71,6 +71,14 @@ ChatReactions ChatReactions::get_active_reactions(const FlatHashMap<string, size
return result; return result;
} }
bool ChatReactions::is_allowed_reaction(const string &reaction) const {
CHECK(!allow_all_);
if (allow_custom_ && reaction[0] == '#') {
return true;
}
return td::contains(reactions_, reaction);
}
td_api::object_ptr<td_api::ChatAvailableReactions> ChatReactions::get_chat_available_reactions_object() const { td_api::object_ptr<td_api::ChatAvailableReactions> ChatReactions::get_chat_available_reactions_object() const {
if (allow_all_) { if (allow_all_) {
return td_api::make_object<td_api::chatAvailableReactionsAll>(); return td_api::make_object<td_api::chatAvailableReactionsAll>();

View File

@ -35,6 +35,8 @@ struct ChatReactions {
ChatReactions get_active_reactions(const FlatHashMap<string, size_t> &active_reaction_pos) const; ChatReactions get_active_reactions(const FlatHashMap<string, size_t> &active_reaction_pos) const;
bool is_allowed_reaction(const string &reaction) const;
telegram_api::object_ptr<telegram_api::ChatReactions> get_input_chat_reactions() const; telegram_api::object_ptr<telegram_api::ChatReactions> get_input_chat_reactions() const;
td_api::object_ptr<td_api::ChatAvailableReactions> get_chat_available_reactions_object() const; td_api::object_ptr<td_api::ChatAvailableReactions> get_chat_available_reactions_object() const;

View File

@ -24531,7 +24531,7 @@ void MessagesManager::add_message_reaction(FullMessageId full_message_id, string
return promise.set_error(Status::Error(400, "Message not found")); return promise.set_error(Status::Error(400, "Message not found"));
} }
if (!td::contains(get_message_available_reactions(d, m).reactions_, reaction)) { if (!get_message_available_reactions(d, m).is_allowed_reaction(reaction)) {
return promise.set_error(Status::Error(400, "The reaction isn't available for the message")); return promise.set_error(Status::Error(400, "The reaction isn't available for the message"));
} }