Add td_api::editChatFilter.

GitOrigin-RevId: 51af78e8079dbb89421cdfbd81d4e37b10d95f03
This commit is contained in:
levlam 2020-05-19 00:47:34 +03:00
parent d1bb70820a
commit 49ccb05176
7 changed files with 92 additions and 14 deletions

View File

@ -3712,6 +3712,9 @@ getChatFilter chat_filter_id:int32 = ChatFilter;
//@description Creates new chat filter @filter The chat filter
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 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

@ -4872,9 +4872,17 @@ struct MessagesManager::DialogFilter {
lhs.include_channels == rhs.include_channels;
}
friend bool operator!=(const DialogFilter &lhs, const DialogFilter &rhs) {
return !(lhs == rhs);
}
friend bool operator==(const unique_ptr<DialogFilter> &lhs, const unique_ptr<DialogFilter> &rhs) {
return *lhs == *rhs;
}
friend bool operator!=(const unique_ptr<DialogFilter> &lhs, const unique_ptr<DialogFilter> &rhs) {
return !(lhs == rhs);
}
};
template <class StorerT>
@ -14974,7 +14982,7 @@ td_api::object_ptr<td_api::messageLinkInfo> MessagesManager::get_message_link_in
}
Result<unique_ptr<MessagesManager::DialogFilter>> MessagesManager::create_dialog_filter(
td_api::object_ptr<td_api::chatFilter> filter) {
DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter) {
CHECK(filter != nullptr);
for (auto chat_ids : {&filter->pinned_chat_ids_, &filter->excluded_chat_ids_, &filter->included_chat_ids_}) {
for (auto chat_id : *chat_ids) {
@ -14995,13 +15003,6 @@ Result<unique_ptr<MessagesManager::DialogFilter>> MessagesManager::create_dialog
}
}
DialogFilterId dialog_filter_id;
do {
auto min_id = static_cast<int>(DialogFilterId::min().get());
auto max_id = static_cast<int>(DialogFilterId::max().get());
dialog_filter_id = DialogFilterId(static_cast<int32>(Random::fast(min_id, max_id)));
} while (get_dialog_filter(dialog_filter_id) != nullptr);
auto dialog_filter = make_unique<DialogFilter>();
dialog_filter->dialog_filter_id = dialog_filter_id;
@ -15056,13 +15057,19 @@ void MessagesManager::create_dialog_filter(td_api::object_ptr<td_api::chatFilter
return promise.set_error(Status::Error(400, "Maximum number of chat folders exceeded"));
}
auto r_dialog_filter = create_dialog_filter(std::move(filter));
DialogFilterId dialog_filter_id;
do {
auto min_id = static_cast<int>(DialogFilterId::min().get());
auto max_id = static_cast<int>(DialogFilterId::max().get());
dialog_filter_id = DialogFilterId(static_cast<int32>(Random::fast(min_id, max_id)));
} while (get_dialog_filter(dialog_filter_id) != nullptr);
auto r_dialog_filter = create_dialog_filter(dialog_filter_id, std::move(filter));
if (r_dialog_filter.is_error()) {
return promise.set_error(r_dialog_filter.move_as_error());
}
auto dialog_filter = r_dialog_filter.move_as_ok();
CHECK(dialog_filter != nullptr);
auto dialog_filter_id = dialog_filter->dialog_filter_id;
auto input_dialog_filter = dialog_filter->get_input_dialog_filter();
// TODO logevent
@ -15070,20 +15077,63 @@ void MessagesManager::create_dialog_filter(td_api::object_ptr<td_api::chatFilter
// TODO SequenceDispatcher
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_filter = std::move(dialog_filter),
promise = std::move(promise)](Result<Unit> result) mutable {
send_closure(actor_id, &MessagesManager::on_create_dialog_filter, std::move(dialog_filter),
send_closure(actor_id, &MessagesManager::on_update_dialog_filter, std::move(dialog_filter),
result.is_error() ? result.move_as_error() : Status::OK(), std::move(promise));
});
td_->create_handler<UpdateDialogFilterQuery>(std::move(query_promise))
->send(dialog_filter_id, std::move(input_dialog_filter));
}
void MessagesManager::on_create_dialog_filter(unique_ptr<DialogFilter> dialog_filter, Status result,
void MessagesManager::edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
Promise<Unit> &&promise) {
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"));
}
auto r_dialog_filter = create_dialog_filter(dialog_filter_id, std::move(filter));
if (r_dialog_filter.is_error()) {
return promise.set_error(r_dialog_filter.move_as_error());
}
auto new_dialog_filter = r_dialog_filter.move_as_ok();
CHECK(new_dialog_filter != nullptr);
if (*new_dialog_filter == *old_dialog_filter) {
return promise.set_value(Unit());
}
auto input_dialog_filter = new_dialog_filter->get_input_dialog_filter();
// TODO logevent
// TODO edit dialog filter locally
// TODO SequenceDispatcher
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_filter = std::move(new_dialog_filter),
promise = std::move(promise)](Result<Unit> result) mutable {
send_closure(actor_id, &MessagesManager::on_update_dialog_filter, std::move(dialog_filter),
result.is_error() ? result.move_as_error() : Status::OK(), std::move(promise));
});
td_->create_handler<UpdateDialogFilterQuery>(std::move(query_promise))
->send(dialog_filter_id, std::move(input_dialog_filter));
}
void MessagesManager::on_update_dialog_filter(unique_ptr<DialogFilter> dialog_filter, Status result,
Promise<Unit> &&promise) {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
// TODO update all changed chat lists and their unread counts
for (auto &filter : dialog_filters_) {
if (filter->dialog_filter_id == dialog_filter->dialog_filter_id) {
if (*filter != *dialog_filter) {
filter = std::move(dialog_filter);
send_update_chat_filters(false);
}
promise.set_value(Unit());
return;
}
}
dialog_filters_.push_back(std::move(dialog_filter));
send_update_chat_filters(false);
promise.set_value(Unit());

View File

@ -553,6 +553,9 @@ class MessagesManager : public Actor {
void create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter, Promise<Unit> &&promise);
void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
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,
@ -2204,9 +2207,10 @@ class MessagesManager : public Actor {
void update_dialogs_hints(const Dialog *d);
void update_dialogs_hints_rating(const Dialog *d);
Result<unique_ptr<DialogFilter>> create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter);
Result<unique_ptr<DialogFilter>> create_dialog_filter(DialogFilterId dialog_filter_id,
td_api::object_ptr<td_api::chatFilter> filter);
void on_create_dialog_filter(unique_ptr<DialogFilter> dialog_filter, Status result, Promise<Unit> &&promise);
void on_update_dialog_filter(unique_ptr<DialogFilter> dialog_filter, 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

@ -5888,6 +5888,18 @@ void Td::on_request(uint64 id, td_api::createChatFilter &request) {
messages_manager_->create_dialog_filter(std::move(request.filter_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::editChatFilter &request) {
CHECK_IS_USER();
if (request.filter_ == nullptr) {
return send_error_raw(id, 400, "Chat filter must be non-empty");
}
CLEAN_INPUT_STRING(request.filter_->title_);
CLEAN_INPUT_STRING(request.filter_->emoji_);
CREATE_OK_REQUEST_PROMISE();
messages_manager_->edit_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(request.filter_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setChatTitle &request) {
CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE();

View File

@ -679,6 +679,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::createChatFilter &request);
void on_request(uint64 id, td_api::editChatFilter &request);
void on_request(uint64 id, td_api::setChatTitle &request);
void on_request(uint64 id, const td_api::setChatPhoto &request);

View File

@ -3508,6 +3508,13 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getChatFilter>(as_chat_filter_id(args)));
} else if (op == "ccf") {
send_request(td_api::make_object<td_api::createChatFilter>(as_chat_filter(args)));
} else if (op == "ecf") {
string chat_filter_id;
string filter;
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 == "sct") {
string chat_id;
string title;