Add deleteChatFilter.leave_chat_ids.

This commit is contained in:
levlam 2023-04-02 12:05:04 +03:00
parent 7085bc4d8f
commit 4bf49b246f
5 changed files with 41 additions and 12 deletions

View File

@ -6794,8 +6794,8 @@ createChatFilter filter:chatFilter = ChatFilterInfo;
//@description Edits existing chat filter. Returns information about the edited chat filter @chat_filter_id Chat filter identifier @filter The edited chat filter //@description Edits existing chat filter. Returns information about the edited chat filter @chat_filter_id Chat filter identifier @filter The edited chat filter
editChatFilter chat_filter_id:int32 filter:chatFilter = ChatFilterInfo; editChatFilter chat_filter_id:int32 filter:chatFilter = ChatFilterInfo;
//@description Deletes existing chat filter @chat_filter_id Chat filter identifier //@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 = Ok; deleteChatFilter chat_filter_id:int32 leave_chat_ids:vector<int53> = Ok;
//@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 //@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; reorderChatFilters chat_filter_ids:vector<int32> main_chat_list_position:int32 = Ok;

View File

@ -879,7 +879,7 @@ void DialogFilterManager::delete_dialogs_from_filter(const DialogFilter *dialog_
new_dialog_filter->remove_dialog_id(dialog_id); new_dialog_filter->remove_dialog_id(dialog_id);
} }
if (new_dialog_filter->is_empty(false)) { if (new_dialog_filter->is_empty(false)) {
delete_dialog_filter(dialog_filter->get_dialog_filter_id(), Promise<Unit>()); delete_dialog_filter(dialog_filter->get_dialog_filter_id(), vector<DialogId>(), Promise<Unit>());
return; return;
} }
CHECK(new_dialog_filter->check_limits().is_ok()); CHECK(new_dialog_filter->check_limits().is_ok());
@ -1157,7 +1157,7 @@ void DialogFilterManager::on_get_dialog_filters(
// the filter was deleted from another client // the filter was deleted from another client
// ignore edits done from the current client and just delete the filter // ignore edits done from the current client and just delete the filter
is_changed = true; is_changed = true;
delete_dialog_filter(dialog_filter_id, "on_get_dialog_filters"); do_delete_dialog_filter(dialog_filter_id, "on_get_dialog_filters");
} }
} }
bool is_order_changed = [&] { bool is_order_changed = [&] {
@ -1449,14 +1449,40 @@ void DialogFilterManager::on_update_dialog_filter(unique_ptr<DialogFilter> dialo
synchronize_dialog_filters(); synchronize_dialog_filters();
} }
void DialogFilterManager::delete_dialog_filter(DialogFilterId dialog_filter_id, Promise<Unit> &&promise) { void DialogFilterManager::delete_dialog_filter(DialogFilterId dialog_filter_id, vector<DialogId> leave_dialog_ids,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
auto dialog_filter = get_dialog_filter(dialog_filter_id); auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) { if (dialog_filter == nullptr) {
return promise.set_value(Unit()); return promise.set_value(Unit());
} }
for (auto &leave_dialog_id : leave_dialog_ids) {
if (!dialog_filter->is_dialog_included(leave_dialog_id)) {
return promise.set_error(Status::Error(400, "The chat doesn't included in the folder"));
}
}
if (!leave_dialog_ids.empty()) {
MultiPromiseActorSafe mpas{"LeaveDialogsMultiPromiseActor"};
mpas.add_promise(PromiseCreator::lambda(
[actor_id = actor_id(this), dialog_filter_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
send_closure(actor_id, &DialogFilterManager::delete_dialog_filter, dialog_filter_id, vector<DialogId>(),
std::move(promise));
}));
auto lock = mpas.get_promise();
int32 position = delete_dialog_filter(dialog_filter_id, "delete_dialog_filter"); for (auto &leave_dialog_id : leave_dialog_ids) {
td_->contacts_manager_->leave_dialog(leave_dialog_id, mpas.get_promise());
}
lock.set_value(Unit());
return;
}
int32 position = do_delete_dialog_filter(dialog_filter_id, "delete_dialog_filter");
if (main_dialog_list_position_ > position) { if (main_dialog_list_position_ > position) {
main_dialog_list_position_--; main_dialog_list_position_--;
} }
@ -1605,7 +1631,7 @@ void DialogFilterManager::edit_dialog_filter(unique_ptr<DialogFilter> new_dialog
UNREACHABLE(); UNREACHABLE();
} }
int32 DialogFilterManager::delete_dialog_filter(DialogFilterId dialog_filter_id, const char *source) { int32 DialogFilterManager::do_delete_dialog_filter(DialogFilterId dialog_filter_id, const char *source) {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
// just in case // just in case
return -1; return -1;

View File

@ -65,7 +65,8 @@ class DialogFilterManager final : public Actor {
void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter, void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise); Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise);
void delete_dialog_filter(DialogFilterId dialog_filter_id, Promise<Unit> &&promise); void delete_dialog_filter(DialogFilterId dialog_filter_id, vector<DialogId> leave_dialog_ids,
Promise<Unit> &&promise);
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position, void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Promise<Unit> &&promise); Promise<Unit> &&promise);
@ -166,7 +167,7 @@ class DialogFilterManager final : public Actor {
void edit_dialog_filter(unique_ptr<DialogFilter> new_dialog_filter, const char *source); void edit_dialog_filter(unique_ptr<DialogFilter> new_dialog_filter, const char *source);
int32 delete_dialog_filter(DialogFilterId dialog_filter_id, const char *source); int32 do_delete_dialog_filter(DialogFilterId dialog_filter_id, const char *source);
const DialogFilter *get_server_dialog_filter(DialogFilterId dialog_filter_id) const; const DialogFilter *get_server_dialog_filter(DialogFilterId dialog_filter_id) const;

View File

@ -6141,7 +6141,8 @@ void Td::on_request(uint64 id, td_api::editChatFilter &request) {
void Td::on_request(uint64 id, const td_api::deleteChatFilter &request) { void Td::on_request(uint64 id, const td_api::deleteChatFilter &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
dialog_filter_manager_->delete_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(promise)); dialog_filter_manager_->delete_dialog_filter(DialogFilterId(request.chat_filter_id_),
DialogId::get_dialog_ids(request.leave_chat_ids_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::reorderChatFilters &request) { void Td::on_request(uint64 id, const td_api::reorderChatFilters &request) {

View File

@ -4578,8 +4578,9 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::editChatFilter>(chat_filter_id, as_chat_filter(filter, op == "ecfs"))); send_request(td_api::make_object<td_api::editChatFilter>(chat_filter_id, as_chat_filter(filter, op == "ecfs")));
} else if (op == "dcf") { } else if (op == "dcf") {
ChatFilterId chat_filter_id; ChatFilterId chat_filter_id;
get_args(args, chat_filter_id); string chat_ids;
send_request(td_api::make_object<td_api::deleteChatFilter>(chat_filter_id)); 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 == "rcf") { } else if (op == "rcf") {
int32 main_chat_list_position; int32 main_chat_list_position;
string chat_filter_ids; string chat_filter_ids;