Skip to content

Commit

Permalink
Add synchronous td_api::getChatFilterDefaultIconName.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 15072bd5fffdd55e9879e0e5076a567bfe56f432
  • Loading branch information
levlam committed Jun 5, 2020
1 parent 0740409 commit cbf77e3
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
10 changes: 7 additions & 3 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<int32> = 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
Expand Down
Binary file modified td/generate/scheme/td_api.tlo
Binary file not shown.
25 changes: 16 additions & 9 deletions td/telegram/DialogFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,41 @@ string DialogFilter::get_icon_name() const {
if (it != emoji_to_icon_name_.end()) {
return it->second;
}
return string();
}

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 (!pinned_dialog_ids.empty() || !included_dialog_ids.empty() || !excluded_dialog_ids.empty()) {
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";
Expand Down
3 changes: 3 additions & 0 deletions td/telegram/DialogFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<telegram_api::dialogFilter> get_input_dialog_filter() const;

// merges changes from old_server_filter to new_server_filter in old_filter
Expand Down
13 changes: 0 additions & 13 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 20 additions & 0 deletions td/telegram/Td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -3452,6 +3454,7 @@ td_api::object_ptr<td_api::Object> Td::static_request(td_api::object_ptr<td_api:
case td_api::getFileMimeType::ID:
case td_api::getFileExtension::ID:
case td_api::cleanFileName::ID:
case td_api::getChatFilterDefaultIconName::ID:
case td_api::getJsonValue::ID:
case td_api::getJsonString::ID:
case td_api::testReturnError::ID:
Expand Down Expand Up @@ -7735,6 +7738,10 @@ void Td::on_request(uint64 id, const td_api::getPushReceiverId &request) {
UNREACHABLE();
}

void Td::on_request(uint64 id, const td_api::getChatFilterDefaultIconName &request) {
UNREACHABLE();
}

void Td::on_request(uint64 id, const td_api::getJsonValue &request) {
UNREACHABLE();
}
Expand Down Expand Up @@ -7886,6 +7893,19 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getPushRe
return td_api::make_object<td_api::pushReceiverId>(r_push_receiver_id.ok());
}

td_api::object_ptr<td_api::Object> 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<td_api::text>(DialogFilter::get_default_icon_name(request.filter_.get()));
}

td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::getJsonValue &request) {
if (!check_utf8(request.json_)) {
return make_error(400, "JSON has invalid encoding");
Expand Down
3 changes: 3 additions & 0 deletions td/telegram/Td.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1135,6 +1137,7 @@ class Td final : public NetQueryCallback {
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::cleanFileName &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getLanguagePackString &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getPushReceiverId &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getChatFilterDefaultIconName &request);
static td_api::object_ptr<td_api::Object> do_static_request(td_api::getJsonValue &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getJsonString &request);
static td_api::object_ptr<td_api::Object> do_static_request(td_api::setLogStream &request);
Expand Down
4 changes: 3 additions & 1 deletion td/telegram/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -3540,6 +3540,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::reorderChatFilters>(as_chat_filter_ids(args)));
} else if (op == "grcf") {
send_request(td_api::make_object<td_api::getRecommendedChatFilters>());
} else if (op == "gcfdin") {
execute(td_api::make_object<td_api::getChatFilterDefaultIconName>(as_chat_filter(args)));
} else if (op == "sct") {
string chat_id;
string title;
Expand Down

0 comments on commit cbf77e3

Please sign in to comment.