Check that reaction is among available reactions before set it locally.
This commit is contained in:
parent
ba5c326ba8
commit
97e0288363
@ -275,6 +275,15 @@ MessageReaction *MessageReactions::get_reaction(const string &reaction) {
|
|||||||
return nullptr;
|
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) {
|
void MessageReactions::update_from(const MessageReactions &old_reactions) {
|
||||||
if (old_reactions.has_pending_reaction_) {
|
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
|
// we will ignore all updates, received while there is a pending reaction, so there are no reasons to update
|
||||||
|
@ -109,6 +109,8 @@ struct MessageReactions {
|
|||||||
|
|
||||||
MessageReaction *get_reaction(const string &reaction);
|
MessageReaction *get_reaction(const string &reaction);
|
||||||
|
|
||||||
|
const MessageReaction *get_reaction(const string &reaction) const;
|
||||||
|
|
||||||
void update_from(const MessageReactions &old_reactions);
|
void update_from(const MessageReactions &old_reactions);
|
||||||
|
|
||||||
void sort(const std::unordered_map<string, size_t> &active_reaction_pos);
|
void sort(const std::unordered_map<string, size_t> &active_reaction_pos);
|
||||||
|
@ -23765,11 +23765,16 @@ Result<vector<string>> MessagesManager::get_message_available_reactions(FullMess
|
|||||||
return Status::Error(400, "Chat not found");
|
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) {
|
if (m == nullptr) {
|
||||||
return Status::Error(400, "Message not found");
|
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()) {
|
if (!m->message_id.is_valid() || !m->message_id.is_server() || get_active_reactions(d->available_reactions).empty()) {
|
||||||
return vector<string>();
|
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"));
|
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()) {
|
if (!td::contains(get_message_available_reactions(d, m), reaction)) {
|
||||||
return promise.set_error(Status::Error(400, "Message can't have reactions"));
|
return promise.set_error(Status::Error(400, "The reaction isn't available for the message"));
|
||||||
}
|
|
||||||
|
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool can_see_all_choosers = !is_broadcast_channel(dialog_id);
|
bool can_see_all_choosers = !is_broadcast_channel(dialog_id);
|
||||||
|
@ -2596,6 +2596,8 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
bool update_dialog_silent_send_message(Dialog *d, bool silent_send_message);
|
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 set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions);
|
||||||
|
|
||||||
void update_dialog_message_reactions_visibility(const Dialog *d);
|
void update_dialog_message_reactions_visibility(const Dialog *d);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user