Add td_api::getChatFilterChatsToLeave.

This commit is contained in:
levlam 2023-04-02 12:40:57 +03:00
parent 4bf49b246f
commit 6198a6a842
6 changed files with 91 additions and 0 deletions

View File

@ -6797,6 +6797,9 @@ editChatFilter chat_filter_id:int32 filter:chatFilter = ChatFilterInfo;
//@description Deletes existing chat filter @chat_filter_id Chat filter identifier @leave_chat_ids Identifiers of the chats to leave. The chats must be pinned or always included by the filter
deleteChatFilter chat_filter_id:int32 leave_chat_ids:vector<int53> = Ok;
//@description Returns identifiers of pinned or always included chats from a chat filter, which are suggested to be left when the chat filter is deleted @chat_filter_id Chat filter identifier
getChatFilterChatsToLeave chat_filter_id:int32 = Chats;
//@description Changes the order of chat filters @chat_filter_ids Identifiers of chat filters in the new correct order @main_chat_list_position Position of the main chat list among chat filters, 0-based. Can be non-zero only for Premium users
reorderChatFilters chat_filter_ids:vector<int32> main_chat_list_position:int32 = Ok;

View File

@ -278,6 +278,35 @@ class LeaveChatlistQuery final : public Td::ResultHandler {
}
};
class GetLeaveChatlistSuggestionsQuery final : public Td::ResultHandler {
Promise<vector<telegram_api::object_ptr<telegram_api::Peer>>> promise_;
public:
explicit GetLeaveChatlistSuggestionsQuery(Promise<vector<telegram_api::object_ptr<telegram_api::Peer>>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogFilterId dialog_filter_id) {
send_query(G()->net_query_creator().create(
telegram_api::chatlists_getLeaveChatlistSuggestions(dialog_filter_id.get_input_chatlist())));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::chatlists_getLeaveChatlistSuggestions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetLeaveChatlistSuggestionsQuery: " << to_string(ptr);
promise_.set_value(std::move(ptr));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class CheckChatlistInviteQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatFilterInviteLinkInfo>> promise_;
string invite_link_;
@ -1525,6 +1554,45 @@ void DialogFilterManager::on_delete_dialog_filter(DialogFilterId dialog_filter_i
synchronize_dialog_filters();
}
void DialogFilterManager::get_leave_dialog_filter_suggestions(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> &&promise) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat folder not found"));
}
if (!dialog_filter->is_shareable()) {
return promise.set_value(td_api::make_object<td_api::chats>());
}
auto query_promise =
PromiseCreator::lambda([actor_id = actor_id(this), dialog_filter_id, promise = std::move(promise)](
Result<vector<telegram_api::object_ptr<telegram_api::Peer>>> &&result) mutable {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
send_closure(actor_id, &DialogFilterManager::on_get_leave_dialog_filter_suggestions, dialog_filter_id,
result.move_as_ok(), std::move(promise));
});
td_->create_handler<GetLeaveChatlistSuggestionsQuery>(std::move(query_promise))->send(dialog_filter_id);
}
void DialogFilterManager::on_get_leave_dialog_filter_suggestions(
DialogFilterId dialog_filter_id, vector<telegram_api::object_ptr<telegram_api::Peer>> peers,
Promise<td_api::object_ptr<td_api::chats>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat folder not found"));
}
if (!dialog_filter->is_shareable()) {
return promise.set_value(td_api::make_object<td_api::chats>());
}
auto dialog_ids = td_->messages_manager_->get_peers_dialog_ids(std::move(peers));
td::remove_if(dialog_ids, [&](DialogId dialog_id) { return !dialog_filter->is_dialog_included(dialog_id); });
promise.set_value(MessagesManager::get_chats_object(-1, dialog_ids));
}
void DialogFilterManager::reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids,
int32 main_dialog_list_position, Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot());

View File

@ -68,6 +68,9 @@ class DialogFilterManager final : public Actor {
void delete_dialog_filter(DialogFilterId dialog_filter_id, vector<DialogId> leave_dialog_ids,
Promise<Unit> &&promise);
void get_leave_dialog_filter_suggestions(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Promise<Unit> &&promise);
@ -156,6 +159,10 @@ class DialogFilterManager final : public Actor {
void on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result);
void on_get_leave_dialog_filter_suggestions(DialogFilterId dialog_filter_id,
vector<telegram_api::object_ptr<telegram_api::Peer>> peers,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void reorder_dialog_filters_on_server(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position);
void on_reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,

View File

@ -6145,6 +6145,13 @@ void Td::on_request(uint64 id, const td_api::deleteChatFilter &request) {
DialogId::get_dialog_ids(request.leave_chat_ids_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getChatFilterChatsToLeave &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
dialog_filter_manager_->get_leave_dialog_filter_suggestions(DialogFilterId(request.chat_filter_id_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::reorderChatFilters &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -923,6 +923,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::deleteChatFilter &request);
void on_request(uint64 id, const td_api::getChatFilterChatsToLeave &request);
void on_request(uint64 id, const td_api::reorderChatFilters &request);
void on_request(uint64 id, td_api::createChatFilterInviteLink &request);

View File

@ -4581,6 +4581,10 @@ class CliClient final : public Actor {
string chat_ids;
get_args(args, chat_filter_id, chat_ids);
send_request(td_api::make_object<td_api::deleteChatFilter>(chat_filter_id, as_chat_ids(chat_ids)));
} else if (op == "gcfctl") {
ChatFilterId chat_filter_id;
get_args(args, chat_filter_id);
send_request(td_api::make_object<td_api::getChatFilterChatsToLeave>(chat_filter_id));
} else if (op == "rcf") {
int32 main_chat_list_position;
string chat_filter_ids;