Postpone channel status change side effects before channel is loaded from database.

GitOrigin-RevId: 591b017d47920027d97e0a271158e413fac9ab81
This commit is contained in:
levlam 2020-07-07 16:34:47 +03:00
parent bf287039ce
commit abf833e4f3
2 changed files with 32 additions and 13 deletions

View File

@ -7829,15 +7829,21 @@ void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string
} else { } else {
CHECK(!c->is_saved); // channel can't be saved before load completes CHECK(!c->is_saved); // channel can't be saved before load completes
CHECK(!c->is_being_saved); CHECK(!c->is_being_saved);
if (c->participant_count == 0 && !value.empty()) { if (!value.empty()) {
Channel temp_c; Channel temp_c;
log_event_parse(temp_c, value).ensure(); log_event_parse(temp_c, value).ensure();
if (temp_c.participant_count != 0) { if (c->participant_count == 0 && temp_c.participant_count != 0) {
c->participant_count = temp_c.participant_count; c->participant_count = temp_c.participant_count;
CHECK(c->is_update_supergroup_sent); CHECK(c->is_update_supergroup_sent);
send_closure(G()->td(), &Td::send_update, send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateSupergroup>(get_supergroup_object(channel_id, c))); make_tl_object<td_api::updateSupergroup>(get_supergroup_object(channel_id, c)));
} }
c->status.update_restrictions();
temp_c.status.update_restrictions();
if (temp_c.status != c->status) {
on_channel_status_changed(c, channel_id, temp_c.status, c->status);
}
} }
auto new_value = get_channel_database_value(c); auto new_value = get_channel_database_value(c);
if (value != new_value) { if (value != new_value) {
@ -11548,14 +11554,25 @@ void ContactsManager::on_update_channel_title(Channel *c, ChannelId channel_id,
void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status) { void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status) {
if (c->status != status) { if (c->status != status) {
LOG(INFO) << "Update " << channel_id << " status from " << c->status << " to " << status; LOG(INFO) << "Update " << channel_id << " status from " << c->status << " to " << status;
bool is_ownership_transferred = c->status.is_creator() != status.is_creator(); if (c->is_update_supergroup_sent) {
bool drop_invite_link = on_channel_status_changed(c, channel_id, c->status, status);
c->status.is_administrator() != status.is_administrator() || c->status.is_member() != status.is_member(); }
c->status = status; c->status = status;
c->is_status_changed = true; c->is_status_changed = true;
c->is_changed = true; c->is_changed = true;
}
}
void ContactsManager::on_channel_status_changed(Channel *c, ChannelId channel_id,
const DialogParticipantStatus &old_status,
const DialogParticipantStatus &new_status) {
CHECK(c->is_update_supergroup_sent);
bool drop_invite_link = old_status.is_administrator() != new_status.is_administrator() ||
old_status.is_member() != new_status.is_member();
invalidate_channel_full(channel_id, drop_invite_link, !c->is_slow_mode_enabled); invalidate_channel_full(channel_id, drop_invite_link, !c->is_slow_mode_enabled);
if (is_ownership_transferred) {
if (old_status.is_creator() != new_status.is_creator()) {
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
created_public_channels_inited_[i] = false; created_public_channels_inited_[i] = false;
created_public_channels_[i].clear(); created_public_channels_[i].clear();
@ -11564,7 +11581,6 @@ void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id,
send_get_channel_full_query(nullptr, channel_id, Auto(), "update channel owner"); send_get_channel_full_query(nullptr, channel_id, Auto(), "update channel owner");
reload_dialog_administrators(DialogId(channel_id), 0, Auto()); reload_dialog_administrators(DialogId(channel_id), 0, Auto());
} }
}
} }
void ContactsManager::on_update_channel_default_permissions(Channel *c, ChannelId channel_id, void ContactsManager::on_update_channel_default_permissions(Channel *c, ChannelId channel_id,

View File

@ -1161,6 +1161,9 @@ class ContactsManager : public Actor {
void on_update_channel_full_bot_user_ids(ChannelFull *channel_full, ChannelId channel_id, void on_update_channel_full_bot_user_ids(ChannelFull *channel_full, ChannelId channel_id,
vector<UserId> &&bot_user_ids); vector<UserId> &&bot_user_ids);
void on_channel_status_changed(Channel *c, ChannelId channel_id, const DialogParticipantStatus &old_status,
const DialogParticipantStatus &new_status);
void remove_linked_channel_id(ChannelId channel_id); void remove_linked_channel_id(ChannelId channel_id);
ChannelId get_linked_channel_id(ChannelId channel_id) const; ChannelId get_linked_channel_id(ChannelId channel_id) const;