Add td_api::getRecommendedChatFilters.

GitOrigin-RevId: d5f56357448c9f13154b5dead09cbd73ecf01e90
This commit is contained in:
levlam 2020-05-19 04:03:15 +03:00
parent 0d520e25be
commit a8e570fd65
7 changed files with 127 additions and 4 deletions

View File

@ -671,6 +671,12 @@ chatFilter title:string emoji:string pinned_chat_ids:vector<int53> included_chat
//@emoji The emoji for short filter representation
chatFilterInfo chat_filter_id:int32 title:string emoji:string = ChatFilterInfo;
//@description Describes a recommended chat filter @filter The chat filter @param_description Chat filter description
recommendedChatFilter filter:chatFilter description:string = RecommendedChatFilter;
//@description Contains a list of recommended chat filters @chat_filters List of recommended chat filters
recommendedChatFilters chat_filters:vector<recommendedChatFilter> = RecommendedChatFilters;
//@class ChatList @description Describes a list of chats
@ -3721,6 +3727,9 @@ 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
getRecommendedChatFilters = RecommendedChatFilters;
//@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

Binary file not shown.

View File

@ -169,6 +169,32 @@ class ReorderDialogFiltersQuery : public Td::ResultHandler {
}
};
class GetSuggestedDialogFiltersQuery : public Td::ResultHandler {
Promise<vector<tl_object_ptr<telegram_api::dialogFilterSuggested>>> promise_;
public:
explicit GetSuggestedDialogFiltersQuery(Promise<vector<tl_object_ptr<telegram_api::dialogFilterSuggested>>> &&promise)
: promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(telegram_api::messages_getSuggestedDialogFilters()));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::messages_getSuggestedDialogFilters>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
class GetOnlinesQuery : public Td::ResultHandler {
DialogId dialog_id_;
@ -4830,9 +4856,10 @@ struct MessagesManager::DialogFilter {
template <class ParserT>
void parse(ParserT &parser);
static unique_ptr<DialogFilter> get_dialog_filter(telegram_api::object_ptr<telegram_api::dialogFilter> filter) {
static unique_ptr<DialogFilter> get_dialog_filter(telegram_api::object_ptr<telegram_api::dialogFilter> filter,
bool with_id) {
DialogFilterId dialog_filter_id(filter->id_);
if (!dialog_filter_id.is_valid()) {
if (with_id && !dialog_filter_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << to_string(filter);
return nullptr;
}
@ -13763,6 +13790,63 @@ void MessagesManager::load_dialog_filter(const DialogFilter *filter, bool force,
promise.set_value(Unit());
}
void MessagesManager::get_recommended_dialog_filters(
Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise) {
auto query_promise =
PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](
Result<vector<tl_object_ptr<telegram_api::dialogFilterSuggested>>> result) mutable {
send_closure(actor_id, &MessagesManager::on_get_recommended_dialog_filters, std::move(result),
std::move(promise));
});
td_->create_handler<GetSuggestedDialogFiltersQuery>(std::move(query_promise))->send();
}
void MessagesManager::on_get_recommended_dialog_filters(
Result<vector<tl_object_ptr<telegram_api::dialogFilterSuggested>>> result,
Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise) {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
auto suggested_filters = result.move_as_ok();
MultiPromiseActorSafe mpas{"LoadRecommendedFiltersMultiPromiseActor"};
mpas.add_promise(Promise<Unit>());
auto lock = mpas.get_promise();
vector<RecommendedDialogFilter> filters;
for (auto &suggested_filter : suggested_filters) {
RecommendedDialogFilter filter;
filter.dialog_filter = DialogFilter::get_dialog_filter(std::move(suggested_filter->filter_), false);
CHECK(filter.dialog_filter != nullptr);
filter.dialog_filter->dialog_filter_id = DialogFilterId(); // just in case
load_dialog_filter(filter.dialog_filter.get(), false, mpas.get_promise());
filter.description = std::move(suggested_filter->description_);
filters.push_back(std::move(filter));
}
mpas.add_promise(PromiseCreator::lambda([actor_id = actor_id(this), filters = std::move(filters),
promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &MessagesManager::on_load_recommended_dialog_filters, std::move(result), std::move(filters),
std::move(promise));
}));
lock.set_value(Unit());
}
void MessagesManager::on_load_recommended_dialog_filters(
Result<Unit> &&result, vector<RecommendedDialogFilter> &&filters,
Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise) {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
auto chat_filters = transform(filters, [this](const RecommendedDialogFilter &filter) {
return td_api::make_object<td_api::recommendedChatFilter>(get_chat_filter_object(filter.dialog_filter.get()),
filter.description);
});
promise.set_value(td_api::make_object<td_api::recommendedChatFilters>(std::move(chat_filters)));
}
vector<DialogId> MessagesManager::get_dialogs(FolderId folder_id, DialogDate offset, int32 limit, bool force,
Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot());
@ -14079,7 +14163,7 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
vector<unique_ptr<DialogFilter>> dialog_filters;
LOG(INFO) << "Receive " << filters.size() << " chat filters";
for (auto &filter : filters) {
auto dialog_filter = DialogFilter::get_dialog_filter(std::move(filter));
auto dialog_filter = DialogFilter::get_dialog_filter(std::move(filter), true);
if (dialog_filter == nullptr) {
continue;
}
@ -16567,7 +16651,12 @@ td_api::object_ptr<td_api::chatFilter> MessagesManager::get_chat_filter_object(D
return nullptr;
}
auto get_chat_ids = [this, dialog_filter_id](const vector<InputDialogId> &input_dialog_ids) {
return get_chat_filter_object(filter);
}
td_api::object_ptr<td_api::chatFilter> MessagesManager::get_chat_filter_object(const DialogFilter *filter) const {
auto get_chat_ids = [this,
dialog_filter_id = filter->dialog_filter_id](const vector<InputDialogId> &input_dialog_ids) {
vector<int64> chat_ids;
chat_ids.reserve(input_dialog_ids.size());
for (auto &input_dialog_id : input_dialog_ids) {

View File

@ -501,6 +501,8 @@ class MessagesManager : public Actor {
void load_dialog_filter(DialogFilterId dialog_id, bool force, Promise<Unit> &&promise);
void get_recommended_dialog_filters(Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);
vector<DialogId> get_dialogs(FolderId folder_id, DialogDate offset, int32 limit, bool force, Promise<Unit> &&promise);
vector<DialogId> search_public_dialogs(const string &query, Promise<Unit> &&promise);
@ -1234,6 +1236,11 @@ class MessagesManager : public Actor {
struct DialogFilter;
struct RecommendedDialogFilter {
unique_ptr<DialogFilter> dialog_filter;
string description;
};
struct DialogList {
FolderId folder_id;
bool is_message_unread_count_inited_ = false;
@ -2211,8 +2218,16 @@ class MessagesManager : public Actor {
void update_dialogs_hints(const Dialog *d);
void update_dialogs_hints_rating(const Dialog *d);
td_api::object_ptr<td_api::chatFilter> get_chat_filter_object(const DialogFilter *filter) const;
void load_dialog_filter(const DialogFilter *filter, bool force, Promise<Unit> &&promise);
void on_get_recommended_dialog_filters(Result<vector<tl_object_ptr<telegram_api::dialogFilterSuggested>>> result,
Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);
void on_load_recommended_dialog_filters(Result<Unit> &&result, vector<RecommendedDialogFilter> &&filters,
Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);
Result<unique_ptr<DialogFilter>> create_dialog_filter(DialogFilterId dialog_filter_id,
td_api::object_ptr<td_api::chatFilter> filter);

View File

@ -5877,6 +5877,12 @@ void Td::on_request(uint64 id, const td_api::getChatFilter &request) {
CREATE_REQUEST(GetChatFilterRequest, request.chat_filter_id_);
}
void Td::on_request(uint64 id, const td_api::getRecommendedChatFilters &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
messages_manager_->get_recommended_dialog_filters(std::move(promise));
}
void Td::on_request(uint64 id, td_api::createChatFilter &request) {
CHECK_IS_USER();
if (request.filter_ == nullptr) {

View File

@ -677,6 +677,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::getChatFilter &request);
void on_request(uint64 id, const td_api::getRecommendedChatFilters &request);
void on_request(uint64 id, td_api::createChatFilter &request);
void on_request(uint64 id, td_api::editChatFilter &request);

View File

@ -3524,6 +3524,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::deleteChatFilter>(as_chat_filter_id(args)));
} else if (op == "rcf") {
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 == "sct") {
string chat_id;
string title;