From 761bc9c992b995d17fb9beb3702957e8fbd10387 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Mar 2023 18:23:26 +0300 Subject: [PATCH] Add chatFilter.is_shareable. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/DialogFilter.cpp | 8 ++++---- td/telegram/DialogFilterManager.cpp | 14 ++++++++++---- td/telegram/cli.cpp | 7 ++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b92459d5a..e9f5ca63d 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1295,6 +1295,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int53 = ChatType; //@icon_name The chosen icon name for short filter representation. If non-empty, must be one of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", //-"Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work", "Airplane", "Book", "Light", "Like", "Money", "Note", "Palette". //-If empty, use getChatFilterDefaultIconName to get default icon name for the filter +//@is_shareable True if at least one link has been created for the filter //@pinned_chat_ids The chat identifiers of pinned chats in the filtered chat list. There can be up to getOption("chat_filter_chosen_chat_count_max") pinned and always included non-secret chats and the same number of secret chats, but the limit can be increased with Telegram Premium //@included_chat_ids The chat identifiers of always included chats in the filtered chat list. There can be up to getOption("chat_filter_chosen_chat_count_max") pinned and always included non-secret chats and the same number of secret chats, but the limit can be increased with Telegram Premium //@excluded_chat_ids The chat identifiers of always excluded chats in the filtered chat list. There can be up to getOption("chat_filter_chosen_chat_count_max") always excluded non-secret chats and the same number of secret chats, but the limit can be increased with Telegram Premium @@ -1306,7 +1307,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int53 = ChatType; //@include_bots True, if bots need to be included //@include_groups True, if basic groups and supergroups need to be included //@include_channels True, if channels need to be included -chatFilter title:string icon_name:string pinned_chat_ids:vector included_chat_ids:vector excluded_chat_ids:vector exclude_muted:Bool exclude_read:Bool exclude_archived:Bool include_contacts:Bool include_non_contacts:Bool include_bots:Bool include_groups:Bool include_channels:Bool = ChatFilter; +chatFilter title:string icon_name:string is_shareable:Bool pinned_chat_ids:vector included_chat_ids:vector excluded_chat_ids:vector exclude_muted:Bool exclude_read:Bool exclude_archived:Bool include_contacts:Bool include_non_contacts:Bool include_bots:Bool include_groups:Bool include_channels:Bool = ChatFilter; //@description Contains basic information about a chat filter //@id Unique chat filter identifier diff --git a/td/telegram/DialogFilter.cpp b/td/telegram/DialogFilter.cpp index 1cc76bfd7..452fcd38d 100644 --- a/td/telegram/DialogFilter.cpp +++ b/td/telegram/DialogFilter.cpp @@ -135,7 +135,7 @@ Result> DialogFilter::create_dialog_filter(Td *td, Dial dialog_filter->include_bots_ = filter->include_bots_; dialog_filter->include_groups_ = filter->include_groups_; dialog_filter->include_channels_ = filter->include_channels_; - dialog_filter->is_shareable_ = false; + dialog_filter->is_shareable_ = filter->is_shareable_; TRY_STATUS(dialog_filter->check_limits()); dialog_filter->sort_input_dialog_ids(td, "create_dialog_filter"); @@ -280,11 +280,11 @@ Status DialogFilter::check_limits() const { } if (is_shareable_) { if (!excluded_dialog_ids_.empty()) { - return Status::Error(400, "The folder can't have excluded chats"); + return Status::Error(400, "Shareable folders can't have excluded chats"); } if (include_contacts_ || include_non_contacts_ || include_bots_ || include_groups_ || include_channels_ || exclude_archived_ || exclude_read_ || exclude_muted_) { - return Status::Error(400, "The folder can't have chat filters"); + return Status::Error(400, "Shareable folders can't have chat filters"); } } @@ -450,7 +450,7 @@ td_api::object_ptr DialogFilter::get_chat_filter_object( }; return td_api::make_object( - title_, get_icon_name(), get_chat_ids(pinned_dialog_ids_), get_chat_ids(included_dialog_ids_), + title_, get_icon_name(), is_shareable_, get_chat_ids(pinned_dialog_ids_), get_chat_ids(included_dialog_ids_), get_chat_ids(excluded_dialog_ids_), exclude_muted_, exclude_read_, exclude_archived_, include_contacts_, include_non_contacts_, include_bots_, include_groups_, include_channels_); } diff --git a/td/telegram/DialogFilterManager.cpp b/td/telegram/DialogFilterManager.cpp index 5910dc26a..d50a73a34 100644 --- a/td/telegram/DialogFilterManager.cpp +++ b/td/telegram/DialogFilterManager.cpp @@ -1195,6 +1195,9 @@ void DialogFilterManager::create_dialog_filter(td_api::object_ptris_shareable()) { + return promise.set_error(Status::Error(400, "Can't create shareable folder")); + } auto chat_filter_info = dialog_filter->get_chat_filter_info_object(); bool at_beginning = is_recommended_dialog_filter(dialog_filter.get()); @@ -1215,12 +1218,15 @@ void DialogFilterManager::edit_dialog_filter(DialogFilterId dialog_filter_id, 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")); + return promise.set_error(Status::Error(400, "Chat folder not found")); } CHECK(is_update_chat_filters_sent_); TRY_RESULT_PROMISE(promise, new_dialog_filter, DialogFilter::create_dialog_filter(td_, dialog_filter_id, std::move(filter))); + if (new_dialog_filter->is_shareable() != old_dialog_filter->is_shareable()) { + return promise.set_error(Status::Error(400, "Can't convert a shareable folder to a non-shareable")); + } auto chat_filter_info = new_dialog_filter->get_chat_filter_info_object(); if (*new_dialog_filter == *old_dialog_filter) { @@ -1347,7 +1353,7 @@ void DialogFilterManager::reorder_dialog_filters(vector dialog_f for (auto dialog_filter_id : dialog_filter_ids) { auto dialog_filter = get_dialog_filter(dialog_filter_id); if (dialog_filter == nullptr) { - return promise.set_error(Status::Error(400, "Chat filter not found")); + return promise.set_error(Status::Error(400, "Chat folder not found")); } } std::unordered_set new_dialog_filter_ids_set(dialog_filter_ids.begin(), @@ -1490,7 +1496,7 @@ void DialogFilterManager::create_dialog_filter_invite_link( Promise> promise) { auto dialog_filter = get_dialog_filter(dialog_filter_id); if (dialog_filter == nullptr) { - return promise.set_error(Status::Error(400, "Chat filter not found")); + return promise.set_error(Status::Error(400, "Chat folder not found")); } vector> input_peers; input_peers.reserve(dialog_ids.size()); @@ -1512,7 +1518,7 @@ void DialogFilterManager::get_dialog_filter_invite_links( DialogFilterId dialog_filter_id, Promise> promise) { auto dialog_filter = get_dialog_filter(dialog_filter_id); if (dialog_filter == nullptr) { - return promise.set_error(Status::Error(400, "Chat filter not found")); + return promise.set_error(Status::Error(400, "Chat folder not found")); } if (!dialog_filter->is_shareable()) { return promise.set_value(td_api::make_object()); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 2f1cd23e5..c7ac0f2d5 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1533,9 +1533,10 @@ class CliClient final : public Actor { string included_chat_ids; string excluded_chat_ids; get_args(filter, title, icon_name, pinned_chat_ids, included_chat_ids, excluded_chat_ids); - return td_api::make_object( - title, icon_name, as_chat_ids(pinned_chat_ids), as_chat_ids(included_chat_ids), as_chat_ids(excluded_chat_ids), - rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool()); + return td_api::make_object(title, icon_name, false, as_chat_ids(pinned_chat_ids), + as_chat_ids(included_chat_ids), as_chat_ids(excluded_chat_ids), + rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), + rand_bool(), rand_bool(), rand_bool()); } static td_api::object_ptr as_chat_administrator_rights(