Add class chatFilterIcon.

This commit is contained in:
levlam 2023-03-31 13:34:47 +03:00
parent 725c7ba5d1
commit 715f681651
4 changed files with 33 additions and 22 deletions

View File

@ -1290,11 +1290,13 @@ chatTypeSupergroup supergroup_id:int53 is_channel:Bool = ChatType;
chatTypeSecret secret_chat_id:int32 user_id:int53 = ChatType;
//@description Represents an icon for a chat filter @name The chosen icon name for short filter representation; 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"
chatFilterIcon name:string = ChatFilterIcon;
//@description Represents a filter of user chats
//@title The title of the filter; 1-12 characters without line feeds
//@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
//@icon The chosen icon for the chat filter; may be null. If null, 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
@ -1307,14 +1309,13 @@ 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 is_shareable:Bool pinned_chat_ids:vector<int53> included_chat_ids:vector<int53> excluded_chat_ids:vector<int53> 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:chatFilterIcon is_shareable:Bool pinned_chat_ids:vector<int53> included_chat_ids:vector<int53> excluded_chat_ids:vector<int53> 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
//@title The title of the filter; 1-12 characters without line feeds
//@icon_name The chosen or default icon name for short filter representation. 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"
chatFilterInfo id:int32 title:string icon_name:string = ChatFilterInfo;
//@icon The chosen or default icon for the chat filter
chatFilterInfo id:int32 title:string icon:chatFilterIcon = ChatFilterInfo;
//@description Contains a chat filter invite link
//@invite_link The chat filter invite link
@ -6797,7 +6798,7 @@ reorderChatFilters chat_filter_ids:vector<int32> main_chat_list_position:int32 =
getRecommendedChatFilters = RecommendedChatFilters;
//@description Returns default icon name for a filter. Can be called synchronously @filter Chat filter
getChatFilterDefaultIconName filter:chatFilter = Text;
getChatFilterDefaultIconName filter:chatFilter = ChatFilterIcon;
//@description Creates a new invite link for a chat filter. A link can be created for a filter if it has only pinned and included chats
//@chat_filter_id Chat filter identifier

View File

@ -96,7 +96,11 @@ Result<unique_ptr<DialogFilter>> DialogFilter::create_dialog_filter(Td *td, Dial
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_)) {
string icon_name;
if (filter->icon_ != nullptr) {
icon_name = std::move(filter->icon_->name_);
}
if (!clean_input_string(filter->title_) || !clean_input_string(icon_name)) {
return Status::Error(400, "Strings must be encoded in UTF-8");
}
@ -123,8 +127,8 @@ Result<unique_ptr<DialogFilter>> DialogFilter::create_dialog_filter(Td *td, Dial
if (dialog_filter->title_.empty()) {
return Status::Error(400, "Title must be non-empty");
}
dialog_filter->emoji_ = get_emoji_by_icon_name(filter->icon_name_);
if (dialog_filter->emoji_.empty() && !filter->icon_name_.empty()) {
dialog_filter->emoji_ = get_emoji_by_icon_name(icon_name);
if (dialog_filter->emoji_.empty() && !icon_name.empty()) {
return Status::Error(400, "Invalid icon name specified");
}
dialog_filter->exclude_muted_ = filter->exclude_muted_;
@ -353,8 +357,9 @@ string DialogFilter::get_chosen_or_default_icon_name() const {
}
string DialogFilter::get_default_icon_name(const td_api::chatFilter *filter) {
if (!filter->icon_name_.empty() && !get_emoji_by_icon_name(filter->icon_name_).empty()) {
return filter->icon_name_;
if (filter->icon_ != nullptr && !filter->icon_->name_.empty() &&
!get_emoji_by_icon_name(filter->icon_->name_).empty()) {
return filter->icon_->name_;
}
if (!filter->pinned_chat_ids_.empty() || !filter->included_chat_ids_.empty() || !filter->excluded_chat_ids_.empty()) {
@ -449,15 +454,20 @@ td_api::object_ptr<td_api::chatFilter> DialogFilter::get_chat_filter_object(
return chat_ids;
};
td_api::object_ptr<td_api::chatFilterIcon> icon;
auto icon_name = get_icon_name();
if (!icon_name.empty()) {
icon = td_api::make_object<td_api::chatFilterIcon>(icon_name);
}
return td_api::make_object<td_api::chatFilter>(
title_, get_icon_name(), is_shareable_, get_chat_ids(pinned_dialog_ids_), get_chat_ids(included_dialog_ids_),
title_, std::move(icon), 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_);
}
td_api::object_ptr<td_api::chatFilterInfo> DialogFilter::get_chat_filter_info_object() const {
return td_api::make_object<td_api::chatFilterInfo>(dialog_filter_id_.get(), title_,
get_chosen_or_default_icon_name());
return td_api::make_object<td_api::chatFilterInfo>(
dialog_filter_id_.get(), title_, td_api::make_object<td_api::chatFilterIcon>(get_chosen_or_default_icon_name()));
}
void DialogFilter::for_each_dialog(std::function<void(const InputDialogId &)> callback) const {

View File

@ -8767,10 +8767,10 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getChatFi
if (!check_utf8(request.filter_->title_)) {
return make_error(400, "Chat filter title must be encoded in UTF-8");
}
if (!check_utf8(request.filter_->icon_name_)) {
if (request.filter_->icon_ != nullptr && !check_utf8(request.filter_->icon_->name_)) {
return make_error(400, "Chat filter icon name must be encoded in UTF-8");
}
return td_api::make_object<td_api::text>(DialogFilter::get_default_icon_name(request.filter_.get()));
return td_api::make_object<td_api::chatFilterIcon>(DialogFilter::get_default_icon_name(request.filter_.get()));
}
td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::getJsonValue &request) {

View File

@ -1533,10 +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<td_api::chatFilter>(title, icon_name, is_shareable, 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<td_api::chatFilter>(
title, td_api::make_object<td_api::chatFilterIcon>(icon_name), is_shareable, 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<td_api::chatAdministratorRights> as_chat_administrator_rights(