Add td_api::readChatList.

This commit is contained in:
levlam 2023-04-14 15:17:25 +03:00
parent d302dbd241
commit cfe57dbd60
6 changed files with 68 additions and 0 deletions

View File

@ -7066,6 +7066,9 @@ toggleChatIsPinned chat_list:ChatList chat_id:int53 is_pinned:Bool = Ok;
//@description Changes the order of pinned chats @chat_list Chat list in which to change the order of pinned chats @chat_ids The new list of pinned chats
setPinnedChats chat_list:ChatList chat_ids:vector<int53> = Ok;
//@description Traverse all chats in a chat list and marks all messages in the chats as read @chat_list Chat list in which to mark all chats as read
readChatList chat_list:ChatList = Ok;
//@description Returns information about a bot that can be added to attachment menu @bot_user_id Bot's user identifier
getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;

View File

@ -17275,6 +17275,57 @@ void MessagesManager::on_get_dialogs_from_list(int64 task_id, Result<Unit> &&res
get_dialogs_from_list_impl(task_id);
}
void MessagesManager::mark_dialog_as_read(Dialog *d) {
if (is_forum_channel(d->dialog_id)) {
// TODO read forum topics
}
if (d->server_unread_count + d->local_unread_count > 0 && d->last_message_id.is_valid()) {
MessagesConstIterator it(d, d->last_message_id);
while (*it != nullptr) {
auto message_id = (*it)->message_id;
if (message_id.is_server() || message_id.is_local()) {
read_dialog_inbox(d, message_id);
break;
}
--it;
}
if (*it == nullptr) {
// if can't find the last message, then d->last_new_message_id is the best guess
read_dialog_inbox(d, d->last_new_message_id);
}
}
if (d->is_marked_as_unread) {
set_dialog_is_marked_as_unread(d, false);
}
}
void MessagesManager::read_all_dialogs_from_list(DialogListId dialog_list_id, Promise<Unit> &&promise,
bool is_recursive) {
TRY_STATUS_PROMISE(promise, G()->close_status());
if (get_dialog_list(dialog_list_id) == nullptr) {
return promise.set_error(Status::Error(400, "Chat list not found"));
}
dialogs_.foreach([&](const DialogId &dialog_id, unique_ptr<Dialog> &dialog) {
Dialog *d = dialog.get();
if (is_dialog_in_list(d, dialog_list_id)) {
mark_dialog_as_read(d);
}
});
if (is_recursive) {
return promise.set_value(Unit());
}
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_list_id, promise = std::move(promise)](
Result<td_api::object_ptr<td_api::chats>> &&) mutable {
// it is expected that loading of so many chats will fail, so just ignore the error and result itself
send_closure(actor_id, &MessagesManager::read_all_dialogs_from_list, dialog_list_id, std::move(promise), true);
});
get_dialogs_from_list(dialog_list_id, 10000, std::move(query_promise));
}
vector<DialogId> MessagesManager::get_pinned_dialog_ids(DialogListId dialog_list_id) const {
CHECK(!td_->auth_manager_->is_bot());
if (dialog_list_id.is_filter()) {

View File

@ -599,6 +599,8 @@ class MessagesManager final : public Actor {
void get_dialogs_from_list(DialogListId dialog_list_id, int32 limit,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void read_all_dialogs_from_list(DialogListId dialog_list_id, Promise<Unit> &&promise, bool is_recursive = false);
vector<DialogId> search_public_dialogs(const string &query, Promise<Unit> &&promise);
std::pair<int32, vector<DialogId>> search_dialogs(const string &query, int32 limit, Promise<Unit> &&promise);
@ -2255,6 +2257,8 @@ class MessagesManager final : public Actor {
void read_dialog_inbox(Dialog *d, MessageId max_message_id);
void mark_dialog_as_read(Dialog *d);
int32 calc_new_unread_count_from_last_unread(Dialog *d, MessageId max_message_id, MessageType type) const;
int32 calc_new_unread_count_from_the_end(Dialog *d, MessageId max_message_id, MessageType type,

View File

@ -6294,6 +6294,12 @@ void Td::on_request(uint64 id, const td_api::setPinnedChats &request) {
DialogId::get_dialog_ids(request.chat_ids_)));
}
void Td::on_request(uint64 id, const td_api::readChatList &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->read_all_dialogs_from_list(DialogListId(request.chat_list_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -973,6 +973,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setPinnedChats &request);
void on_request(uint64 id, const td_api::readChatList &request);
void on_request(uint64 id, const td_api::getAttachmentMenuBot &request);
void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request);

View File

@ -3852,6 +3852,8 @@ class CliClient final : public Actor {
td_api::make_object<td_api::toggleChatDefaultDisableNotification>(chat_id, default_disable_notification));
} else if (op == "spchats" || op == "spchatsa" || begins_with(op, "spchats-")) {
send_request(td_api::make_object<td_api::setPinnedChats>(as_chat_list(op), as_chat_ids(args)));
} else if (op == "rcl" || op == "rcla" || begins_with(op, "rcl-")) {
send_request(td_api::make_object<td_api::readChatList>(as_chat_list(op)));
} else if (op == "gamb") {
UserId user_id;
get_args(args, user_id);