Ignore reaction changes while there is a pending request to read unread reactions.

This commit is contained in:
levlam 2023-06-01 15:31:05 +03:00
parent 04525f6f6b
commit 6b342e9b0d
3 changed files with 47 additions and 4 deletions

View File

@ -7095,9 +7095,14 @@ bool MessagesManager::update_message_interaction_info(Dialog *d, Message *m, int
if (has_reactions) {
auto it = pending_reactions_.find({dialog_id, m->message_id});
if (it != pending_reactions_.end()) {
LOG(INFO) << "Ignore reactions, because have a pending message reaction";
has_reactions = false;
it->second.was_updated = true;
}
if (has_reactions && pending_read_reactions_.count({dialog_id, m->message_id}) > 0) {
LOG(INFO) << "Ignore reactions, because have a pending message reaction read";
has_reactions = false;
}
}
if (has_reactions && reactions != nullptr) {
if (m->reactions != nullptr) {
@ -19967,6 +19972,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
MessageId max_message_id; // max server or local viewed message_id
vector<MessageId> read_content_message_ids;
vector<MessageId> read_reaction_message_ids;
vector<MessageId> new_viewed_message_ids;
vector<MessageId> viewed_reaction_message_ids;
for (auto message_id : message_ids) {
@ -19995,7 +20001,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
if (need_read && remove_message_unread_reactions(d, m, "view_messages 7")) {
CHECK(m->message_id.is_server());
read_content_message_ids.push_back(m->message_id);
read_reaction_message_ids.push_back(m->message_id);
on_message_changed(d, m, true, "view_messages 8");
}
@ -20044,6 +20050,17 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
if (!read_content_message_ids.empty()) {
read_message_contents_on_server(dialog_id, std::move(read_content_message_ids), 0, Auto());
}
if (!read_reaction_message_ids.empty()) {
for (auto message_id : read_reaction_message_ids) {
pending_read_reactions_[{dialog_id, message_id}]++;
}
auto promise = PromiseCreator::lambda(
[actor_id = actor_id(this), dialog_id, read_reaction_message_ids](Result<Unit> &&result) mutable {
send_closure(actor_id, &MessagesManager::on_read_message_reactions, dialog_id,
std::move(read_reaction_message_ids), std::move(result));
});
read_message_contents_on_server(dialog_id, std::move(read_reaction_message_ids), 0, std::move(promise));
}
if (!new_viewed_message_ids.empty()) {
LOG(INFO) << "Have new viewed " << new_viewed_message_ids;
auto &info = dialog_viewed_messages_[dialog_id];
@ -23818,7 +23835,7 @@ void MessagesManager::on_set_message_reactions(FullMessageId full_message_id, Re
pending_reactions_.erase(it);
}
if (!have_message_force(full_message_id, "on_set_message_reaction")) {
if (!have_message_force(full_message_id, "on_set_message_reactions")) {
return promise.set_value(Unit());
}
@ -23829,6 +23846,26 @@ void MessagesManager::on_set_message_reactions(FullMessageId full_message_id, Re
promise.set_result(std::move(result));
}
void MessagesManager::on_read_message_reactions(DialogId dialog_id, vector<MessageId> &&message_ids,
Result<Unit> &&result) {
for (auto message_id : message_ids) {
FullMessageId full_message_id{dialog_id, message_id};
auto it = pending_read_reactions_.find(full_message_id);
CHECK(it != pending_read_reactions_.end());
if (--it->second == 0) {
pending_read_reactions_.erase(it);
}
if (!have_message_force(full_message_id, "on_read_message_reactions")) {
continue;
}
if (result.is_error()) {
queue_message_reactions_reload(full_message_id);
}
}
}
void MessagesManager::get_message_public_forwards(FullMessageId full_message_id, string offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise) {
auto dc_id_promise = PromiseCreator::lambda([actor_id = actor_id(this), full_message_id, offset = std::move(offset),

View File

@ -2623,6 +2623,8 @@ class MessagesManager final : public Actor {
void on_set_message_reactions(FullMessageId full_message_id, Result<Unit> result, Promise<Unit> promise);
void on_read_message_reactions(DialogId dialog_id, vector<MessageId> &&message_ids, Result<Unit> &&result);
void set_dialog_available_reactions(Dialog *d, ChatReactions &&available_reactions);
void set_dialog_next_available_reactions_generation(Dialog *d, uint32 generation);
@ -3636,6 +3638,8 @@ class MessagesManager final : public Actor {
};
FlatHashMap<FullMessageId, PendingReaction, FullMessageIdHash> pending_reactions_;
FlatHashMap<FullMessageId, int32, FullMessageIdHash> pending_read_reactions_;
vector<string> active_reactions_;
FlatHashMap<string, size_t> active_reaction_pos_;

View File

@ -5218,12 +5218,14 @@ class CliClient final : public Actor {
} else if (op == "rrh") {
const string &hashtag = args;
send_request(td_api::make_object<td_api::removeRecentHashtag>(hashtag));
} else if (op == "view" || op == "viewt") {
} else if (op == "view" || op == "viewh" || op == "viewt") {
ChatId chat_id;
string message_ids;
get_args(args, chat_id, message_ids);
td_api::object_ptr<td_api::MessageSource> source;
if (op == "viewt") {
if (op == "viewh") {
source = td_api::make_object<td_api::messageSourceChatHistory>();
} else if (op == "viewt") {
source = td_api::make_object<td_api::messageSourceMessageThreadHistory>();
}
send_request(