From 75739dd0eae096bd924382edb3dff87125c66196 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 24 Oct 2022 17:04:05 +0300 Subject: [PATCH] Allow to pass message thread identifier to readAllChatReactions. --- td/generate/scheme/td_api.tl | 6 +++--- td/telegram/MessagesManager.cpp | 34 ++++++++++++++++++++++++++------- td/telegram/MessagesManager.h | 2 +- td/telegram/Td.cpp | 3 ++- td/telegram/cli.cpp | 5 +++-- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d2a3bbb0a..83e2ffb50 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5507,11 +5507,11 @@ getExternalLinkInfo link:string = LoginUrlInfo; getExternalLink link:string allow_write_access:Bool = HttpUrl; -//@description Marks all mentions in a chat as read @chat_id Chat identifier @message_thread_id If not 0, a message thread identifier in mentions are marked as read; for forum supergroups only +//@description Marks all mentions in a chat as read @chat_id Chat identifier @message_thread_id If not 0, a message thread identifier in which mentions are marked as read; for forum supergroups only readAllChatMentions chat_id:int53 message_thread_id:int53 = Ok; -//@description Marks all reactions in a chat as read @chat_id Chat identifier -readAllChatReactions chat_id:int53 = Ok; +//@description Marks all reactions in a chat as read @chat_id Chat identifier @message_thread_id If not 0, a message thread identifier in which reactions are marked as read; for forum supergroups only +readAllChatReactions chat_id:int53 message_thread_id:int53 = Ok; //@description Returns an existing chat corresponding to a given user @user_id User identifier @force Pass true to create the chat without a network request. In this case all information about the chat except its type, title and photo can be incorrect diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5f4389032..536e3329f 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3267,7 +3267,7 @@ class ReadReactionsQuery final : public Td::ResultHandler { explicit ReadReactionsQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(DialogId dialog_id) { + void send(DialogId dialog_id, MessageId top_thread_message_id) { dialog_id_ = dialog_id; auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read); @@ -3276,8 +3276,13 @@ class ReadReactionsQuery final : public Td::ResultHandler { } int32 flags = 0; - send_query(G()->net_query_creator().create(telegram_api::messages_readReactions(flags, std::move(input_peer), 0), - {{dialog_id}})); + if (top_thread_message_id.is_valid()) { + flags |= telegram_api::messages_readReactions::TOP_MSG_ID_MASK; + } + send_query(G()->net_query_creator().create( + telegram_api::messages_readReactions(flags, std::move(input_peer), + top_thread_message_id.get_server_message_id().get()), + {{dialog_id}})); } void on_result(BufferSlice packet) final { @@ -12126,17 +12131,32 @@ void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uin get_erase_log_event_promise(log_event_id, std::move(promise))); } -void MessagesManager::read_all_dialog_reactions(DialogId dialog_id, Promise &&promise) { +void MessagesManager::read_all_dialog_reactions(DialogId dialog_id, MessageId top_thread_message_id, + Promise &&promise) { Dialog *d = get_dialog_force(dialog_id, "read_all_dialog_reactions"); if (d == nullptr) { return promise.set_error(Status::Error(400, "Chat not found")); } - LOG(INFO) << "Receive readAllChatReactions request in " << dialog_id << " with " << d->unread_reaction_count - << " unread reactions"; + TRY_STATUS_PROMISE(promise, can_use_top_thread_message_id(d, top_thread_message_id, MessageId())); + if (!have_input_peer(dialog_id, AccessRights::Read)) { return promise.set_error(Status::Error(400, "Chat is not accessible")); } + + if (top_thread_message_id.is_valid()) { + LOG(INFO) << "Receive readAllChatReactions request in thread of " << top_thread_message_id << " in " << dialog_id; + AffectedHistoryQuery query = [td = td_, top_thread_message_id](DialogId dialog_id, + Promise &&query_promise) { + td->create_handler(std::move(query_promise))->send(dialog_id, top_thread_message_id); + }; + run_affected_history_query_until_complete(dialog_id, std::move(query), true, std::move(promise)); + return; + } else { + LOG(INFO) << "Receive readAllChatReactions request in " << dialog_id << " with " << d->unread_reaction_count + << " unread reactions"; + } + if (dialog_id.get_type() == DialogType::SecretChat) { CHECK(d->unread_reaction_count == 0); return promise.set_value(Unit()); @@ -12204,7 +12224,7 @@ void MessagesManager::read_all_dialog_reactions_on_server(DialogId dialog_id, ui } AffectedHistoryQuery query = [td = td_](DialogId dialog_id, Promise &&query_promise) { - td->create_handler(std::move(query_promise))->send(dialog_id); + td->create_handler(std::move(query_promise))->send(dialog_id, MessageId()); }; run_affected_history_query_until_complete(dialog_id, std::move(query), false, get_erase_log_event_promise(log_event_id, std::move(promise))); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 3e9f5cff9..8728216a5 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -414,7 +414,7 @@ class MessagesManager final : public Actor { void read_all_dialog_mentions(DialogId dialog_id, MessageId top_thread_message_id, Promise &&promise); - void read_all_dialog_reactions(DialogId dialog_id, Promise &&promise); + void read_all_dialog_reactions(DialogId dialog_id, MessageId top_thread_message_id, Promise &&promise); Status add_recently_found_dialog(DialogId dialog_id) TD_WARN_UNUSED_RESULT; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index e526cdaf6..a6df8f418 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5335,7 +5335,8 @@ void Td::on_request(uint64 id, const td_api::readAllChatMentions &request) { void Td::on_request(uint64 id, const td_api::readAllChatReactions &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - messages_manager_->read_all_dialog_reactions(DialogId(request.chat_id_), std::move(promise)); + messages_manager_->read_all_dialog_reactions(DialogId(request.chat_id_), MessageId(request.message_thread_id_), + std::move(promise)); } void Td::on_request(uint64 id, const td_api::getChatAvailableMessageSenders &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 56e81b0df..2acaed57e 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4758,8 +4758,9 @@ class CliClient final : public Actor { send_request(td_api::make_object(chat_id, as_message_thread_id(message_thread_id))); } else if (op == "racr") { ChatId chat_id; - get_args(args, chat_id); - send_request(td_api::make_object(chat_id)); + string message_thread_id; + get_args(args, chat_id, message_thread_id); + send_request(td_api::make_object(chat_id, as_message_thread_id(message_thread_id))); } else if (op == "tre") { send_request(td_api::make_object( args.empty() ? nullptr : td_api::make_object(-1, args)));