From 0e41d96335d5239d7fd9e2fac35d807294c1d990 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 27 Jan 2018 16:57:59 +0300 Subject: [PATCH] Send update with unknown basic group/supergroup/secret chat when its identifier is returned. GitOrigin-RevId: e3c0d7904f02b79abdcbf990db1bdcf8d67591e3 --- td/generate/scheme/td_api.tl | 10 +++--- td/telegram/ContactsManager.cpp | 57 +++++++++++++++++++++++++++------ td/telegram/ContactsManager.h | 9 ++++++ td/telegram/MessagesManager.cpp | 17 ++++++---- td/telegram/Td.cpp | 3 +- 5 files changed, 74 insertions(+), 22 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 16ad6d109..27027e5ca 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1806,16 +1806,16 @@ updateUserChatAction chat_id:int53 user_id:int32 action:ChatAction = Update; //@description The user went online or offline @user_id User identifier @status New status of the user updateUserStatus user_id:int32 status:UserStatus = Update; -//@description Some data of a user has changed. This update is guaranteed to come before the user identifier is returned to the client as long as the library has information on the user @user New data about the user +//@description Some data of a user has changed. This update is guaranteed to come before the user identifier is returned to the client @user New data about the user updateUser user:user = Update; -//@description Some data of a basic group has changed. This update is guaranteed to come before the basic group identifier is returned to the client, as long as the library has information on the group @basic_group New data about the group +//@description Some data of a basic group has changed. This update is guaranteed to come before the basic group identifier is returned to the client @basic_group New data about the group updateBasicGroup basic_group:basicGroup = Update; -//@description Some data of a supergroup or a channel has changed. This update is guaranteed to come before the supergroup identifier is returned to the client as long as the library has information on the supergroup @supergroup New data about the supergroup +//@description Some data of a supergroup or a channel has changed. This update is guaranteed to come before the supergroup identifier is returned to the client @supergroup New data about the supergroup updateSupergroup supergroup:supergroup = Update; -//@description Some data of a secret chat has changed. This update is guaranteed to come before the secret chat identifier is returned to the client as long as the library has information about the secret chat @secret_chat New data about the secret chat +//@description Some data of a secret chat has changed. This update is guaranteed to come before the secret chat identifier is returned to the client @secret_chat New data about the secret chat updateSecretChat secret_chat:secretChat = Update; //@description Some data from userFullInfo has been changed @user_id User identifier @user_full_info New full information about the user @@ -2036,7 +2036,7 @@ getChats offset_order:int64 offset_chat_id:int53 limit:int32 = Chats; //@description Searches a public chat by its username. Currently only private chats, supergroups and channels can be public. Returns the chat if found; otherwise an error is returned @username Username to be resolved searchPublicChat username:string = Chat; -//@description Searches public chats by a prefix of their username. Currently only private chats, supergroups and channels can be public. Returns a meaningful number of results. Returns nothing if the length of the searched username prefix is less than 5. Excludes private chats with contacts and chats from the chat list from the results @query Query to search for +//@description Searches public chats by looking for specified query in their username and title. Currently only private chats, supergroups and channels can be public. Returns a meaningful number of results. Returns nothing if the length of the searched username prefix is less than 5. Excludes private chats with contacts and chats from the chat list from the results @query Query to search for searchPublicChats query:string = Chats; //@description Searches for the specified query in the title and username of already known chats, this is an offline request. Returns chats in the order seen in the chat list @query Query to search for. If the query is empty, returns up to 20 recently found chats @limit Maximum number of chats to be returned diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 693f513db..e49f4ad18 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -5835,9 +5835,9 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id) { on_update_dialog_administrators(DialogId(chat_id), std::move(administrator_user_ids), chat_full->version != -1); chat_full->is_changed = false; - send_closure( - G()->td(), &Td::send_update, - make_tl_object(chat_id.get(), get_basic_group_full_info_object(chat_full))); + send_closure(G()->td(), &Td::send_update, + make_tl_object(get_basic_group_id_object(chat_id), + get_basic_group_full_info_object(chat_full))); } } @@ -5848,9 +5848,9 @@ void ContactsManager::update_channel_full(ChannelFull *channel_full, ChannelId c channel_full->administrator_count = channel_full->participant_count; } channel_full->is_changed = false; - send_closure( - G()->td(), &Td::send_update, - make_tl_object(channel_id.get(), get_channel_full_info_object(channel_full))); + send_closure(G()->td(), &Td::send_update, + make_tl_object(get_supergroup_id_object(channel_id), + get_channel_full_info_object(channel_full))); } } @@ -9007,6 +9007,18 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U get_bot_info_object(user_full->bot_info.get())); } +int32 ContactsManager::get_basic_group_id_object(ChatId chat_id) 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; + 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, true, 0))); + } + return chat_id.get(); +} + tl_object_ptr ContactsManager::get_basic_group_object(ChatId chat_id) const { return get_basic_group_object(chat_id, get_chat(chat_id)); } @@ -9017,7 +9029,7 @@ tl_object_ptr ContactsManager::get_basic_group_object(ChatId } return make_tl_object( chat_id.get(), chat->participant_count, get_chat_status(chat).get_chat_member_status_object(), - chat->everyone_is_administrator, chat->is_active, chat->migrated_to_channel_id.get()); + chat->everyone_is_administrator, chat->is_active, get_supergroup_id_object(chat->migrated_to_channel_id)); } tl_object_ptr ContactsManager::get_basic_group_full_info_object(ChatId chat_id) const { @@ -9034,6 +9046,18 @@ tl_object_ptr ContactsManager::get_basic_group_full_ chat_full->invite_link); } +int32 ContactsManager::get_supergroup_id_object(ChannelId channel_id) 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; + 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, true, false, ""))); + } + return channel_id.get(); +} + tl_object_ptr ContactsManager::get_supergroup_object(ChannelId channel_id) const { return get_supergroup_object(channel_id, get_channel(channel_id)); } @@ -9061,7 +9085,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(), - channel_full->migrated_from_chat_id.get(), channel_full->migrated_from_max_message_id.get()); + get_basic_group_id_object(channel_full->migrated_from_chat_id), channel_full->migrated_from_max_message_id.get()); } tl_object_ptr ContactsManager::get_secret_chat_state_object(SecretChatState state) { @@ -9079,6 +9103,19 @@ tl_object_ptr ContactsManager::get_secret_chat_state_ob } } +int32 ContactsManager::get_secret_chat_id_object(SecretChatId secret_chat_id) 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; + 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))); + } + return secret_chat_id.get(); +} + tl_object_ptr ContactsManager::get_secret_chat_object(SecretChatId secret_chat_id) { return get_secret_chat_object(secret_chat_id, get_secret_chat(secret_chat_id)); } @@ -9162,7 +9199,7 @@ tl_object_ptr ContactsManager::get_chat_invite_link_ } else { LOG(ERROR) << "Have no information about " << chat_id; } - chat_type = td_api::make_object(chat_id.get()); + chat_type = td_api::make_object(get_basic_group_id_object(chat_id)); } else if (invite_link_info->channel_id != ChannelId()) { CHECK(invite_link_info->chat_id == ChatId()); auto channel_id = invite_link_info->channel_id; @@ -9180,7 +9217,7 @@ tl_object_ptr ContactsManager::get_chat_invite_link_ } else { LOG(ERROR) << "Have no information about " << channel_id; } - chat_type = td_api::make_object(channel_id.get(), !is_megagroup); + chat_type = td_api::make_object(get_supergroup_id_object(channel_id), !is_megagroup); } else { title = invite_link_info->title; photo = &invite_link_info->photo; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 1c3d313b6..55b986d72 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -372,14 +372,20 @@ class ContactsManager : public Actor { tl_object_ptr get_user_full_info_object(UserId user_id) const; + int32 get_basic_group_id_object(ChatId chat_id) const; + tl_object_ptr get_basic_group_object(ChatId chat_id) const; tl_object_ptr get_basic_group_full_info_object(ChatId chat_id) const; + int32 get_supergroup_id_object(ChannelId channel_id) const; + tl_object_ptr get_supergroup_object(ChannelId channel_id) const; tl_object_ptr get_channel_full_info_object(ChannelId channel_id) const; + int32 get_secret_chat_id_object(SecretChatId secret_chat_id) const; + tl_object_ptr get_secret_chat_object(SecretChatId secret_chat_id); void on_update_secret_chat(SecretChatId secret_chat_id, int64 access_hash, UserId user_id, SecretChatState state, @@ -983,12 +989,15 @@ class ContactsManager : public Actor { std::unordered_map chats_; std::unordered_map chats_full_; + mutable std::unordered_set unknown_chats_; std::unordered_set min_channels_; std::unordered_map channels_; std::unordered_map channels_full_; + mutable std::unordered_set unknown_channels_; std::unordered_map secret_chats_; + mutable std::unordered_set unknown_secret_chats_; std::unordered_map, UserIdHash> secret_chats_with_user_; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e319461c0..b752f8d55 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8177,7 +8177,8 @@ tl_object_ptr MessagesManager::get_message_content_objec } case MessageChatMigrateTo::ID: { const MessageChatMigrateTo *m = static_cast(content); - return make_tl_object(m->migrated_to_channel_id.get()); + return make_tl_object( + td_->contacts_manager_->get_supergroup_id_object(m->migrated_to_channel_id)); } case MessageChannelCreate::ID: { const MessageChannelCreate *m = static_cast(content); @@ -8185,7 +8186,8 @@ tl_object_ptr MessagesManager::get_message_content_objec } case MessageChannelMigrateFrom::ID: { const MessageChannelMigrateFrom *m = static_cast(content); - return make_tl_object(m->title, m->migrated_from_chat_id.get()); + return make_tl_object( + m->title, td_->contacts_manager_->get_basic_group_id_object(m->migrated_from_chat_id)); } case MessagePinMessage::ID: { const MessagePinMessage *m = static_cast(content); @@ -11872,18 +11874,21 @@ tl_object_ptr MessagesManager::get_draft_message_object( tl_object_ptr MessagesManager::get_chat_type_object(DialogId dialog_id) const { switch (dialog_id.get_type()) { case DialogType::User: - return make_tl_object(dialog_id.get_user_id().get()); + return make_tl_object( + td_->contacts_manager_->get_user_id_object(dialog_id.get_user_id())); case DialogType::Chat: - return make_tl_object(dialog_id.get_chat_id().get()); + return make_tl_object( + td_->contacts_manager_->get_basic_group_id_object(dialog_id.get_chat_id())); case DialogType::Channel: { auto channel_id = dialog_id.get_channel_id(); auto channel_type = td_->contacts_manager_->get_channel_type(channel_id); - return make_tl_object(channel_id.get(), channel_type != ChannelType::Megagroup); + return make_tl_object(td_->contacts_manager_->get_supergroup_id_object(channel_id), + channel_type != ChannelType::Megagroup); } case DialogType::SecretChat: { auto secret_chat_id = dialog_id.get_secret_chat_id(); auto user_id = td_->contacts_manager_->get_secret_chat_user_id(secret_chat_id); - return make_tl_object(secret_chat_id.get(), + return make_tl_object(td_->contacts_manager_->get_secret_chat_id_object(secret_chat_id), td_->contacts_manager_->get_user_id_object(user_id)); } case DialogType::None: diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 68578b16f..5734bc59a 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -241,7 +241,8 @@ class GetRecentMeUrlsQuery : public Td::ResultHandler { result = nullptr; break; } - result->type_ = make_tl_object(channel_id.get()); + result->type_ = + make_tl_object(td->contacts_manager_->get_supergroup_id_object(channel_id)); break; } case telegram_api::recentMeUrlChatInvite::ID: {