Ignore reaction updates while setting reaction.
This commit is contained in:
parent
3150b3d491
commit
abb2c1a105
@ -351,12 +351,6 @@ const MessageReaction *MessageReactions::get_reaction(const string &reaction) co
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessageReactions::update_from(const MessageReactions &old_reactions) {
|
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_) {
|
if (is_min_ && !old_reactions.is_min_) {
|
||||||
// chosen reaction was known, keep it
|
// chosen reaction was known, keep it
|
||||||
is_min_ = false;
|
is_min_ = false;
|
||||||
@ -395,10 +389,6 @@ bool MessageReactions::need_update_message_reactions(const MessageReactions *old
|
|||||||
// add reactions
|
// add reactions
|
||||||
return new_reactions != nullptr;
|
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) {
|
if (new_reactions == nullptr) {
|
||||||
// remove reactions when they are disabled
|
// remove reactions when they are disabled
|
||||||
return true;
|
return true;
|
||||||
|
@ -134,7 +134,6 @@ struct MessageReactions {
|
|||||||
bool is_min_ = false;
|
bool is_min_ = false;
|
||||||
bool need_polling_ = true;
|
bool need_polling_ = true;
|
||||||
bool can_see_all_choosers_ = false;
|
bool can_see_all_choosers_ = false;
|
||||||
bool has_pending_reaction_ = false;
|
|
||||||
|
|
||||||
MessageReactions() = default;
|
MessageReactions() = default;
|
||||||
|
|
||||||
|
@ -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 (has_reactions && reactions != nullptr) {
|
||||||
if (m->reactions != nullptr) {
|
if (m->reactions != nullptr) {
|
||||||
reactions->update_from(*m->reactions);
|
reactions->update_from(*m->reactions);
|
||||||
@ -24146,7 +24153,9 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
|
|||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
// m->reactions->has_pending_reaction_ = true;
|
|
||||||
|
pending_reactions_[full_message_id].query_count++;
|
||||||
|
|
||||||
if (!is_found && !reaction.empty()) {
|
if (!is_found && !reaction.empty()) {
|
||||||
vector<DialogId> recent_chooser_dialog_ids;
|
vector<DialogId> recent_chooser_dialog_ids;
|
||||||
if (!is_broadcast_channel(dialog_id)) {
|
if (!is_broadcast_channel(dialog_id)) {
|
||||||
@ -24172,12 +24181,23 @@ void MessagesManager::on_set_message_reaction(FullMessageId full_message_id, Res
|
|||||||
Promise<Unit> promise) {
|
Promise<Unit> promise) {
|
||||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||||
|
|
||||||
if (result.is_error() && have_message_force(full_message_id, "on_set_message_reaction")) {
|
bool need_reload = result.is_error();
|
||||||
reload_message_reactions(td_, full_message_id.get_dialog_id(), {full_message_id.get_message_id()});
|
auto it = pending_reactions_.find(full_message_id);
|
||||||
promise.set_error(result.move_as_error());
|
CHECK(it != pending_reactions_.end());
|
||||||
} else {
|
if (--it->second.query_count == 0) {
|
||||||
promise.set_value(Unit());
|
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,
|
void MessagesManager::get_message_public_forwards(FullMessageId full_message_id, string offset, int32 limit,
|
||||||
|
@ -3633,6 +3633,12 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
std::unordered_map<DialogId, MessageId, DialogIdHash> previous_repaired_read_inbox_max_message_id_;
|
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_;
|
vector<string> active_reactions_;
|
||||||
std::unordered_map<string, size_t> active_reaction_pos_;
|
std::unordered_map<string, size_t> active_reaction_pos_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user