diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 87e47d634..b1549fcc8 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4130,6 +4130,9 @@ removeRecentlyFoundChat chat_id:int53 = Ok; //@description Clears the list of recently found chats clearRecentlyFoundChats = Ok; +//@description Returns recently opened chats, this is an offline request. Returns chats in the order of last opening @limit The maximum number of chats to be returned +getRecentlyOpenedChats limit:int32 = Chats; + //@description Checks whether a username can be set for a chat @chat_id Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if the chat is being created @username Username to be checked checkChatUsername chat_id:int53 username:string = CheckChatUsernameResult; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index adca1b55f..a9919e903 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5695,7 +5695,10 @@ MessagesManager::Dialog::~Dialog() { } MessagesManager::MessagesManager(Td *td, ActorShared<> parent) - : recently_found_dialogs_{td, "recently_found", MAX_RECENTLY_FOUND_DIALOGS}, td_(td), parent_(std::move(parent)) { + : recently_found_dialogs_{td, "recently_found", MAX_RECENT_DIALOGS} + , recently_opened_dialogs_{td, "recently_opened", MAX_RECENT_DIALOGS} + , td_(td) + , parent_(std::move(parent)) { upload_media_callback_ = std::make_shared(); upload_thumbnail_callback_ = std::make_shared(); upload_dialog_photo_callback_ = std::make_shared(); @@ -10919,6 +10922,7 @@ void MessagesManager::on_dialog_deleted(DialogId dialog_id, Promise &&prom d->need_restore_reply_markup = true; } recently_found_dialogs_.remove_dialog(dialog_id); + recently_opened_dialogs_.remove_dialog(dialog_id); if (dialog_id.get_type() == DialogType::Channel) { G()->td_db()->get_binlog_pmc()->erase(get_channel_pts_key(dialog_id)); } @@ -16262,6 +16266,10 @@ std::pair> MessagesManager::search_dialogs(const string return {narrow_cast(result.first), std::move(dialog_ids)}; } +std::pair> MessagesManager::get_recently_opened_dialogs(int32 limit, Promise &&promise) { + return recently_opened_dialogs_.get_dialogs(limit, std::move(promise)); +} + vector MessagesManager::sort_dialogs_by_order(const vector &dialog_ids, int32 limit) const { CHECK(!td_->auth_manager_->is_bot()); int64 fake_order = static_cast(dialog_ids.size()) + 1; @@ -19525,7 +19533,11 @@ void MessagesManager::read_message_contents_on_server(DialogId dialog_id, vector void MessagesManager::open_dialog(Dialog *d) { DialogId dialog_id = d->dialog_id; - if (d->is_opened || !have_input_peer(dialog_id, AccessRights::Read)) { + if (!have_input_peer(dialog_id, AccessRights::Read)) { + return; + } + recently_opened_dialogs_.add_dialog(dialog_id); + if (d->is_opened) { return; } d->is_opened = true; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 58624c944..2a9d0341d 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -369,6 +369,8 @@ class MessagesManager final : public Actor { void clear_recently_found_dialogs(); + std::pair> get_recently_opened_dialogs(int32 limit, Promise &&promise); + DialogId resolve_dialog_username(const string &username) const; DialogId search_public_dialog(const string &username_to_search, bool force, Promise &&promise); @@ -1652,7 +1654,7 @@ class MessagesManager final : public Actor { static constexpr int32 MIN_CHANNEL_DIFFERENCE = 1; static constexpr int32 MAX_CHANNEL_DIFFERENCE = 100; static constexpr int32 MAX_BOT_CHANNEL_DIFFERENCE = 100000; // server side limit - static constexpr int32 MAX_RECENTLY_FOUND_DIALOGS = 50; // some reasonable value + static constexpr int32 MAX_RECENT_DIALOGS = 50; // some reasonable value static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description static constexpr size_t MAX_DIALOG_FILTER_TITLE_LENGTH = 12; // server side limit for dialog filter title @@ -3057,6 +3059,7 @@ class MessagesManager final : public Actor { static DialogId get_message_original_sender(const Message *m); RecentDialogList recently_found_dialogs_; + RecentDialogList recently_opened_dialogs_; class UploadMediaCallback; class UploadThumbnailCallback; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 63e73ba20..1d4de6eaa 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -960,6 +960,25 @@ class GetInactiveSupergroupChatsRequest final : public RequestActor<> { } }; +class GetRecentlyOpenedChatsRequest final : public RequestActor<> { + int32 limit_; + + std::pair> dialog_ids_; + + void do_run(Promise &&promise) final { + dialog_ids_ = td->messages_manager_->get_recently_opened_dialogs(limit_, std::move(promise)); + } + + void do_send_result() final { + send_result(MessagesManager::get_chats_object(dialog_ids_)); + } + + public: + GetRecentlyOpenedChatsRequest(ActorShared td, uint64 request_id, int32 limit) + : RequestActor(std::move(td), request_id), limit_(limit) { + } +}; + class GetMessageRequest final : public RequestOnceActor { FullMessageId full_message_id_; @@ -5363,6 +5382,11 @@ void Td::on_request(uint64 id, const td_api::clearRecentlyFoundChats &request) { send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } +void Td::on_request(uint64 id, const td_api::getRecentlyOpenedChats &request) { + CHECK_IS_USER(); + CREATE_REQUEST(GetRecentlyOpenedChatsRequest, request.limit_); +} + void Td::on_request(uint64 id, const td_api::openChat &request) { CHECK_IS_USER(); answer_ok_query(id, messages_manager_->open_dialog(DialogId(request.chat_id_))); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 9e6cebd54..2349a12e0 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -577,6 +577,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::clearRecentlyFoundChats &request); + void on_request(uint64 id, const td_api::getRecentlyOpenedChats &request); + void on_request(uint64 id, const td_api::getGroupsInCommon &request); void on_request(uint64 id, td_api::checkChatUsername &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 2f45b7f09..ed4106f6e 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4049,6 +4049,8 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_chat_id(args))); } else if (op == "crfcs") { send_request(td_api::make_object()); + } else if (op == "groc") { + send_request(td_api::make_object(as_limit(args))); } else if (op == "gwpp") { send_request(td_api::make_object(as_caption(args))); } else if (op == "gwpiv") {