Send update with unknown basic group/supergroup/secret chat when its identifier is returned.

GitOrigin-RevId: e3c0d7904f02b79abdcbf990db1bdcf8d67591e3
This commit is contained in:
levlam 2018-01-27 16:57:59 +03:00
parent 083eba265b
commit 0e41d96335
5 changed files with 74 additions and 22 deletions

View File

@ -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

View File

@ -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<td_api::updateBasicGroupFullInfo>(chat_id.get(), get_basic_group_full_info_object(chat_full)));
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateBasicGroupFullInfo>(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<td_api::updateSupergroupFullInfo>(channel_id.get(), get_channel_full_info_object(channel_full)));
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateSupergroupFullInfo>(get_supergroup_id_object(channel_id),
get_channel_full_info_object(channel_full)));
}
}
@ -9007,6 +9007,18 @@ tl_object_ptr<td_api::userFullInfo> 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::updateBasicGroup>(td_api::make_object<td_api::basicGroup>(
chat_id.get(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), true, true, 0)));
}
return chat_id.get();
}
tl_object_ptr<td_api::basicGroup> 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<td_api::basicGroup> ContactsManager::get_basic_group_object(ChatId
}
return make_tl_object<td_api::basicGroup>(
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<td_api::basicGroupFullInfo> ContactsManager::get_basic_group_full_info_object(ChatId chat_id) const {
@ -9034,6 +9046,18 @@ tl_object_ptr<td_api::basicGroupFullInfo> 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::updateSupergroup>(td_api::make_object<td_api::supergroup>(
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<td_api::supergroup> 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<td_api::supergroupFullInfo> 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<td_api::SecretChatState> ContactsManager::get_secret_chat_state_object(SecretChatState state) {
@ -9079,6 +9103,19 @@ tl_object_ptr<td_api::SecretChatState> 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::updateSecretChat>(td_api::make_object<td_api::secretChat>(
secret_chat_id.get(), 0, get_secret_chat_state_object(SecretChatState::Unknown), false, 0, string(), 0)));
}
return secret_chat_id.get();
}
tl_object_ptr<td_api::secretChat> 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<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
} else {
LOG(ERROR) << "Have no information about " << chat_id;
}
chat_type = td_api::make_object<td_api::chatTypeBasicGroup>(chat_id.get());
chat_type = td_api::make_object<td_api::chatTypeBasicGroup>(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<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
} else {
LOG(ERROR) << "Have no information about " << channel_id;
}
chat_type = td_api::make_object<td_api::chatTypeSupergroup>(channel_id.get(), !is_megagroup);
chat_type = td_api::make_object<td_api::chatTypeSupergroup>(get_supergroup_id_object(channel_id), !is_megagroup);
} else {
title = invite_link_info->title;
photo = &invite_link_info->photo;

View File

@ -372,14 +372,20 @@ class ContactsManager : public Actor {
tl_object_ptr<td_api::userFullInfo> get_user_full_info_object(UserId user_id) const;
int32 get_basic_group_id_object(ChatId chat_id) const;
tl_object_ptr<td_api::basicGroup> get_basic_group_object(ChatId chat_id) const;
tl_object_ptr<td_api::basicGroupFullInfo> get_basic_group_full_info_object(ChatId chat_id) const;
int32 get_supergroup_id_object(ChannelId channel_id) const;
tl_object_ptr<td_api::supergroup> get_supergroup_object(ChannelId channel_id) const;
tl_object_ptr<td_api::supergroupFullInfo> get_channel_full_info_object(ChannelId channel_id) const;
int32 get_secret_chat_id_object(SecretChatId secret_chat_id) const;
tl_object_ptr<td_api::secretChat> 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<ChatId, Chat, ChatIdHash> chats_;
std::unordered_map<ChatId, ChatFull, ChatIdHash> chats_full_;
mutable std::unordered_set<ChatId, ChatIdHash> unknown_chats_;
std::unordered_set<ChannelId, ChannelIdHash> min_channels_;
std::unordered_map<ChannelId, Channel, ChannelIdHash> channels_;
std::unordered_map<ChannelId, ChannelFull, ChannelIdHash> channels_full_;
mutable std::unordered_set<ChannelId, ChannelIdHash> unknown_channels_;
std::unordered_map<SecretChatId, SecretChat, SecretChatIdHash> secret_chats_;
mutable std::unordered_set<SecretChatId, SecretChatIdHash> unknown_secret_chats_;
std::unordered_map<UserId, vector<SecretChatId>, UserIdHash> secret_chats_with_user_;

View File

@ -8177,7 +8177,8 @@ tl_object_ptr<td_api::MessageContent> MessagesManager::get_message_content_objec
}
case MessageChatMigrateTo::ID: {
const MessageChatMigrateTo *m = static_cast<const MessageChatMigrateTo *>(content);
return make_tl_object<td_api::messageChatUpgradeTo>(m->migrated_to_channel_id.get());
return make_tl_object<td_api::messageChatUpgradeTo>(
td_->contacts_manager_->get_supergroup_id_object(m->migrated_to_channel_id));
}
case MessageChannelCreate::ID: {
const MessageChannelCreate *m = static_cast<const MessageChannelCreate *>(content);
@ -8185,7 +8186,8 @@ tl_object_ptr<td_api::MessageContent> MessagesManager::get_message_content_objec
}
case MessageChannelMigrateFrom::ID: {
const MessageChannelMigrateFrom *m = static_cast<const MessageChannelMigrateFrom *>(content);
return make_tl_object<td_api::messageChatUpgradeFrom>(m->title, m->migrated_from_chat_id.get());
return make_tl_object<td_api::messageChatUpgradeFrom>(
m->title, td_->contacts_manager_->get_basic_group_id_object(m->migrated_from_chat_id));
}
case MessagePinMessage::ID: {
const MessagePinMessage *m = static_cast<const MessagePinMessage *>(content);
@ -11872,18 +11874,21 @@ tl_object_ptr<td_api::draftMessage> MessagesManager::get_draft_message_object(
tl_object_ptr<td_api::ChatType> MessagesManager::get_chat_type_object(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
return make_tl_object<td_api::chatTypePrivate>(dialog_id.get_user_id().get());
return make_tl_object<td_api::chatTypePrivate>(
td_->contacts_manager_->get_user_id_object(dialog_id.get_user_id()));
case DialogType::Chat:
return make_tl_object<td_api::chatTypeBasicGroup>(dialog_id.get_chat_id().get());
return make_tl_object<td_api::chatTypeBasicGroup>(
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<td_api::chatTypeSupergroup>(channel_id.get(), channel_type != ChannelType::Megagroup);
return make_tl_object<td_api::chatTypeSupergroup>(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<td_api::chatTypeSecret>(secret_chat_id.get(),
return make_tl_object<td_api::chatTypeSecret>(td_->contacts_manager_->get_secret_chat_id_object(secret_chat_id),
td_->contacts_manager_->get_user_id_object(user_id));
}
case DialogType::None:

View File

@ -241,7 +241,8 @@ class GetRecentMeUrlsQuery : public Td::ResultHandler {
result = nullptr;
break;
}
result->type_ = make_tl_object<td_api::tMeUrlTypeSupergroup>(channel_id.get());
result->type_ =
make_tl_object<td_api::tMeUrlTypeSupergroup>(td->contacts_manager_->get_supergroup_id_object(channel_id));
break;
}
case telegram_api::recentMeUrlChatInvite::ID: {