Update Chat online member count on any participants change.
GitOrigin-RevId: 6049a003d73e86d2bb30b9364a07aa3050be3a7f
This commit is contained in:
parent
b20d9ba6d6
commit
d038c6b5c4
@ -6389,7 +6389,7 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id) {
|
||||
if (chat_full->is_changed) {
|
||||
vector<UserId> administrator_user_ids;
|
||||
vector<UserId> bot_user_ids;
|
||||
for (auto &participant : chat_full->participants) {
|
||||
for (const auto &participant : chat_full->participants) {
|
||||
auto user_id = participant.user_id;
|
||||
if (participant.status.is_administrator()) {
|
||||
administrator_user_ids.push_back(user_id);
|
||||
@ -6661,22 +6661,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
td_->messages_manager_->on_update_dialog_notify_settings(DialogId(chat_id), std::move(chat_full->notify_settings_),
|
||||
"on_get_chat_full");
|
||||
|
||||
int32 online_member_count = 0;
|
||||
int32 time = G()->unix_time();
|
||||
for (auto &participant : chat->participants) {
|
||||
auto u = get_user(participant.user_id);
|
||||
if (u != nullptr) {
|
||||
int32 was_online = u->was_online;
|
||||
if (participant.user_id == get_my_id() && my_was_online_local_ != 0) {
|
||||
was_online = my_was_online_local_;
|
||||
}
|
||||
if (was_online > time) {
|
||||
online_member_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
td_->messages_manager_->on_update_dialog_online_member_count(DialogId(chat_id), online_member_count);
|
||||
|
||||
update_chat_full(chat, chat_id);
|
||||
} else {
|
||||
CHECK(chat_full_ptr->get_id() == telegram_api::channelFull::ID);
|
||||
@ -6767,7 +6751,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
if ((channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_ONLINE_MEMBER_COUNT) != 0) {
|
||||
online_member_count = channel_full->online_count_;
|
||||
}
|
||||
td_->messages_manager_->on_update_dialog_online_member_count(DialogId(channel_id), online_member_count);
|
||||
td_->messages_manager_->on_update_dialog_online_member_count(DialogId(channel_id), online_member_count, true);
|
||||
|
||||
for (auto &bot_info : channel_full->bot_info_) {
|
||||
on_update_bot_info(std::move(bot_info));
|
||||
@ -7137,6 +7121,25 @@ void ContactsManager::invalidate_user_full(UserId user_id) {
|
||||
update_user_full(user_full, user_id);
|
||||
}
|
||||
|
||||
void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id,
|
||||
bool is_from_server) const {
|
||||
int32 online_member_count = 0;
|
||||
int32 time = G()->unix_time();
|
||||
for (const auto &participant : chat_full->participants) {
|
||||
auto u = get_user(participant.user_id);
|
||||
if (u != nullptr) {
|
||||
int32 was_online = u->was_online;
|
||||
if (participant.user_id == get_my_id() && my_was_online_local_ != 0) {
|
||||
was_online = my_was_online_local_;
|
||||
}
|
||||
if (was_online > time) {
|
||||
online_member_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
td_->messages_manager_->on_update_dialog_online_member_count(DialogId(chat_id), online_member_count, is_from_server);
|
||||
}
|
||||
|
||||
void ContactsManager::on_get_chat_participants(tl_object_ptr<telegram_api::ChatParticipants> &&participants_ptr) {
|
||||
switch (participants_ptr->get_id()) {
|
||||
case telegram_api::chatParticipantsForbidden::ID: {
|
||||
@ -7248,8 +7251,8 @@ const DialogParticipant *ContactsManager::get_chat_participant(ChatId chat_id, U
|
||||
return get_chat_participant(chat_full, user_id);
|
||||
}
|
||||
|
||||
const DialogParticipant *ContactsManager::get_chat_participant(const ChatFull *chat_full, UserId user_id) const {
|
||||
for (auto &dialog_participant : chat_full->participants) {
|
||||
const DialogParticipant *ContactsManager::get_chat_participant(const ChatFull *chat_full, UserId user_id) {
|
||||
for (const auto &dialog_participant : chat_full->participants) {
|
||||
if (dialog_participant.user_id == user_id) {
|
||||
return &dialog_participant;
|
||||
}
|
||||
@ -7741,6 +7744,7 @@ void ContactsManager::on_update_chat_add_user(ChatId chat_id, UserId inviter_use
|
||||
user_id == chat_full->creator_user_id
|
||||
? DialogParticipantStatus::Creator(true)
|
||||
: DialogParticipantStatus::Member()});
|
||||
update_chat_online_member_count(chat_full, chat_id, false);
|
||||
chat_full->is_changed = true;
|
||||
update_chat_full(chat_full, chat_id);
|
||||
|
||||
@ -7863,6 +7867,7 @@ void ContactsManager::on_update_chat_delete_user(ChatId chat_id, UserId user_id,
|
||||
chat_full->participants[i] = chat_full->participants.back();
|
||||
chat_full->participants.resize(chat_full->participants.size() - 1);
|
||||
chat_full->is_changed = true;
|
||||
update_chat_online_member_count(chat_full, chat_id, false);
|
||||
update_chat_full(chat_full, chat_id);
|
||||
|
||||
if (static_cast<int>(chat_full->participants.size()) != c->participant_count) {
|
||||
@ -8078,6 +8083,7 @@ void ContactsManager::on_update_chat_full_participants(ChatFull *chat_full, Chat
|
||||
chat_full->participants = std::move(participants);
|
||||
chat_full->version = version;
|
||||
chat_full->is_changed = true;
|
||||
update_chat_online_member_count(chat_full, chat_id, true);
|
||||
}
|
||||
|
||||
void ContactsManager::invalidate_chat_full(ChatId chat_id) {
|
||||
@ -8095,6 +8101,7 @@ void ContactsManager::invalidate_chat_full(ChatId chat_id) {
|
||||
chat_full->participants.clear();
|
||||
chat_full->version = -1;
|
||||
update_invite_link(chat_full->invite_link, nullptr);
|
||||
update_chat_online_member_count(chat_full, chat_id, true);
|
||||
chat_full->is_changed = true;
|
||||
update_chat_full(chat_full, chat_id);
|
||||
}
|
||||
@ -8625,7 +8632,7 @@ ContactsManager::ChatFull *ContactsManager::get_chat_full(ChatId chat_id) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ContactsManager::is_chat_full_outdated(ChatFull *chat_full, Chat *c, ChatId chat_id) {
|
||||
bool ContactsManager::is_chat_full_outdated(const ChatFull *chat_full, const Chat *c, ChatId chat_id) const {
|
||||
CHECK(c != nullptr);
|
||||
CHECK(chat_full != nullptr);
|
||||
if (chat_full->version != c->version) {
|
||||
@ -8634,7 +8641,7 @@ bool ContactsManager::is_chat_full_outdated(ChatFull *chat_full, Chat *c, ChatId
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto &participant : chat_full->participants) {
|
||||
for (const auto &participant : chat_full->participants) {
|
||||
auto user = get_user(participant.user_id);
|
||||
if (user != nullptr && user->bot_info_version != -1) {
|
||||
auto user_full = get_user_full(participant.user_id);
|
||||
@ -9127,7 +9134,7 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_partici
|
||||
};
|
||||
|
||||
vector<UserId> user_ids;
|
||||
for (auto &participant : chat_full->participants) {
|
||||
for (const auto &participant : chat_full->participants) {
|
||||
if (is_dialog_participant_suitable(participant, filter)) {
|
||||
user_ids.push_back(participant.user_id);
|
||||
}
|
||||
|
@ -891,6 +891,7 @@ class ContactsManager : public Actor {
|
||||
void speculative_add_channel_user(ChannelId channel_id, UserId user_id, DialogParticipantStatus status,
|
||||
DialogParticipantStatus old_status);
|
||||
|
||||
void update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server) const;
|
||||
void invalidate_chat_full(ChatId chat_id);
|
||||
|
||||
void on_chat_update(telegram_api::chatEmpty &chat, const char *source);
|
||||
@ -949,7 +950,7 @@ class ContactsManager : public Actor {
|
||||
void update_chat_full(ChatFull *chat_full, ChatId chat_id);
|
||||
void update_channel_full(ChannelFull *channel_full, ChannelId channel_id);
|
||||
|
||||
bool is_chat_full_outdated(ChatFull *chat_full, Chat *c, ChatId chat_id);
|
||||
bool is_chat_full_outdated(const ChatFull *chat_full, const Chat *c, ChatId chat_id) const;
|
||||
|
||||
int32 get_contacts_hash();
|
||||
|
||||
@ -980,7 +981,7 @@ class ContactsManager : public Actor {
|
||||
|
||||
const DialogParticipant *get_chat_participant(ChatId chat_id, UserId user_id) const;
|
||||
|
||||
const DialogParticipant *get_chat_participant(const ChatFull *chat_full, UserId user_id) const;
|
||||
static const DialogParticipant *get_chat_participant(const ChatFull *chat_full, UserId user_id);
|
||||
|
||||
static string get_dialog_administrators_database_key(DialogId dialog_id);
|
||||
|
||||
|
@ -106,12 +106,12 @@ class GetOnlinesQuery : public Td::ResultHandler {
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
td->messages_manager_->on_update_dialog_online_member_count(dialog_id_, result->onlines_);
|
||||
td->messages_manager_->on_update_dialog_online_member_count(dialog_id_, result->onlines_, true);
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetOnlinesQuery");
|
||||
td->messages_manager_->on_update_dialog_online_member_count(dialog_id_, 0);
|
||||
td->messages_manager_->on_update_dialog_online_member_count(dialog_id_, 0, true);
|
||||
}
|
||||
};
|
||||
|
||||
@ -5173,7 +5173,8 @@ void MessagesManager::on_update_channel_max_unavailable_message_id(ChannelId cha
|
||||
"on_update_channel_max_unavailable_message_id");
|
||||
}
|
||||
|
||||
void MessagesManager::on_update_dialog_online_member_count(DialogId dialog_id, int32 online_member_count) {
|
||||
void MessagesManager::on_update_dialog_online_member_count(DialogId dialog_id, int32 online_member_count,
|
||||
bool is_from_server) {
|
||||
if (!dialog_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive online member count in invalid " << dialog_id;
|
||||
return;
|
||||
@ -5190,7 +5191,8 @@ void MessagesManager::on_update_dialog_online_member_count(DialogId dialog_id, i
|
||||
return;
|
||||
}
|
||||
|
||||
set_dialog_online_member_count(dialog_id, online_member_count, "on_update_channel_online_member_count");
|
||||
set_dialog_online_member_count(dialog_id, online_member_count, is_from_server,
|
||||
"on_update_channel_online_member_count");
|
||||
}
|
||||
|
||||
void MessagesManager::on_update_include_sponsored_dialog_to_unread_count() {
|
||||
@ -8568,7 +8570,7 @@ void MessagesManager::set_dialog_max_unavailable_message_id(DialogId dialog_id,
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::set_dialog_online_member_count(DialogId dialog_id, int32 online_member_count,
|
||||
void MessagesManager::set_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, bool is_from_server,
|
||||
const char *source) {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
@ -8590,7 +8592,11 @@ void MessagesManager::set_dialog_online_member_count(DialogId dialog_id, int32 o
|
||||
send_update_chat_online_member_count(dialog_id, online_member_count);
|
||||
}
|
||||
if (d->is_opened) {
|
||||
update_dialog_online_member_count_timeout_.set_timeout_in(dialog_id.get(), ONLINE_MEMBER_COUNT_UPDATE_TIME);
|
||||
if (is_from_server) {
|
||||
update_dialog_online_member_count_timeout_.set_timeout_in(dialog_id.get(), ONLINE_MEMBER_COUNT_UPDATE_TIME);
|
||||
} else {
|
||||
update_dialog_online_member_count_timeout_.add_timeout_in(dialog_id.get(), ONLINE_MEMBER_COUNT_UPDATE_TIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ class MessagesManager : public Actor {
|
||||
|
||||
void on_update_channel_max_unavailable_message_id(ChannelId channel_id, MessageId max_unavailable_message_id);
|
||||
|
||||
void on_update_dialog_online_member_count(DialogId dialog_id, int32 online_member_count);
|
||||
void on_update_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, bool is_from_server);
|
||||
|
||||
void on_update_include_sponsored_dialog_to_unread_count();
|
||||
|
||||
@ -1463,7 +1463,8 @@ class MessagesManager : public Actor {
|
||||
void set_dialog_max_unavailable_message_id(DialogId dialog_id, MessageId max_unavailable_message_id, bool from_update,
|
||||
const char *source);
|
||||
|
||||
void set_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, const char *source);
|
||||
void set_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, bool is_from_server,
|
||||
const char *source);
|
||||
|
||||
void on_update_dialog_online_member_count_timeout(DialogId dialog_id);
|
||||
|
||||
|
Reference in New Issue
Block a user