From 680bad4a72c254030b96e7d1f05c708fdc48a554 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 24 Dec 2021 20:42:49 +0300 Subject: [PATCH] Return default icon name if there is no chosen name in chatFilterInfo. --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/DialogFilter.cpp | 40 +++++++++++++++++++++++++++++++++++- td/telegram/DialogFilter.h | 2 ++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b6379df4c..4c0a864cf 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -890,7 +890,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int53 = ChatType; //@description Represents a filter of user chats //@title The title of the filter; 1-12 characters without line feeds -//@icon_name The 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". +//@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". //-If empty, use getChatFilterDefaultIconName to get default icon name for the filter //@pinned_chat_ids The chat identifiers of pinned chats in the filtered chat list //@included_chat_ids The chat identifiers of always included chats in the filtered chat list @@ -908,7 +908,7 @@ chatFilter title:string icon_name:string pinned_chat_ids:vector included_ //@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 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" +//@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" chatFilterInfo id:int32 title:string icon_name:string = ChatFilterInfo; //@description Describes a recommended chat filter @filter The chat filter @param_description Chat filter description diff --git a/td/telegram/DialogFilter.cpp b/td/telegram/DialogFilter.cpp index d5f0b21cd..6b9f13031 100644 --- a/td/telegram/DialogFilter.cpp +++ b/td/telegram/DialogFilter.cpp @@ -131,6 +131,44 @@ string DialogFilter::get_icon_name() const { return string(); } +string DialogFilter::get_chosen_or_default_icon_name() const { + auto icon_name = get_icon_name(); + if (!icon_name.empty()) { + return icon_name; + } + + if (!pinned_dialog_ids.empty() || !included_dialog_ids.empty() || !excluded_dialog_ids.empty()) { + return "Custom"; + } + + if (include_contacts || include_non_contacts) { + if (!include_bots && !include_groups && !include_channels) { + return "Private"; + } + } else { + if (!include_bots && !include_channels) { + if (!include_groups) { + // just in case + return "Custom"; + } + return "Groups"; + } + if (!include_bots && !include_groups) { + return "Channels"; + } + if (!include_groups && !include_channels) { + return "Bots"; + } + } + if (exclude_read && !exclude_muted) { + return "Unread"; + } + if (exclude_muted && !exclude_read) { + return "Unmuted"; + } + return "Custom"; +} + 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_; @@ -206,7 +244,7 @@ telegram_api::object_ptr DialogFilter::get_input_dia } td_api::object_ptr DialogFilter::get_chat_filter_info_object() const { - return td_api::make_object(dialog_filter_id.get(), title, get_icon_name()); + return td_api::make_object(dialog_filter_id.get(), title, get_chosen_or_default_icon_name()); } // merges changes from old_server_filter to new_server_filter in old_filter diff --git a/td/telegram/DialogFilter.h b/td/telegram/DialogFilter.h index d661d7471..a74d841b8 100644 --- a/td/telegram/DialogFilter.h +++ b/td/telegram/DialogFilter.h @@ -79,6 +79,8 @@ class DialogFilter { static std::unordered_map icon_name_to_emoji_; static void init_icon_names(); + + string get_chosen_or_default_icon_name() const; }; inline bool operator==(const DialogFilter &lhs, const DialogFilter &rhs) {