From 571fbd68aa62bc0172d2d88d3e8555de48aab1ec Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 26 Dec 2023 21:24:04 +0300 Subject: [PATCH] Add td_api::openChatSimilarChat. --- td/generate/scheme/td_api.tl | 5 +++++ td/telegram/ContactsManager.cpp | 19 +++++++++++++++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/Td.cpp | 7 +++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 5 +++++ 6 files changed, 40 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 44328a610..c609cfa34 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7034,6 +7034,11 @@ getChatSimilarChats chat_id:int53 = Chats; //@return_local Pass true to get the number of chats without sending network requests, or -1 if the number of chats is unknown locally getChatSimilarChatCount chat_id:int53 return_local:Bool = Count; +//@description Informs TDLib that a chat was opened from the list of similar chats. The method is independent from openChat and closeChat methods +//@chat_id Identifier of the original chat, which similar chats were requested +//@opened_chat_id Identifier of the opened chat +openChatSimilarChat chat_id:int53 opened_chat_id:int53 = Ok; + //@description Returns a list of frequently used chats @category Category of chats to be returned @limit The maximum number of chats to be returned; up to 30 getTopChats category:TopChatCategory limit:int32 = Chats; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 121992d4d..72b189792 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7,6 +7,7 @@ #include "td/telegram/ContactsManager.h" #include "td/telegram/AnimationsManager.h" +#include "td/telegram/Application.h" #include "td/telegram/AuthManager.h" #include "td/telegram/BlockListId.h" #include "td/telegram/BotMenuButton.h" @@ -10155,6 +10156,24 @@ void ContactsManager::on_get_channel_recommendations( finish_load_channel_recommendations_queries(channel_id, total_count, std::move(dialog_ids)); } +void ContactsManager::open_channel_recommended_channel(DialogId dialog_id, DialogId opened_dialog_id, + Promise &&promise) { + if (!td_->messages_manager_->have_dialog_force(dialog_id, "open_channel_recommended_channel") || + !td_->messages_manager_->have_dialog_force(opened_dialog_id, "open_channel_recommended_channel")) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (dialog_id.get_type() != DialogType::Channel || opened_dialog_id.get_type() != DialogType::Channel) { + return promise.set_error(Status::Error(400, "Invalid chat specified")); + } + vector> data; + data.push_back(telegram_api::make_object( + "ref_channel_id", make_tl_object(to_string(dialog_id.get_channel_id().get())))); + data.push_back(telegram_api::make_object( + "open_channel_id", make_tl_object(to_string(opened_dialog_id.get_channel_id().get())))); + save_app_log(td_, "channels.open_recommended_channel", DialogId(), + telegram_api::make_object(std::move(data)), std::move(promise)); +} + void ContactsManager::return_created_public_dialogs(Promise> &&promise, const vector &channel_ids) { if (!promise) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index fac1814af..08c0a31ca 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -594,6 +594,8 @@ class ContactsManager final : public Actor { void get_created_public_dialogs(PublicDialogType type, Promise> &&promise, bool from_binlog); + void open_channel_recommended_channel(DialogId dialog_id, DialogId opened_dialog_id, Promise &&promise); + void check_created_public_dialogs_limit(PublicDialogType type, Promise &&promise); void reload_created_public_dialogs(PublicDialogType type, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 795c67424..87a222157 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5109,6 +5109,13 @@ void Td::on_request(uint64 id, const td_api::getChatSimilarChatCount &request) { std::move(promise)); } +void Td::on_request(uint64 id, const td_api::openChatSimilarChat &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->open_channel_recommended_channel(DialogId(request.chat_id_), DialogId(request.opened_chat_id_), + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getTopChats &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 22519b6a7..152500d60 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -641,6 +641,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getChatSimilarChatCount &request); + void on_request(uint64 id, const td_api::openChatSimilarChat &request); + void on_request(uint64 id, const td_api::getTopChats &request); void on_request(uint64 id, const td_api::removeTopChat &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7c75dba26..ba2134760 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5225,6 +5225,11 @@ class CliClient final : public Actor { bool return_local; get_args(args, chat_id, return_local); send_request(td_api::make_object(chat_id, return_local)); + } else if (op == "ocsc") { + ChatId chat_id; + ChatId similar_chat_id; + get_args(args, chat_id, similar_chat_id); + send_request(td_api::make_object(chat_id, similar_chat_id)); } else if (op == "gcpc") { send_request(td_api::make_object()); } else if (op == "gcpcl") {