From 5563ad4304f9a3f68bb312b8a7289185659106b4 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 17 Mar 2023 21:42:34 +0300 Subject: [PATCH] Add get_update_user/basic_group/supergroup/secret_chat_object --- td/telegram/ContactsManager.cpp | 44 +++++++++++++++++++++------------ td/telegram/ContactsManager.h | 10 ++++++++ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 6062f3efd..01a1e4009 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -10877,8 +10877,7 @@ void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string if (c->participant_count == 0 && temp_c.participant_count != 0) { c->participant_count = temp_c.participant_count; CHECK(c->is_update_supergroup_sent); - send_closure(G()->td(), &Td::send_update, - make_tl_object(get_supergroup_object(channel_id, c))); + send_closure(G()->td(), &Td::send_update, get_update_supergroup_object(channel_id, c)); } c->status.update_restrictions(); @@ -11651,7 +11650,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo u->need_save_to_database = false; } if (u->is_changed) { - send_closure(G()->td(), &Td::send_update, make_tl_object(get_user_object(user_id, u))); + send_closure(G()->td(), &Td::send_update, get_update_user_object(user_id, u)); u->is_changed = false; u->is_status_changed = false; u->is_update_user_sent = true; @@ -11741,8 +11740,7 @@ void ContactsManager::update_chat(Chat *c, ChatId chat_id, bool from_binlog, boo c->need_save_to_database = false; } if (c->is_changed) { - send_closure(G()->td(), &Td::send_update, - make_tl_object(get_basic_group_object(chat_id, c))); + send_closure(G()->td(), &Td::send_update, get_update_basic_group_object(chat_id, c)); c->is_changed = false; c->is_update_basic_group_sent = true; } @@ -11870,8 +11868,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from c->need_save_to_database = false; } if (c->is_changed) { - send_closure(G()->td(), &Td::send_update, - make_tl_object(get_supergroup_object(channel_id, c))); + send_closure(G()->td(), &Td::send_update, get_update_supergroup_object(channel_id, c)); c->is_changed = false; c->is_update_supergroup_sent = true; } @@ -11929,8 +11926,7 @@ void ContactsManager::update_secret_chat(SecretChat *c, SecretChatId secret_chat } } if (c->is_changed) { - send_closure(G()->td(), &Td::send_update, - make_tl_object(get_secret_chat_object(secret_chat_id, c))); + send_closure(G()->td(), &Td::send_update, get_update_secret_chat_object(secret_chat_id, c)); c->is_changed = false; } @@ -13330,13 +13326,10 @@ void ContactsManager::on_update_user_full_need_phone_number_privacy_exception( void ContactsManager::on_ignored_restriction_reasons_changed() { restricted_user_ids_.foreach([&](const UserId &user_id) { - send_closure(G()->td(), &Td::send_update, - td_api::make_object(get_user_object(user_id, get_user(user_id)))); + send_closure(G()->td(), &Td::send_update, get_update_user_object(user_id, get_user(user_id))); }); restricted_channel_ids_.foreach([&](const ChannelId &channel_id) { - send_closure( - G()->td(), &Td::send_update, - td_api::make_object(get_supergroup_object(channel_id, get_channel(channel_id)))); + send_closure(G()->td(), &Td::send_update, get_update_supergroup_object(channel_id, get_channel(channel_id))); }); } @@ -18308,6 +18301,10 @@ td_api::object_ptr ContactsManager::get_user_status_object(U } } +td_api::object_ptr ContactsManager::get_update_user_object(UserId user_id, const User *u) const { + return td_api::make_object(get_user_object(user_id, u)); +} + td_api::object_ptr ContactsManager::get_update_unknown_user_object(UserId user_id) const { auto have_access = user_id == get_my_id() || user_messages_.count(user_id) != 0; return td_api::make_object(td_api::make_object( @@ -18422,6 +18419,11 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U std::move(bot_info)); } +td_api::object_ptr ContactsManager::get_update_basic_group_object(ChatId chat_id, + const Chat *c) { + return td_api::make_object(get_basic_group_object(chat_id, c)); +} + 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)); @@ -18476,6 +18478,11 @@ tl_object_ptr ContactsManager::get_basic_group_full_ chat_full->invite_link.get_chat_invite_link_object(this), std::move(bot_commands)); } +td_api::object_ptr ContactsManager::get_update_supergroup_object(ChannelId channel_id, + const Channel *c) const { + return td_api::make_object(get_supergroup_object(channel_id, c)); +} + td_api::object_ptr ContactsManager::get_update_unknown_supergroup_object( ChannelId channel_id) const { auto min_channel = get_min_channel(channel_id); @@ -18559,6 +18566,11 @@ tl_object_ptr ContactsManager::get_secret_chat_state_ob } } +td_api::object_ptr ContactsManager::get_update_secret_chat_object( + SecretChatId secret_chat_id, const SecretChat *secret_chat) { + return td_api::make_object(get_secret_chat_object(secret_chat_id, secret_chat)); +} + td_api::object_ptr ContactsManager::get_update_unknown_secret_chat_object( SecretChatId secret_chat_id) { return td_api::make_object(td_api::make_object( @@ -18746,10 +18758,10 @@ void ContactsManager::get_current_state(vector &user) { - updates.push_back(td_api::make_object(get_user_object(user_id, user.get()))); + updates.push_back(get_update_user_object(user_id, user.get())); }); channels_.foreach([&](const ChannelId &channel_id, const unique_ptr &channel) { - updates.push_back(td_api::make_object(get_supergroup_object(channel_id, channel.get()))); + updates.push_back(get_update_supergroup_object(channel_id, channel.get())); }); // chat objects can contain channel_id, so they must be sent after channels chats_.foreach([&](const ChatId &chat_id, const unique_ptr &chat) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 5229e83e8..402da7693 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1684,6 +1684,8 @@ class ContactsManager final : public Actor { void on_dismiss_suggested_action(SuggestedAction action, Result &&result); + td_api::object_ptr get_update_user_object(UserId user_id, const User *u) const; + td_api::object_ptr get_update_unknown_user_object(UserId user_id) const; td_api::object_ptr get_user_status_object(UserId user_id, const User *u) const; @@ -1692,6 +1694,8 @@ class ContactsManager final : public Actor { tl_object_ptr get_user_full_info_object(UserId user_id, const UserFull *user_full) const; + td_api::object_ptr get_update_basic_group_object(ChatId chat_id, const Chat *c); + 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); @@ -1701,6 +1705,9 @@ class ContactsManager final : public Actor { tl_object_ptr get_basic_group_full_info_object(ChatId chat_id, const ChatFull *chat_full) const; + td_api::object_ptr get_update_supergroup_object(ChannelId channel_id, + const Channel *c) const; + td_api::object_ptr get_update_unknown_supergroup_object(ChannelId channel_id) const; static tl_object_ptr get_supergroup_object(ChannelId channel_id, const Channel *c); @@ -1718,6 +1725,9 @@ class ContactsManager final : public Actor { static tl_object_ptr get_secret_chat_state_object(SecretChatState state); + td_api::object_ptr get_update_secret_chat_object(SecretChatId secret_chat_id, + const SecretChat *secret_chat); + static td_api::object_ptr get_update_unknown_secret_chat_object( SecretChatId secret_chat_id);