Allow to pass message thread identifier to readAllChatMentions.

This commit is contained in:
levlam 2022-10-24 16:57:26 +03:00
parent 4496c53313
commit df561b7822
5 changed files with 35 additions and 13 deletions

View File

@ -5507,8 +5507,8 @@ 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
readAllChatMentions chat_id:int53 = Ok;
//@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
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;

View File

@ -3226,7 +3226,7 @@ class ReadMentionsQuery final : public Td::ResultHandler {
explicit ReadMentionsQuery(Promise<AffectedHistory> &&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);
@ -3234,8 +3234,14 @@ class ReadMentionsQuery final : public Td::ResultHandler {
return promise_.set_error(Status::Error(400, "Chat is not accessible"));
}
send_query(G()->net_query_creator().create(telegram_api::messages_readMentions(0, std::move(input_peer), 0),
{{dialog_id}}));
int32 flags = 0;
if (top_thread_message_id.is_valid()) {
flags |= telegram_api::messages_readMentions::TOP_MSG_ID_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::messages_readMentions(flags, std::move(input_peer),
top_thread_message_id.get_server_message_id().get()),
{{dialog_id}}));
}
void on_result(BufferSlice packet) final {
@ -12017,17 +12023,31 @@ void MessagesManager::on_update_dialog_group_call_rights(DialogId dialog_id) {
}
}
void MessagesManager::read_all_dialog_mentions(DialogId dialog_id, Promise<Unit> &&promise) {
void MessagesManager::read_all_dialog_mentions(DialogId dialog_id, MessageId top_thread_message_id,
Promise<Unit> &&promise) {
Dialog *d = get_dialog_force(dialog_id, "read_all_dialog_mentions");
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
LOG(INFO) << "Receive readAllChatMentions request in " << dialog_id << " with " << d->unread_mention_count
<< " unread mentions";
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 readAllChatMentions request in thread of " << top_thread_message_id << " in " << dialog_id;
AffectedHistoryQuery query = [td = td_, top_thread_message_id](DialogId dialog_id,
Promise<AffectedHistory> &&query_promise) {
td->create_handler<ReadMentionsQuery>(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 readAllChatMentions request in " << dialog_id << " with " << d->unread_mention_count
<< " unread mentions";
}
if (dialog_id.get_type() == DialogType::SecretChat) {
CHECK(d->unread_mention_count == 0);
return promise.set_value(Unit());
@ -12100,7 +12120,7 @@ void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uin
}
AffectedHistoryQuery query = [td = td_](DialogId dialog_id, Promise<AffectedHistory> &&query_promise) {
td->create_handler<ReadMentionsQuery>(std::move(query_promise))->send(dialog_id);
td->create_handler<ReadMentionsQuery>(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)));

View File

@ -412,7 +412,7 @@ class MessagesManager final : public Actor {
void on_update_dialog_group_call_rights(DialogId dialog_id);
void read_all_dialog_mentions(DialogId dialog_id, Promise<Unit> &&promise);
void read_all_dialog_mentions(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
void read_all_dialog_reactions(DialogId dialog_id, Promise<Unit> &&promise);

View File

@ -5328,7 +5328,8 @@ void Td::on_request(uint64 id, const td_api::deleteChatMessagesByDate &request)
void Td::on_request(uint64 id, const td_api::readAllChatMentions &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->read_all_dialog_mentions(DialogId(request.chat_id_), std::move(promise));
messages_manager_->read_all_dialog_mentions(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::readAllChatReactions &request) {

View File

@ -4753,8 +4753,9 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getExternalLink>(link, op == "gelw"));
} else if (op == "racm") {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::readAllChatMentions>(chat_id));
string message_thread_id;
get_args(args, chat_id, message_thread_id);
send_request(td_api::make_object<td_api::readAllChatMentions>(chat_id, as_message_thread_id(message_thread_id)));
} else if (op == "racr") {
ChatId chat_id;
get_args(args, chat_id);