From 8bfc68b3f858a9083bb4aaf3792aacb6abc557de Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 20 Dec 2022 15:12:36 +0300 Subject: [PATCH] Improve ContactsManager::get_channel_effective_has_hidden_participants. --- td/telegram/ContactsManager.cpp | 16 ++++++++++++---- td/telegram/ContactsManager.h | 2 +- td/telegram/MessagesManager.cpp | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 730aecf30..c88af624c 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13321,7 +13321,7 @@ void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full, } void ContactsManager::update_channel_online_member_count(ChannelId channel_id, bool is_from_server) { - if (!is_megagroup_channel(channel_id) || get_channel_has_hidden_participants(channel_id)) { + if (!is_megagroup_channel(channel_id) || get_channel_effective_has_hidden_participants(channel_id)) { return; } @@ -13566,7 +13566,7 @@ void ContactsManager::on_get_channel_participants( LOG(INFO) << "Receive " << participants.size() << " " << filter << " members in " << channel_id; bool is_full = offset == 0 && static_cast(participants.size()) < limit && total_count < limit; - bool has_hidden_participants = get_channel_has_hidden_participants(channel_id); + bool has_hidden_participants = get_channel_effective_has_hidden_participants(channel_id); bool is_full_recent = is_full && filter.is_recent() && !has_hidden_participants; auto channel_type = get_channel_type(channel_id); @@ -16357,10 +16357,18 @@ int32 ContactsManager::get_channel_slow_mode_delay(ChannelId channel_id) { return channel_full->slow_mode_delay; } -bool ContactsManager::get_channel_has_hidden_participants(ChannelId channel_id) { +bool ContactsManager::get_channel_effective_has_hidden_participants(ChannelId channel_id) { + auto c = get_channel_force(channel_id); + if (c == nullptr) { + return true; + } + if (get_channel_status(c).is_administrator()) { + return false; + } + auto channel_full = get_channel_full_const(channel_id); if (channel_full == nullptr) { - channel_full = get_channel_full_force(channel_id, true, "get_channel_has_hidden_participants"); + channel_full = get_channel_full_force(channel_id, true, "get_channel_effective_has_hidden_participants"); if (channel_full == nullptr) { return true; } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 0f1f50309..b3d918ccb 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -608,7 +608,7 @@ class ContactsManager final : public Actor { bool get_channel_can_be_deleted(ChannelId channel_id) const; ChannelId get_channel_linked_channel_id(ChannelId channel_id); int32 get_channel_slow_mode_delay(ChannelId channel_id); - bool get_channel_has_hidden_participants(ChannelId channel_id); + bool get_channel_effective_has_hidden_participants(ChannelId channel_id); void add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit, Promise &&promise); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7401afe38..9498e4fad 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13074,7 +13074,7 @@ void MessagesManager::on_update_dialog_online_member_count_timeout(DialogId dial if (dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(dialog_id)) { auto participant_count = td_->contacts_manager_->get_channel_participant_count(dialog_id.get_channel_id()); auto has_hidden_participants = - td_->contacts_manager_->get_channel_has_hidden_participants(dialog_id.get_channel_id()); + td_->contacts_manager_->get_channel_effective_has_hidden_participants(dialog_id.get_channel_id()); if (participant_count == 0 || participant_count >= 195 || has_hidden_participants) { td_->create_handler()->send(dialog_id); } else { @@ -18751,7 +18751,7 @@ Status MessagesManager::can_get_message_viewers(DialogId dialog_id, const Messag if (is_broadcast_channel(dialog_id)) { return Status::Error(400, "Can't get message viewers in channel chats"); } - if (td_->contacts_manager_->get_channel_has_hidden_participants(dialog_id.get_channel_id())) { + if (td_->contacts_manager_->get_channel_effective_has_hidden_participants(dialog_id.get_channel_id())) { return Status::Error(400, "Participant list is hidden in the chat"); } participant_count = td_->contacts_manager_->get_channel_participant_count(dialog_id.get_channel_id()); @@ -21613,7 +21613,7 @@ void MessagesManager::open_dialog(Dialog *d) { if (!is_broadcast_channel(dialog_id)) { auto participant_count = td_->contacts_manager_->get_channel_participant_count(channel_id); auto has_hidden_participants = - td_->contacts_manager_->get_channel_has_hidden_participants(dialog_id.get_channel_id()); + td_->contacts_manager_->get_channel_effective_has_hidden_participants(dialog_id.get_channel_id()); if (participant_count < 195 && !has_hidden_participants) { // include unknown participant_count td_->contacts_manager_->get_channel_participants( channel_id, td_api::make_object(), string(), 0, 200, 200, Auto());