Add update_dialog_online_member_count method.
GitOrigin-RevId: 5195f98ab61692355fce12e5ac804cdb2ff66d1a
This commit is contained in:
parent
cda10ecd83
commit
457650ed74
@ -7136,37 +7136,55 @@ void ContactsManager::invalidate_user_full(UserId user_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::update_user_online_member_count(User *u) {
|
void ContactsManager::update_user_online_member_count(User *u) {
|
||||||
if (u->online_member_chats.empty()) {
|
if (u->online_member_dialogs.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto now = G()->unix_time_cached();
|
auto now = G()->unix_time_cached();
|
||||||
vector<ChatId> expired_chat_ids;
|
vector<DialogId> expired_dialog_ids;
|
||||||
for (auto &it : u->online_member_chats) {
|
for (auto &it : u->online_member_dialogs) {
|
||||||
auto chat_id = it.first;
|
auto dialog_id = it.first;
|
||||||
auto time = it.second;
|
auto time = it.second;
|
||||||
if (time < now - MessagesManager::ONLINE_MEMBER_COUNT_CACHE_EXPIRE_TIME) {
|
if (time < now - MessagesManager::ONLINE_MEMBER_COUNT_CACHE_EXPIRE_TIME) {
|
||||||
expired_chat_ids.push_back(chat_id);
|
expired_dialog_ids.push_back(dialog_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (dialog_id.get_type()) {
|
||||||
|
case DialogType::Chat: {
|
||||||
|
auto chat_id = dialog_id.get_chat_id();
|
||||||
auto chat_full = get_chat_full(chat_id);
|
auto chat_full = get_chat_full(chat_id);
|
||||||
CHECK(chat_full != nullptr);
|
CHECK(chat_full != nullptr);
|
||||||
update_chat_online_member_count(chat_full, chat_id, false);
|
update_chat_online_member_count(chat_full, chat_id, false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
for (auto &chat_id : expired_chat_ids) {
|
case DialogType::Channel:
|
||||||
u->online_member_chats.erase(chat_id);
|
break;
|
||||||
|
case DialogType::User:
|
||||||
|
case DialogType::SecretChat:
|
||||||
|
case DialogType::None:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto &dialog_id : expired_dialog_ids) {
|
||||||
|
u->online_member_dialogs.erase(dialog_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server) {
|
void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server) {
|
||||||
|
update_dialog_online_member_count(chat_full->participants, DialogId(chat_id), is_from_server);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactsManager::update_dialog_online_member_count(const vector<DialogParticipant> &participants,
|
||||||
|
DialogId dialog_id, bool is_from_server) {
|
||||||
if (td_->auth_manager_->is_bot()) {
|
if (td_->auth_manager_->is_bot()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 online_member_count = 0;
|
int32 online_member_count = 0;
|
||||||
int32 time = G()->unix_time();
|
int32 time = G()->unix_time();
|
||||||
for (const auto &participant : chat_full->participants) {
|
for (const auto &participant : participants) {
|
||||||
auto u = get_user(participant.user_id);
|
auto u = get_user(participant.user_id);
|
||||||
if (u != nullptr && !u->is_deleted && !u->is_bot) {
|
if (u != nullptr && !u->is_deleted && !u->is_bot) {
|
||||||
int32 was_online = u->was_online;
|
int32 was_online = u->was_online;
|
||||||
@ -7176,10 +7194,10 @@ void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full,
|
|||||||
if (was_online > time) {
|
if (was_online > time) {
|
||||||
online_member_count++;
|
online_member_count++;
|
||||||
}
|
}
|
||||||
u->online_member_chats[chat_id] = time;
|
u->online_member_dialogs[dialog_id] = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
td_->messages_manager_->on_update_dialog_online_member_count(DialogId(chat_id), online_member_count, is_from_server);
|
td_->messages_manager_->on_update_dialog_online_member_count(dialog_id, online_member_count, is_from_server);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::on_get_chat_participants(tl_object_ptr<telegram_api::ChatParticipants> &&participants_ptr) {
|
void ContactsManager::on_get_chat_participants(tl_object_ptr<telegram_api::ChatParticipants> &&participants_ptr) {
|
||||||
|
@ -471,7 +471,7 @@ class ContactsManager : public Actor {
|
|||||||
|
|
||||||
std::unordered_set<int64> photo_ids;
|
std::unordered_set<int64> photo_ids;
|
||||||
|
|
||||||
std::unordered_map<ChatId, int32, ChatIdHash> online_member_chats; // id -> time
|
std::unordered_map<DialogId, int32, DialogIdHash> online_member_dialogs; // id -> time
|
||||||
|
|
||||||
bool is_received = false;
|
bool is_received = false;
|
||||||
bool is_verified = false;
|
bool is_verified = false;
|
||||||
@ -898,6 +898,8 @@ class ContactsManager : public Actor {
|
|||||||
|
|
||||||
void update_user_online_member_count(User *u);
|
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_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server);
|
||||||
|
void update_dialog_online_member_count(const vector<DialogParticipant> &participants, DialogId dialog_id,
|
||||||
|
bool is_from_server);
|
||||||
|
|
||||||
void on_chat_update(telegram_api::chatEmpty &chat, const char *source);
|
void on_chat_update(telegram_api::chatEmpty &chat, const char *source);
|
||||||
void on_chat_update(telegram_api::chat &chat, const char *source);
|
void on_chat_update(telegram_api::chat &chat, const char *source);
|
||||||
|
Loading…
Reference in New Issue
Block a user