diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d0eb6f500..2ec5d9705 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3715,6 +3715,9 @@ createChatFilter filter:chatFilter = Ok; //@description Edits existing chat filter @chat_filter_id Chat filter identifier @filter The edited chat filter editChatFilter chat_filter_id:int32 filter:chatFilter = Ok; +//@description Deletes existing chat filter @chat_filter_id Chat filter identifier +deleteChatFilter chat_filter_id:int32 = Ok; + //@description Changes the chat title. Supported only for basic groups, supergroups and channels. Requires can_change_info rights. The title will not be changed until the request to the server has been completed //@chat_id Chat identifier @title New title of the chat; 1-128 characters diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 298cea95d..98b3a5604 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 49d59dad8..f80eaacd1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -15053,6 +15053,7 @@ Result> MessagesManager::create_dialog } void MessagesManager::create_dialog_filter(td_api::object_ptr filter, Promise &&promise) { + CHECK(!td_->auth_manager_->is_bot()); if (dialog_filters_.size() >= MAX_DIALOG_FILTERS) { return promise.set_error(Status::Error(400, "Maximum number of chat folders exceeded")); } @@ -15086,6 +15087,7 @@ void MessagesManager::create_dialog_filter(td_api::object_ptr filter, Promise &&promise) { + CHECK(!td_->auth_manager_->is_bot()); auto old_dialog_filter = get_dialog_filter(dialog_filter_id); if (old_dialog_filter == nullptr) { return promise.set_error(Status::Error(400, "Chat filter not found")); @@ -15139,6 +15141,41 @@ void MessagesManager::on_update_dialog_filter(unique_ptr dialog_fi promise.set_value(Unit()); } +void MessagesManager::delete_dialog_filter(DialogFilterId dialog_filter_id, Promise &&promise) { + CHECK(!td_->auth_manager_->is_bot()); + auto dialog_filter = get_dialog_filter(dialog_filter_id); + if (dialog_filter == nullptr) { + return promise.set_value(Unit()); + } + + // TODO logevent + // TODO delete dialog filter locally + // TODO SequenceDispatcher + auto query_promise = PromiseCreator::lambda( + [actor_id = actor_id(this), dialog_filter_id, promise = std::move(promise)](Result result) mutable { + send_closure(actor_id, &MessagesManager::on_delete_dialog_filter, dialog_filter_id, + result.is_error() ? result.move_as_error() : Status::OK(), std::move(promise)); + }); + td_->create_handler(std::move(query_promise))->send(dialog_filter_id, nullptr); +} + +void MessagesManager::on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result, Promise &&promise) { + if (result.is_error()) { + return promise.set_error(result.move_as_error()); + } + + for (auto it = dialog_filters_.begin(); it != dialog_filters_.end(); ++it) { + if ((*it)->dialog_filter_id == dialog_filter_id) { + // TODO delete chat list + dialog_filters_.erase(it); + send_update_chat_filters(false); + break; + } + } + + promise.set_value(Unit()); +} + Status MessagesManager::delete_dialog_reply_markup(DialogId dialog_id, MessageId message_id) { if (td_->auth_manager_->is_bot()) { return Status::Error(6, "Bots can't delete chat reply markup"); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 25dd45c5e..0ec747c74 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -556,6 +556,8 @@ class MessagesManager : public Actor { void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr filter, Promise &&promise); + void delete_dialog_filter(DialogFilterId dialog_filter_id, Promise &&promise); + Status delete_dialog_reply_markup(DialogId dialog_id, MessageId message_id) TD_WARN_UNUSED_RESULT; Status set_dialog_draft_message(DialogId dialog_id, @@ -2212,6 +2214,8 @@ class MessagesManager : public Actor { void on_update_dialog_filter(unique_ptr dialog_filter, Status result, Promise &&promise); + void on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result, Promise &&promise); + DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id); const DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id) const; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index c2ac67d6d..7aa255ae1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5900,6 +5900,12 @@ void Td::on_request(uint64 id, td_api::editChatFilter &request) { std::move(promise)); } +void Td::on_request(uint64 id, const td_api::deleteChatFilter &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + messages_manager_->delete_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setChatTitle &request) { CLEAN_INPUT_STRING(request.title_); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 4d9b5d9fd..963876dc7 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -681,6 +681,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::editChatFilter &request); + void on_request(uint64 id, const td_api::deleteChatFilter &request); + void on_request(uint64 id, td_api::setChatTitle &request); void on_request(uint64 id, const td_api::setChatPhoto &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 6ff674485..041b38ebc 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3515,6 +3515,8 @@ class CliClient final : public Actor { std::tie(chat_filter_id, filter) = split(args); send_request( td_api::make_object(as_chat_filter_id(chat_filter_id), as_chat_filter(filter))); + } else if (op == "dcf") { + send_request(td_api::make_object(as_chat_filter_id(args))); } else if (op == "sct") { string chat_id; string title;