From cbf77e37865bbfa5baa711cf68d0edb67a738eb0 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 5 Jun 2020 03:43:13 +0300 Subject: [PATCH] Add synchronous td_api::getChatFilterDefaultIconName. GitOrigin-RevId: 15072bd5fffdd55e9879e0e5076a567bfe56f432 --- td/generate/scheme/td_api.tl | 10 +++++++--- td/generate/scheme/td_api.tlo | Bin 174476 -> 174580 bytes td/telegram/DialogFilter.cpp | 25 ++++++++++++++++--------- td/telegram/DialogFilter.h | 3 +++ td/telegram/MessagesManager.cpp | 13 ------------- td/telegram/Td.cpp | 20 ++++++++++++++++++++ td/telegram/Td.h | 3 +++ td/telegram/cli.cpp | 4 +++- 8 files changed, 52 insertions(+), 26 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f2d4bcd4e..5f557910c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -676,7 +676,8 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = 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. 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". Pass an empty string for autodetection +//@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". +//-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 //@excluded_chat_ids The chat identifiers of always excluded chats in the filtered chat list @@ -3750,7 +3751,7 @@ addChatToList chat_id:int53 chat_list:ChatList = Ok; //@description Returns information about a chat filter by its identifier @chat_filter_id Chat filter identifier getChatFilter chat_filter_id:int32 = ChatFilter; -//@description Creates new chat filter @filter The chat filter +//@description Creates new chat filter @filter Chat filter createChatFilter filter:chatFilter = Ok; //@description Edits existing chat filter @chat_filter_id Chat filter identifier @filter The edited chat filter @@ -3762,9 +3763,12 @@ deleteChatFilter chat_filter_id:int32 = Ok; //@description Changes the order of chat filters @chat_filter_ids Identifiers of chat filters in the new correct order reorderChatFilters chat_filter_ids:vector = Ok; -//@description Returns recommended chat filters for the user +//@description Returns recommended chat filters for the current user getRecommendedChatFilters = RecommendedChatFilters; +//@description Returns default icon name for a filter. This is an offline method. Can be called before authorization. Can be called synchronously @filter Chat filter +getChatFilterDefaultIconName filter:chatFilter = Text; + //@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 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 642bf01ad28a5577d16e2d43ebeb936dad0077c7..d9694a3f6eb960112f4c383ac9fc9f0ab78e3ef7 100644 GIT binary patch delta 86 zcmV-c0IC0s(+c#{3V^f$Ebsw*w=M7ilR7Op)+4YSXJvFlXkm0lX>4?5aztfjVRdYD sNn>wrPGN0j0001(Sau@W#u7{cm$6U+7nkq|0u+}J1p*Maz$yaFe&H=3Q2+n{ delta 25 hcmexznXBhASHl)YoezxF+jT!MPPW>vq0Mxr4gi`23jhEB diff --git a/td/telegram/DialogFilter.cpp b/td/telegram/DialogFilter.cpp index 2d0a516d8..151e93e3a 100644 --- a/td/telegram/DialogFilter.cpp +++ b/td/telegram/DialogFilter.cpp @@ -126,34 +126,41 @@ string DialogFilter::get_icon_name() const { if (it != emoji_to_icon_name_.end()) { return it->second; } + return string(); +} - if (!pinned_dialog_ids.empty() || !included_dialog_ids.empty() || !excluded_dialog_ids.empty()) { +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->pinned_chat_ids_.empty() || !filter->included_chat_ids_.empty() || !filter->excluded_chat_ids_.empty()) { return "Custom"; } - if (include_contacts || include_non_contacts) { - if (!include_bots && !include_groups && !include_channels) { + if (filter->include_contacts_ || filter->include_non_contacts_) { + if (!filter->include_bots_ && !filter->include_groups_ && !filter->include_channels_) { return "Private"; } } else { - if (!include_bots && !include_channels) { - if (!include_groups) { + if (!filter->include_bots_ && !filter->include_channels_) { + if (!filter->include_groups_) { // just in case return "Custom"; } return "Groups"; } - if (!include_bots && !include_groups) { + if (!filter->include_bots_ && !filter->include_groups_) { return "Channels"; } - if (!include_groups && !include_channels) { + if (!filter->include_groups_ && !filter->include_channels_) { return "Bots"; } } - if (exclude_read && !exclude_muted) { + if (filter->exclude_read_ && !filter->exclude_muted_) { return "Unread"; } - if (exclude_muted && !exclude_read) { + if (filter->exclude_muted_ && !filter->exclude_read_) { return "Unmuted"; } return "Custom"; diff --git a/td/telegram/DialogFilter.h b/td/telegram/DialogFilter.h index e1601e7e3..a43f8bc19 100644 --- a/td/telegram/DialogFilter.h +++ b/td/telegram/DialogFilter.h @@ -8,6 +8,7 @@ #include "td/telegram/DialogFilterId.h" #include "td/telegram/InputDialogId.h" +#include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/utils/common.h" @@ -55,6 +56,8 @@ class DialogFilter { string get_icon_name() const; + static string get_default_icon_name(const td_api::chatFilter *filter); + telegram_api::object_ptr get_input_dialog_filter() const; // merges changes from old_server_filter to new_server_filter in old_filter diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c87183221..7ded3bc97 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -15464,25 +15464,12 @@ void MessagesManager::edit_dialog_filter(DialogFilterId dialog_filter_id, td_api return promise.set_error(Status::Error(400, "Chat filter not found")); } - auto old_icon_name = old_dialog_filter->get_icon_name(); - auto new_icon_name = filter->icon_name_; 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_icon_name.empty()) { - // keep old emoji - new_dialog_filter->emoji = old_dialog_filter->emoji; - } else if (new_icon_name == old_icon_name) { - // keep old emoji, but only if with it icon_name is exactly as specified - auto new_emoji = std::move(new_dialog_filter->emoji); - new_dialog_filter->emoji = old_dialog_filter->emoji; - if (new_dialog_filter->get_icon_name() != new_icon_name) { - new_dialog_filter->emoji = std::move(new_emoji); - } - } if (*new_dialog_filter == *old_dialog_filter) { return promise.set_value(Unit()); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0e30944bd..8771099d4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -24,6 +24,7 @@ #include "td/telegram/ContactsManager.h" #include "td/telegram/DeviceTokenManager.h" #include "td/telegram/DialogAdministrator.h" +#include "td/telegram/DialogFilter.h" #include "td/telegram/DialogId.h" #include "td/telegram/DialogListId.h" #include "td/telegram/DialogLocation.h" @@ -3229,6 +3230,7 @@ bool Td::is_synchronous_request(int32 id) { case td_api::getFileExtension::ID: case td_api::cleanFileName::ID: case td_api::getLanguagePackString::ID: + case td_api::getChatFilterDefaultIconName::ID: case td_api::getJsonValue::ID: case td_api::getJsonString::ID: case td_api::getPushReceiverId::ID: @@ -3452,6 +3454,7 @@ td_api::object_ptr Td::static_request(td_api::object_ptr Td::do_static_request(const td_api::getPushRe return td_api::make_object(r_push_receiver_id.ok()); } +td_api::object_ptr Td::do_static_request(const td_api::getChatFilterDefaultIconName &request) { + if (request.filter_ == nullptr) { + return make_error(400, "Chat filter must be non-empty"); + } + 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_)) { + return make_error(400, "Chat filter icon name must be encoded in UTF-8"); + } + return td_api::make_object(DialogFilter::get_default_icon_name(request.filter_.get())); +} + td_api::object_ptr Td::do_static_request(td_api::getJsonValue &request) { if (!check_utf8(request.json_)) { return make_error(400, "JSON has invalid encoding"); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 1d158d9c3..8be781b94 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1087,6 +1087,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::getPushReceiverId &request); + void on_request(uint64 id, const td_api::getChatFilterDefaultIconName &request); + void on_request(uint64 id, const td_api::getJsonValue &request); void on_request(uint64 id, const td_api::getJsonString &request); @@ -1135,6 +1137,7 @@ class Td final : public NetQueryCallback { static td_api::object_ptr do_static_request(const td_api::cleanFileName &request); static td_api::object_ptr do_static_request(const td_api::getLanguagePackString &request); static td_api::object_ptr do_static_request(const td_api::getPushReceiverId &request); + static td_api::object_ptr do_static_request(const td_api::getChatFilterDefaultIconName &request); static td_api::object_ptr do_static_request(td_api::getJsonValue &request); static td_api::object_ptr do_static_request(const td_api::getJsonString &request); static td_api::object_ptr do_static_request(td_api::setLogStream &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7e94a7d0d..286e1d7cc 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1764,9 +1764,9 @@ class CliClient final : public Actor { } if (op == "gc" || op == "GetChats" || op == "gca" || begins_with(op, "gc-")) { + string limit; string offset_order_string; string offset_chat_id; - string limit; std::tie(limit, args) = split(args); std::tie(offset_order_string, offset_chat_id) = split(args); @@ -3540,6 +3540,8 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_chat_filter_ids(args))); } else if (op == "grcf") { send_request(td_api::make_object()); + } else if (op == "gcfdin") { + execute(td_api::make_object(as_chat_filter(args))); } else if (op == "sct") { string chat_id; string title;