Move all chatFilter checks to DialogFilter::create_dialog_filter.

This commit is contained in:
levlam 2023-03-27 19:08:25 +03:00
parent 19ac20adc9
commit 03819d0322
2 changed files with 6 additions and 11 deletions

View File

@ -93,7 +93,12 @@ unique_ptr<DialogFilter> DialogFilter::get_dialog_filter(
Result<unique_ptr<DialogFilter>> DialogFilter::create_dialog_filter(Td *td, DialogFilterId dialog_filter_id,
td_api::object_ptr<td_api::chatFilter> filter) {
CHECK(filter != nullptr);
if (filter == nullptr) {
return Status::Error(400, "Chat filter must be non-empty");
}
if (!clean_input_string(filter->title_) || !clean_input_string(filter->icon_name_)) {
return Status::Error(400, "Strings must be encoded in UTF-8");
}
auto dialog_filter = make_unique<DialogFilter>();
dialog_filter->dialog_filter_id_ = dialog_filter_id;

View File

@ -6127,22 +6127,12 @@ void Td::on_request(uint64 id, const td_api::getRecommendedChatFilters &request)
void Td::on_request(uint64 id, td_api::createChatFilter &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_->icon_name_);
CREATE_REQUEST_PROMISE();
dialog_filter_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_->icon_name_);
CREATE_REQUEST_PROMISE();
dialog_filter_manager_->edit_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(request.filter_),
std::move(promise));