Add td_api::getChatFolderChatCount.

This commit is contained in:
levlam 2023-05-01 14:57:16 +03:00
parent 29c0004bfd
commit ac81a35283
7 changed files with 44 additions and 1 deletions

View File

@ -6840,6 +6840,9 @@ deleteChatFolder chat_folder_id:int32 leave_chat_ids:vector<int53> = Ok;
//@description Returns identifiers of pinned or always included chats from a chat folder, which are suggested to be left when the chat folder is deleted @chat_folder_id Chat folder identifier //@description Returns identifiers of pinned or always included chats from a chat folder, which are suggested to be left when the chat folder is deleted @chat_folder_id Chat folder identifier
getChatFolderChatsToLeave chat_folder_id:int32 = Chats; getChatFolderChatsToLeave chat_folder_id:int32 = Chats;
//@description Returns approximate number of chats in a being created chat folder. Main and archive chat lists must be fully preloaded for this function to work correctly @folder The new chat folder
getChatFolderChatCount folder:chatFolder = Count;
//@description Changes the order of chat folders @chat_folder_ids Identifiers of chat folders in the new correct order @main_chat_list_position Position of the main chat list among chat folders, 0-based. Can be non-zero only for Premium users //@description Changes the order of chat folders @chat_folder_ids Identifiers of chat folders in the new correct order @main_chat_list_position Position of the main chat list among chat folders, 0-based. Can be non-zero only for Premium users
reorderChatFolders chat_folder_ids:vector<int32> main_chat_list_position:int32 = Ok; reorderChatFolders chat_folder_ids:vector<int32> main_chat_list_position:int32 = Ok;

View File

@ -1469,7 +1469,6 @@ td_api::object_ptr<td_api::updateChatFolders> DialogFilterManager::get_update_ch
void DialogFilterManager::create_dialog_filter(td_api::object_ptr<td_api::chatFolder> filter, void DialogFilterManager::create_dialog_filter(td_api::object_ptr<td_api::chatFolder> filter,
Promise<td_api::object_ptr<td_api::chatFolderInfo>> &&promise) { Promise<td_api::object_ptr<td_api::chatFolderInfo>> &&promise) {
CHECK(!td_->auth_manager_->is_bot());
auto max_dialog_filters = clamp(td_->option_manager_->get_option_integer("chat_folder_count_max"), auto max_dialog_filters = clamp(td_->option_manager_->get_option_integer("chat_folder_count_max"),
static_cast<int64>(0), static_cast<int64>(100)); static_cast<int64>(0), static_cast<int64>(100));
if (dialog_filters_.size() >= narrow_cast<size_t>(max_dialog_filters)) { if (dialog_filters_.size() >= narrow_cast<size_t>(max_dialog_filters)) {

View File

@ -32993,6 +32993,28 @@ void MessagesManager::clear_active_dialog_actions(DialogId dialog_id) {
} }
} }
void MessagesManager::get_dialog_filter_dialog_count(td_api::object_ptr<td_api::chatFolder> filter,
Promise<int32> &&promise) {
TRY_RESULT_PROMISE(promise, dialog_filter,
DialogFilter::create_dialog_filter(td_, DialogFilterId(), std::move(filter)));
int32 total_count = 0;
for (auto folder_id : dialog_filter->get_folder_ids()) {
const auto &folder = *get_dialog_folder(folder_id);
for (const auto &dialog_date : folder.ordered_dialogs_) {
if (dialog_date.get_order() == DEFAULT_ORDER) {
break;
}
auto dialog_id = dialog_date.get_dialog_id();
if (dialog_filter->need_dialog(td_, get_dialog_info_for_dialog_filter(get_dialog(dialog_id)))) {
total_count++;
}
}
}
promise.set_value(std::move(total_count));
}
void MessagesManager::add_dialog_list_for_dialog_filter(DialogFilterId dialog_filter_id) { void MessagesManager::add_dialog_list_for_dialog_filter(DialogFilterId dialog_filter_id) {
DialogListId dialog_list_id(dialog_filter_id); DialogListId dialog_list_id(dialog_filter_id);
CHECK(dialog_lists_.count(dialog_list_id) == 0); CHECK(dialog_lists_.count(dialog_list_id) == 0);

View File

@ -538,6 +538,8 @@ class MessagesManager final : public Actor {
void after_set_typing_query(DialogId dialog_id, int32 generation); void after_set_typing_query(DialogId dialog_id, int32 generation);
void get_dialog_filter_dialog_count(td_api::object_ptr<td_api::chatFolder> filter, Promise<int32> &&promise);
void add_dialog_list_for_dialog_filter(DialogFilterId dialog_filter_id); void add_dialog_list_for_dialog_filter(DialogFilterId dialog_filter_id);
void edit_dialog_list_for_dialog_filter(unique_ptr<DialogFilter> &old_dialog_filter, void edit_dialog_list_for_dialog_filter(unique_ptr<DialogFilter> &old_dialog_filter,

View File

@ -6135,6 +6135,19 @@ void Td::on_request(uint64 id, const td_api::getChatFolderChatsToLeave &request)
std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, td_api::getChatFolderChatCount &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<int32> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(make_tl_object<td_api::count>(result.move_as_ok()));
}
});
messages_manager_->get_dialog_filter_dialog_count(std::move(request.folder_), std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::reorderChatFolders &request) { void Td::on_request(uint64 id, const td_api::reorderChatFolders &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();

View File

@ -926,6 +926,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getChatFolderChatsToLeave &request); void on_request(uint64 id, const td_api::getChatFolderChatsToLeave &request);
void on_request(uint64 id, td_api::getChatFolderChatCount &request);
void on_request(uint64 id, const td_api::reorderChatFolders &request); void on_request(uint64 id, const td_api::reorderChatFolders &request);
void on_request(uint64 id, const td_api::getChatsForChatFolderInviteLink &request); void on_request(uint64 id, const td_api::getChatsForChatFolderInviteLink &request);

View File

@ -4669,6 +4669,8 @@ class CliClient final : public Actor {
ChatFolderId chat_folder_id; ChatFolderId chat_folder_id;
get_args(args, chat_folder_id); get_args(args, chat_folder_id);
send_request(td_api::make_object<td_api::getChatFolderChatsToLeave>(chat_folder_id)); send_request(td_api::make_object<td_api::getChatFolderChatsToLeave>(chat_folder_id));
} else if (op == "gcfcc") {
send_request(td_api::make_object<td_api::getChatFolderChatCount>(as_chat_folder(args)));
} else if (op == "rcf") { } else if (op == "rcf") {
int32 main_chat_list_position; int32 main_chat_list_position;
string chat_folder_ids; string chat_folder_ids;