Add td_api::deleteChatFilter.

GitOrigin-RevId: ceb3700d72271c6b570d258f6cf5e46f50d80b07
This commit is contained in:
levlam 2020-05-19 01:06:24 +03:00
parent 49ccb05176
commit d2b53fc023
7 changed files with 54 additions and 0 deletions

View File

@ -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

Binary file not shown.

View File

@ -15053,6 +15053,7 @@ Result<unique_ptr<MessagesManager::DialogFilter>> MessagesManager::create_dialog
}
void MessagesManager::create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter, Promise<Unit> &&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<td_api::chatFilter
void MessagesManager::edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
Promise<Unit> &&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<DialogFilter> dialog_fi
promise.set_value(Unit());
}
void MessagesManager::delete_dialog_filter(DialogFilterId dialog_filter_id, Promise<Unit> &&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<Unit> 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<UpdateDialogFilterQuery>(std::move(query_promise))->send(dialog_filter_id, nullptr);
}
void MessagesManager::on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result, Promise<Unit> &&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");

View File

@ -556,6 +556,8 @@ class MessagesManager : public Actor {
void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
Promise<Unit> &&promise);
void delete_dialog_filter(DialogFilterId dialog_filter_id, Promise<Unit> &&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<DialogFilter> dialog_filter, Status result, Promise<Unit> &&promise);
void on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result, Promise<Unit> &&promise);
DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id);
const DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id) const;

View File

@ -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();

View File

@ -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);

View File

@ -3515,6 +3515,8 @@ class CliClient final : public Actor {
std::tie(chat_filter_id, filter) = split(args);
send_request(
td_api::make_object<td_api::editChatFilter>(as_chat_filter_id(chat_filter_id), as_chat_filter(filter)));
} else if (op == "dcf") {
send_request(td_api::make_object<td_api::deleteChatFilter>(as_chat_filter_id(args)));
} else if (op == "sct") {
string chat_id;
string title;