From 8799a30b6e32ab1fd88fe34ac5fe8bb959156d20 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 7 Jul 2020 18:48:17 +0300 Subject: [PATCH] Add updates about unknown users, etc. in getCurrentState. GitOrigin-RevId: 137250f7e4e194f4048ee399e0a80bc29c6e0429 --- td/telegram/ContactsManager.cpp | 74 ++++++++++++++++++++++++--------- td/telegram/ContactsManager.h | 10 ++++- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index f38dd41d1..b2d856fc4 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13557,7 +13557,7 @@ void ContactsManager::on_upload_profile_photo_error(FileId file_id, Status statu promise.set_error(std::move(status)); // TODO check that status has valid error code } -tl_object_ptr ContactsManager::get_user_status_object(UserId user_id, const User *u) const { +td_api::object_ptr ContactsManager::get_user_status_object(UserId user_id, const User *u) const { if (u->is_bot) { return make_tl_object(std::numeric_limits::max()); } @@ -13583,15 +13583,18 @@ tl_object_ptr ContactsManager::get_user_status_object(UserId } } +td_api::object_ptr ContactsManager::get_update_unknown_user_object(UserId user_id) { + return td_api::make_object( + td_api::make_object(user_id.get(), "", "", "", "", td_api::make_object(), + get_profile_photo_object(nullptr, nullptr), false, false, false, false, "", + false, false, td_api::make_object(), "")); +} + int32 ContactsManager::get_user_id_object(UserId user_id, const char *source) const { if (user_id.is_valid() && get_user(user_id) == nullptr && unknown_users_.count(user_id) == 0) { LOG(ERROR) << "Have no info about " << user_id << " from " << source; unknown_users_.insert(user_id); - send_closure(G()->td(), &Td::send_update, - td_api::make_object(td_api::make_object( - user_id.get(), "", "", "", "", td_api::make_object(), - get_profile_photo_object(td_->file_manager_.get(), nullptr), false, false, false, false, "", false, - false, td_api::make_object(), ""))); + send_closure(G()->td(), &Td::send_update, get_update_unknown_user_object(user_id)); } return user_id.get(); } @@ -13648,13 +13651,16 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U is_bot ? get_bot_info_object(user_id) : nullptr); } +td_api::object_ptr ContactsManager::get_update_unknown_basic_group_object(ChatId chat_id) { + return td_api::make_object(td_api::make_object( + chat_id.get(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), true, 0)); +} + int32 ContactsManager::get_basic_group_id_object(ChatId chat_id, const char *source) const { if (chat_id.is_valid() && get_chat(chat_id) == nullptr && unknown_chats_.count(chat_id) == 0) { LOG(ERROR) << "Have no info about " << chat_id << " from " << source; unknown_chats_.insert(chat_id); - send_closure(G()->td(), &Td::send_update, - td_api::make_object(td_api::make_object( - chat_id.get(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), true, 0))); + send_closure(G()->td(), &Td::send_update, get_update_unknown_basic_group_object(chat_id)); } return chat_id.get(); } @@ -13694,14 +13700,18 @@ tl_object_ptr ContactsManager::get_basic_group_full_ chat_full->invite_link); } +td_api::object_ptr ContactsManager::get_update_unknown_supergroup_object( + ChannelId channel_id) { + return td_api::make_object(td_api::make_object( + channel_id.get(), string(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), 0, false, + false, false, false, true, false, "", false)); +} + int32 ContactsManager::get_supergroup_id_object(ChannelId channel_id, const char *source) const { if (channel_id.is_valid() && get_channel(channel_id) == nullptr && unknown_channels_.count(channel_id) == 0) { LOG(ERROR) << "Have no info about " << channel_id << " received from " << source; unknown_channels_.insert(channel_id); - send_closure(G()->td(), &Td::send_update, - td_api::make_object(td_api::make_object( - channel_id.get(), string(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), - 0, false, false, false, false, true, false, "", false))); + send_closure(G()->td(), &Td::send_update, get_update_unknown_supergroup_object(channel_id)); } return channel_id.get(); } @@ -13758,15 +13768,18 @@ tl_object_ptr ContactsManager::get_secret_chat_state_ob } } +td_api::object_ptr ContactsManager::get_update_unknown_secret_chat_object( + SecretChatId secret_chat_id) { + return td_api::make_object(td_api::make_object( + secret_chat_id.get(), 0, get_secret_chat_state_object(SecretChatState::Unknown), false, 0, string(), 0)); +} + int32 ContactsManager::get_secret_chat_id_object(SecretChatId secret_chat_id, const char *source) const { if (secret_chat_id.is_valid() && get_secret_chat(secret_chat_id) == nullptr && unknown_secret_chats_.count(secret_chat_id) == 0) { LOG(ERROR) << "Have no info about " << secret_chat_id << " from " << source; unknown_secret_chats_.insert(secret_chat_id); - send_closure( - G()->td(), &Td::send_update, - td_api::make_object(td_api::make_object( - secret_chat_id.get(), 0, get_secret_chat_state_object(SecretChatState::Unknown), false, 0, string(), 0))); + send_closure(G()->td(), &Td::send_update, get_update_unknown_secret_chat_object(secret_chat_id)); } return secret_chat_id.get(); } @@ -13913,6 +13926,27 @@ void ContactsManager::after_get_difference() { } void ContactsManager::get_current_state(vector> &updates) const { + for (auto user_id : unknown_users_) { + if (!have_min_user(user_id)) { + updates.push_back(get_update_unknown_user_object(user_id)); + } + } + for (auto chat_id : unknown_chats_) { + if (!have_chat(chat_id)) { + updates.push_back(get_update_unknown_basic_group_object(chat_id)); + } + } + for (auto channel_id : unknown_channels_) { + if (!have_channel(channel_id)) { + updates.push_back(get_update_unknown_supergroup_object(channel_id)); + } + } + for (auto secret_chat_id : unknown_secret_chats_) { + if (!have_secret_chat(secret_chat_id)) { + updates.push_back(get_update_unknown_secret_chat_object(secret_chat_id)); + } + } + for (auto &it : users_) { updates.push_back(td_api::make_object(get_user_object(it.first, it.second.get()))); } @@ -13930,15 +13964,15 @@ void ContactsManager::get_current_state(vector( - get_user_id_object(it.first, "get_current_state"), get_user_full_info_object(it.first, it.second.get()))); + it.first.get(), get_user_full_info_object(it.first, it.second.get()))); } 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.get()))); + it.first.get(), get_supergroup_full_info_object(it.second.get()))); } 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.get()))); + it.first.get(), get_basic_group_full_info_object(it.second.get()))); } } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index c02e064f2..07f5b6c9b 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1333,7 +1333,9 @@ class ContactsManager : public Actor { void reload_dialog_administrators(DialogId dialog_id, int32 hash, Promise &&promise); - tl_object_ptr get_user_status_object(UserId user_id, const User *u) const; + static td_api::object_ptr get_update_unknown_user_object(UserId user_id); + + td_api::object_ptr get_user_status_object(UserId user_id, const User *u) const; td_api::object_ptr get_bot_info_object(UserId user_id) const; @@ -1341,18 +1343,24 @@ class ContactsManager : public Actor { tl_object_ptr get_user_full_info_object(UserId user_id, const UserFull *user_full) const; + static td_api::object_ptr get_update_unknown_basic_group_object(ChatId chat_id); + tl_object_ptr get_basic_group_object(ChatId chat_id, const Chat *c); tl_object_ptr get_basic_group_object_const(ChatId chat_id, const Chat *c) const; tl_object_ptr get_basic_group_full_info_object(const ChatFull *chat_full) const; + static td_api::object_ptr get_update_unknown_supergroup_object(ChannelId channel_id); + tl_object_ptr get_supergroup_object(ChannelId channel_id, const Channel *c) 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); + static td_api::object_ptr get_update_unknown_secret_chat_object(SecretChatId user_id); + tl_object_ptr get_secret_chat_object(SecretChatId secret_chat_id, const SecretChat *secret_chat); tl_object_ptr get_secret_chat_object_const(SecretChatId secret_chat_id,