Ignore reaction updates while setting reaction.

This commit is contained in:
levlam 2022-01-30 12:55:27 +03:00
parent 3150b3d491
commit abb2c1a105
4 changed files with 32 additions and 17 deletions

View File

@ -351,12 +351,6 @@ const MessageReaction *MessageReactions::get_reaction(const string &reaction) co
}
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
return;
}
CHECK(!has_pending_reaction_);
if (is_min_ && !old_reactions.is_min_) {
// chosen reaction was known, keep it
is_min_ = false;
@ -395,10 +389,6 @@ bool MessageReactions::need_update_message_reactions(const MessageReactions *old
// add reactions
return new_reactions != nullptr;
}
if (old_reactions->has_pending_reaction_) {
// ignore all updates, received while there is a pending reaction
return false;
}
if (new_reactions == nullptr) {
// remove reactions when they are disabled
return true;

View File

@ -134,7 +134,6 @@ struct MessageReactions {
bool is_min_ = false;
bool need_polling_ = true;
bool can_see_all_choosers_ = false;
bool has_pending_reaction_ = false;
MessageReactions() = default;

View File

@ -7092,6 +7092,13 @@ bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Messag
}
}
}
if (has_reactions) {
auto it = pending_reactions_.find({dialog_id, m->message_id});
if (it != pending_reactions_.end()) {
has_reactions = false;
it->second.was_updated = true;
}
}
if (has_reactions && reactions != nullptr) {
if (m->reactions != nullptr) {
reactions->update_from(*m->reactions);
@ -24146,7 +24153,9 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
++it;
}
// m->reactions->has_pending_reaction_ = true;
pending_reactions_[full_message_id].query_count++;
if (!is_found && !reaction.empty()) {
vector<DialogId> recent_chooser_dialog_ids;
if (!is_broadcast_channel(dialog_id)) {
@ -24172,12 +24181,23 @@ void MessagesManager::on_set_message_reaction(FullMessageId full_message_id, Res
Promise<Unit> promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
if (result.is_error() && have_message_force(full_message_id, "on_set_message_reaction")) {
reload_message_reactions(td_, full_message_id.get_dialog_id(), {full_message_id.get_message_id()});
promise.set_error(result.move_as_error());
} else {
promise.set_value(Unit());
bool need_reload = result.is_error();
auto it = pending_reactions_.find(full_message_id);
CHECK(it != pending_reactions_.end());
if (--it->second.query_count == 0) {
need_reload |= it->second.was_updated;
pending_reactions_.erase(it);
}
if (!have_message_force(full_message_id, "on_set_message_reaction")) {
return promise.set_value(Unit());
}
if (need_reload) {
reload_message_reactions(td_, full_message_id.get_dialog_id(), {full_message_id.get_message_id()});
}
promise.set_result(std::move(result));
}
void MessagesManager::get_message_public_forwards(FullMessageId full_message_id, string offset, int32 limit,

View File

@ -3633,6 +3633,12 @@ class MessagesManager final : public Actor {
std::unordered_map<DialogId, MessageId, DialogIdHash> previous_repaired_read_inbox_max_message_id_;
struct PendingReaction {
int32 query_count = 0;
bool was_updated = false;
};
std::unordered_map<FullMessageId, PendingReaction, FullMessageIdHash> pending_reactions_;
vector<string> active_reactions_;
std::unordered_map<string, size_t> active_reaction_pos_;