diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index 65e8dbed7..7a0827c4a 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -275,6 +275,15 @@ MessageReaction *MessageReactions::get_reaction(const string &reaction) { return nullptr; } +const MessageReaction *MessageReactions::get_reaction(const string &reaction) const { + for (auto &chosen_reaction : reactions_) { + if (chosen_reaction.get_reaction() == reaction) { + return &chosen_reaction; + } + } + return nullptr; +} + void MessageReactions::update_from(const MessageReactions &old_reactions) { if (old_reactions.has_pending_reaction_) { // we will ignore all updates, received while there is a pending reaction, so there are no reasons to update diff --git a/td/telegram/MessageReaction.h b/td/telegram/MessageReaction.h index 5545827a3..0e37caabc 100644 --- a/td/telegram/MessageReaction.h +++ b/td/telegram/MessageReaction.h @@ -109,6 +109,8 @@ struct MessageReactions { MessageReaction *get_reaction(const string &reaction); + const MessageReaction *get_reaction(const string &reaction) const; + void update_from(const MessageReactions &old_reactions); void sort(const std::unordered_map &active_reaction_pos); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 17b2aeb40..89d6de505 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -23765,11 +23765,16 @@ Result> MessagesManager::get_message_available_reactions(FullMess return Status::Error(400, "Chat not found"); } - Message *m = get_message_force(d, full_message_id.get_message_id(), "get_message_available_reactions"); + const Message *m = get_message_force(d, full_message_id.get_message_id(), "get_message_available_reactions"); if (m == nullptr) { return Status::Error(400, "Message not found"); } + return get_message_available_reactions(d, m); +} +vector MessagesManager::get_message_available_reactions(const Dialog *d, const Message *m) { + CHECK(d != nullptr); + CHECK(m != nullptr); if (!m->message_id.is_valid() || !m->message_id.is_server() || get_active_reactions(d->available_reactions).empty()) { return vector(); } @@ -23810,16 +23815,8 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string return promise.set_error(Status::Error(400, "Message not found")); } - if (dialog_id.get_type() == DialogType::SecretChat || !m->message_id.is_valid() || !m->message_id.is_server()) { - return promise.set_error(Status::Error(400, "Message can't have reactions")); - } - - if (!is_visible_message_reactions(dialog_id, m)) { - return promise.set_error(Status::Error(400, "Can't set reactions for the message")); - } - - if (!reaction.empty() && !is_active_reaction(td_, reaction)) { - return promise.set_error(Status::Error(400, "Invalid reaction specified")); + if (!td::contains(get_message_available_reactions(d, m), reaction)) { + return promise.set_error(Status::Error(400, "The reaction isn't available for the message")); } bool can_see_all_choosers = !is_broadcast_channel(dialog_id); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 05898a4c5..a913d8021 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2596,6 +2596,8 @@ class MessagesManager final : public Actor { bool update_dialog_silent_send_message(Dialog *d, bool silent_send_message); + vector get_message_available_reactions(const Dialog *d, const Message *m); + void set_dialog_available_reactions(Dialog *d, vector &&available_reactions); void update_dialog_message_reactions_visibility(const Dialog *d);