Check that reaction is among available reactions before set it locally.

This commit is contained in:
levlam 2022-01-26 16:51:47 +03:00
parent ba5c326ba8
commit 97e0288363
4 changed files with 21 additions and 11 deletions

View File

@ -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

View File

@ -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<string, size_t> &active_reaction_pos);

View File

@ -23765,11 +23765,16 @@ Result<vector<string>> 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<string> 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<string>();
}
@ -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);

View File

@ -2596,6 +2596,8 @@ class MessagesManager final : public Actor {
bool update_dialog_silent_send_message(Dialog *d, bool silent_send_message);
vector<string> get_message_available_reactions(const Dialog *d, const Message *m);
void set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions);
void update_dialog_message_reactions_visibility(const Dialog *d);