diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8542bcdc8..7ca1f17f4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7155,7 +7155,10 @@ getSuitableDiscussionChats = Chats; //@description Returns a list of recently inactive supergroups and channels. Can be used when user reaches limit on the number of joined supergroups and channels and receives CHANNELS_TOO_MUCH error. Also, the limit can be increased with Telegram Premium getInactiveSupergroupChats = Chats; -//@description Returns list of non-pinned saved messages topic from the specified offset +//@description Returns list of all pinned saved messages topics +getPinnedSavedMessagesTopics = FoundSavedMessagesTopics; + +//@description Returns list of non-pinned saved messages topics from the specified offset //@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results //@limit The maximum number of saved messages topics to be returned; up to 100 getSavedMessagesTopics offset:string limit:int32 = FoundSavedMessagesTopics; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5c33da074..2c8fdc96a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -188,6 +188,34 @@ class GetPinnedDialogsQuery final : public Td::ResultHandler { } }; +class GetPinnedSavedDialogsQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetPinnedSavedDialogsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::messages_getPinnedSavedDialogs())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto result = result_ptr.move_as_ok(); + LOG(INFO) << "Receive pinned Saved Messages topics: " << to_string(result); + td_->messages_manager_->on_get_saved_messages_topics(std::move(result), std::move(promise_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class GetSavedDialogsQuery final : public Td::ResultHandler { Promise> promise_; @@ -15856,6 +15884,11 @@ void MessagesManager::reload_pinned_dialogs(DialogListId dialog_list_id, Promise } } +void MessagesManager::get_pinned_saved_messages_topics( + Promise> &&promise) { + td_->create_handler(std::move(promise))->send(); +} + void MessagesManager::get_saved_messages_topics( const string &offset, int32 limit, Promise> &&promise) { int32 offset_date = std::numeric_limits::max(); @@ -15907,6 +15940,7 @@ void MessagesManager::on_get_saved_messages_topics( vector> messages; vector> chats; vector> users; + bool is_last = false; switch (saved_dialogs_ptr->get_id()) { case telegram_api::messages_savedDialogsNotModified::ID: LOG(ERROR) << "Receive messages.savedDialogsNotModified"; @@ -15918,6 +15952,7 @@ void MessagesManager::on_get_saved_messages_topics( messages = std::move(saved_dialogs->messages_); chats = std::move(saved_dialogs->chats_); users = std::move(saved_dialogs->users_); + is_last = true; break; } case telegram_api::messages_savedDialogsSlice::ID: { @@ -15955,7 +15990,13 @@ void MessagesManager::on_get_saved_messages_topics( vector added_saved_messages_topic_ids; vector> found_saved_messages_topics; for (auto &dialog : dialogs) { - SavedMessagesTopicId saved_messages_topic_id(DialogId(dialog->peer_)); + auto peer_dialog_id = DialogId(dialog->peer_); + if (!peer_dialog_id.is_valid()) { + LOG(ERROR) << "Receive " << peer_dialog_id << " in result of getSavedMessagesTopics"; + total_count--; + continue; + } + SavedMessagesTopicId saved_messages_topic_id(peer_dialog_id); if (td::contains(added_saved_messages_topic_ids, saved_messages_topic_id)) { LOG(ERROR) << "Receive " << saved_messages_topic_id << " twice in result of getSavedMessagesTopics with total_count = " << total_count; @@ -15979,11 +16020,10 @@ void MessagesManager::on_get_saved_messages_topics( continue; } auto message_date = get_message_date(it->second); - auto dialog_id = DialogId::get_message_dialog_id(it->second); - if (message_date > 0 && dialog_id.is_valid()) { + if (message_date > 0) { last_message_date = message_date; last_message_id = last_topic_message_id; - last_dialog_id = dialog_id; + last_dialog_id = peer_dialog_id; } auto full_message_id = on_get_message(std::move(it->second), false, false, false, "on_get_saved_messages_topics"); message_id_to_message.erase(it); @@ -15999,7 +16039,7 @@ void MessagesManager::on_get_saved_messages_topics( get_message_object(full_message_id, "on_get_saved_messages_topics"))); } string next_offset; - if (last_message_date > 0) { + if (last_message_date > 0 && !is_last) { next_offset = PSTRING() << last_message_date << ',' << last_dialog_id.get() << ',' << last_message_id.get_server_message_id().get(); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index d1bb8b79b..a16f67591 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -529,6 +529,8 @@ class MessagesManager final : public Actor { void read_all_dialogs_from_list(DialogListId dialog_list_id, Promise &&promise, bool is_recursive = false); + void get_pinned_saved_messages_topics(Promise> &&promise); + void get_saved_messages_topics(const string &offset, int32 limit, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8fc0d6a2a..76b4f21b6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5021,6 +5021,12 @@ void Td::on_request(uint64 id, const td_api::getChats &request) { messages_manager_->get_dialogs_from_list(DialogListId(request.chat_list_), request.limit_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getPinnedSavedMessagesTopics &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + messages_manager_->get_pinned_saved_messages_topics(std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getSavedMessagesTopics &request) { CHECK_IS_USER(); // don't need to check offset UTF-8 correctness diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 6e4ce7a8d..eddc310e6 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -671,6 +671,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getChats &request); + void on_request(uint64 id, const td_api::getPinnedSavedMessagesTopics &request); + void on_request(uint64 id, const td_api::getSavedMessagesTopics &request); void on_request(uint64 id, td_api::searchPublicChat &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f2c653892..43ddea597 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2750,6 +2750,8 @@ class CliClient final : public Actor { send_request(td_api::make_object(nullptr, 1)); send_request(td_api::make_object(nullptr, 10)); send_request(td_api::make_object(nullptr, 5)); + } else if (op == "gpsmt") { + send_request(td_api::make_object()); } else if (op == "gsmt") { string limit; string offset;