From f8894dbff90c81be99d19efbe3b2b3c2816ca305 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 Sep 2018 21:37:35 +0300 Subject: [PATCH] Add ContactsManager::get_current_state. GitOrigin-RevId: 108cab6899368e264684aab79d488384be968e48 --- td/telegram/ContactsManager.cpp | 41 +++++++++++++++++++++++++++++---- td/telegram/ContactsManager.h | 6 +++-- td/telegram/Td.cpp | 8 +++---- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 50a00cbb..74b2a52e 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6305,7 +6305,7 @@ void ContactsManager::update_channel_full(ChannelFull *channel_full, ChannelId c send_closure( G()->td(), &Td::send_update, make_tl_object(get_supergroup_id_object(channel_id, "update_channel_full"), - get_channel_full_info_object(channel_full))); + get_supergroup_full_info_object(channel_full))); } } @@ -9677,11 +9677,11 @@ tl_object_ptr ContactsManager::get_supergroup_object(Channel channel->is_verified, channel->restriction_reason); } -tl_object_ptr ContactsManager::get_channel_full_info_object(ChannelId channel_id) const { - return get_channel_full_info_object(get_channel_full(channel_id)); +tl_object_ptr ContactsManager::get_supergroup_full_info_object(ChannelId channel_id) const { + return get_supergroup_full_info_object(get_channel_full(channel_id)); } -tl_object_ptr ContactsManager::get_channel_full_info_object( +tl_object_ptr ContactsManager::get_supergroup_full_info_object( const ChannelFull *channel_full) const { CHECK(channel_full != nullptr); return make_tl_object( @@ -9689,7 +9689,7 @@ tl_object_ptr ContactsManager::get_channel_full_info channel_full->restricted_count, channel_full->banned_count, channel_full->can_get_participants, channel_full->can_set_username, channel_full->can_set_sticker_set, channel_full->is_all_history_available, channel_full->sticker_set_id, channel_full->invite_link, channel_full->pinned_message_id.get(), - get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_channel_full_info_object"), + get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"), channel_full->migrated_from_max_message_id.get()); } @@ -9859,4 +9859,35 @@ UserId ContactsManager::get_support_user(Promise &&promise) { return UserId(); } +void ContactsManager::get_current_state(vector> &updates) { + for (auto &it : users_) { + updates.push_back(td_api::make_object(get_user_object(it.first, &it.second))); + } + for (auto &it : channels_) { + updates.push_back(td_api::make_object(get_supergroup_object(it.first, &it.second))); + } + for (auto &it : chats_) { // chat object can contain channel_id, so it must be sent after channels + updates.push_back(td_api::make_object(get_basic_group_object(it.first, &it.second))); + } + for (auto &it : secret_chats_) { // secret chat object contains user_id, so it must be sent after users + updates.push_back(td_api::make_object(get_secret_chat_object(it.first, &it.second))); + } + + for (auto &it : users_full_) { + if (!it.second.is_inited) { + continue; + } + updates.push_back(td_api::make_object(get_user_id_object(it.first, "get_current_state"), + get_user_full_info_object(it.first, &it.second))); + } + for (auto &it : channels_full_) { + updates.push_back(td_api::make_object( + get_supergroup_id_object(it.first, "get_current_state"), get_supergroup_full_info_object(&it.second))); + } + for (auto &it : chats_full_) { + updates.push_back(td_api::make_object( + get_basic_group_id_object(it.first, "get_current_state"), get_basic_group_full_info_object(&it.second))); + } +} + } // namespace td diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index e6598dbe..a9f8c8c0 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -413,7 +413,7 @@ class ContactsManager : public Actor { tl_object_ptr get_supergroup_object(ChannelId channel_id) const; - tl_object_ptr get_channel_full_info_object(ChannelId channel_id) const; + tl_object_ptr get_supergroup_full_info_object(ChannelId channel_id) const; int32 get_secret_chat_id_object(SecretChatId secret_chat_id, const char *source) const; @@ -433,6 +433,8 @@ class ContactsManager : public Actor { UserId get_support_user(Promise &&promise); + void get_current_state(vector> &updates); + private: enum class LinkState : uint8 { Unknown, None, KnowsPhoneNumber, Contact }; @@ -986,7 +988,7 @@ class ContactsManager : public Actor { tl_object_ptr get_supergroup_object(ChannelId channel_id, const Channel *channel) const; - tl_object_ptr get_channel_full_info_object(const ChannelFull *channel_full) const; + tl_object_ptr get_supergroup_full_info_object(const ChannelFull *channel_full) const; static tl_object_ptr get_secret_chat_state_object(SecretChatState state); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 14ee3a2d..ac50dea6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -846,7 +846,7 @@ class GetSupergroupFullInfoRequest : public RequestActor<> { } void do_send_result() override { - send_result(td->contacts_manager_->get_channel_full_info_object(channel_id_)); + send_result(td->contacts_manager_->get_supergroup_full_info_object(channel_id_)); } public: @@ -4587,19 +4587,19 @@ void Td::on_request(uint64 id, const td_api::getCurrentState &request) { updates.push_back(td_api::make_object(get_connection_state_object(connection_state_))); + contacts_manager_->get_current_state(updates); + /* // TODO updateUnreadMessageCount { updateUnreadChatCount { updateScopeNotificationSettings { updateScopeNotificationSettings { - updateUser { - updateSecretChat { updateNewChat { updateChatLastMessage { */ - // send response synchronously to prevent "Request aborted" + // send response synchronously to prevent "Request aborted" or other changes of the current state send_result(id, td_api::make_object(std::move(updates))); }