Update ChannelFull participant count only after channel is updated.

This commit is contained in:
levlam 2021-01-01 02:45:27 +03:00
parent d9fa3b3f36
commit dbbfcd5d64

View File

@ -13916,10 +13916,10 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
bool is_verified = (channel.flags_ & CHANNEL_FLAG_IS_VERIFIED) != 0;
auto restriction_reasons = get_restriction_reasons(std::move(channel.restriction_reason_));
bool is_scam = (channel.flags_ & CHANNEL_FLAG_IS_SCAM) != 0;
int32 participant_count =
(channel.flags_ & CHANNEL_FLAG_HAS_PARTICIPANT_COUNT) != 0 ? channel.participants_count_ : 0;
bool have_participant_count = (channel.flags_ & CHANNEL_FLAG_HAS_PARTICIPANT_COUNT) != 0;
int32 participant_count = have_participant_count ? channel.participants_count_ : 0;
if (participant_count != 0) {
if (have_participant_count) {
auto channel_full = get_channel_full_const(channel_id);
if (channel_full != nullptr && channel_full->administrator_count > participant_count) {
participant_count = channel_full->administrator_count;
@ -14014,16 +14014,10 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
on_update_channel_default_permissions(c, channel_id,
get_restricted_rights(std::move(channel.default_banned_rights_)));
if (participant_count != 0 && participant_count != c->participant_count) {
bool need_update_participant_count = have_participant_count && participant_count != c->participant_count;
if (need_update_participant_count) {
c->participant_count = participant_count;
c->is_changed = true;
auto channel_full = get_channel_full(channel_id, "on_chat_update");
if (channel_full != nullptr && channel_full->participant_count != participant_count) {
channel_full->participant_count = participant_count;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id);
}
}
bool need_invalidate_channel_full = false;
@ -14054,6 +14048,15 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
c->is_received_from_server = true;
update_channel(c, channel_id);
if (need_update_participant_count) {
auto channel_full = get_channel_full(channel_id, "on_chat_update");
if (channel_full != nullptr && channel_full->participant_count != participant_count) {
channel_full->participant_count = participant_count;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id);
}
}
if (need_invalidate_channel_full) {
invalidate_channel_full(channel_id, false, !c->is_slow_mode_enabled);
}
@ -14139,17 +14142,10 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co
c->is_changed = true;
}
if (c->participant_count != 0) {
bool need_drop_participant_count = c->participant_count != 0;
if (need_drop_participant_count) {
c->participant_count = 0;
c->is_changed = true;
auto channel_full = get_channel_full(channel_id, "on_chat_update");
if (channel_full != nullptr && channel_full->participant_count != 0) {
channel_full->participant_count = 0;
channel_full->administrator_count = 0;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id);
}
}
if (c->cache_version != Channel::CACHE_VERSION) {
@ -14159,6 +14155,15 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co
c->is_received_from_server = true;
update_channel(c, channel_id);
if (need_drop_participant_count) {
auto channel_full = get_channel_full(channel_id, "on_chat_update");
if (channel_full != nullptr && channel_full->participant_count != 0) {
channel_full->participant_count = 0;
channel_full->administrator_count = 0;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id);
}
}
if (need_invalidate_channel_full) {
invalidate_channel_full(channel_id, false, !c->is_slow_mode_enabled);
}