From e406d6ea418b78dadaf67e35d7675c42fb845f8c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 12 Mar 2019 14:52:37 +0300 Subject: [PATCH] Update dialog online member count when receive member list. GitOrigin-RevId: e1178f3c5dabc183c80099d0e98e0c0d3cf56762 --- td/telegram/ContactsManager.cpp | 17 +++++++++++++++-- td/telegram/ContactsManager.h | 7 +++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1163f7765..e503af28a 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7176,6 +7176,18 @@ void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full, update_dialog_online_member_count(chat_full->participants, DialogId(chat_id), is_from_server); } +void ContactsManager::update_channel_online_member_count(ChannelId channel_id, bool is_from_server) { + if (get_channel_type(channel_id) != ChannelType::Megagroup) { + return; + } + + auto it = cached_channel_participants_.find(channel_id); + if (it == cached_channel_participants_.end()) { + return; + } + update_dialog_online_member_count(it->second, DialogId(channel_id), is_from_server); +} + void ContactsManager::update_dialog_online_member_count(const vector &participants, DialogId dialog_id, bool is_from_server) { if (td_->auth_manager_->is_bot()) { @@ -7458,7 +7470,6 @@ void ContactsManager::on_get_channel_participants_success( int32 administrator_count = filter.is_administrators() ? total_count : -1; if (offset == 0 && static_cast(participants.size()) < limit && (filter.is_administrators() || filter.is_bots() || filter.is_recent())) { - vector participant_user_ids; vector administrator_user_ids; vector bot_user_ids; { @@ -7472,13 +7483,15 @@ void ContactsManager::on_get_channel_participants_success( bot_user_ids.push_back(participant.user_id); } } - participant_user_ids = std::move(user_ids); administrator_count = administrator_user_ids.size(); } else if (filter.is_administrators()) { administrator_user_ids = std::move(user_ids); } else if (filter.is_bots()) { bot_user_ids = std::move(user_ids); } + + cached_channel_participants_[channel_id] = result; + update_channel_online_member_count(channel_id, true); } if (filter.is_administrators() || filter.is_recent()) { on_update_dialog_administrators(DialogId(channel_id), std::move(administrator_user_ids), true); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 82c01866c..967b74e08 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -172,8 +172,6 @@ class ContactsManager : public Actor { void on_update_dialog_administrators(DialogId dialog_id, vector administrator_user_ids, bool have_access); - static bool speculative_add_count(int32 &count, int32 new_count); - void speculative_add_channel_participants(ChannelId channel_id, int32 new_participant_count, bool by_me); void invalidate_channel_full(ChannelId channel_id, bool drop_invite_link); @@ -891,6 +889,8 @@ class ContactsManager : public Actor { void on_update_channel_full_invite_link(ChannelFull *channel_full, tl_object_ptr &&invite_link_ptr); + static bool speculative_add_count(int32 &count, int32 new_count); + void speculative_add_channel_user(ChannelId channel_id, UserId user_id, DialogParticipantStatus status, DialogParticipantStatus old_status); @@ -898,6 +898,7 @@ class ContactsManager : public Actor { void update_user_online_member_count(User *u); void update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server); + void update_channel_online_member_count(ChannelId channel_id, bool is_from_server); void update_dialog_online_member_count(const vector &participants, DialogId dialog_id, bool is_from_server); @@ -1119,6 +1120,8 @@ class ContactsManager : public Actor { std::unordered_map received_channel_participant_; std::unordered_map>> received_channel_participants_; + std::unordered_map, ChannelIdHash> cached_channel_participants_; + std::unordered_map>> found_blocked_users_; // random_id -> [total_count, [user_id]...]