Repair dialog action bar with delay to not receive outdated data.

GitOrigin-RevId: 74c3cb3ae95e5204153b91fd220b3e6b62bd87df
This commit is contained in:
levlam 2020-03-24 03:47:33 +03:00
parent f0a8af3b2d
commit 302485d673
3 changed files with 32 additions and 30 deletions

View File

@ -526,7 +526,7 @@ class AddContactQuery : public Td::ResultHandler {
void on_error(uint64 id, Status status) override { void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
td->contacts_manager_->reload_contacts(true); td->contacts_manager_->reload_contacts(true);
td->messages_manager_->repair_dialog_action_bar(DialogId(user_id_), "AddContactQuery"); td->messages_manager_->reget_dialog_action_bar(DialogId(user_id_), "AddContactQuery");
} }
}; };
@ -559,7 +559,7 @@ class AcceptContactQuery : public Td::ResultHandler {
void on_error(uint64 id, Status status) override { void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
td->contacts_manager_->reload_contacts(true); td->contacts_manager_->reload_contacts(true);
td->messages_manager_->repair_dialog_action_bar(DialogId(user_id_), "AcceptContactQuery"); td->messages_manager_->reget_dialog_action_bar(DialogId(user_id_), "AcceptContactQuery");
} }
}; };
@ -4209,7 +4209,7 @@ void ContactsManager::on_set_user_is_blocked_failed(UserId user_id, bool is_bloc
LOG(WARNING) << "Receive error for SetUserIsBlockedQuery: " << error; LOG(WARNING) << "Receive error for SetUserIsBlockedQuery: " << error;
on_update_user_is_blocked(user_id, !is_blocked); on_update_user_is_blocked(user_id, !is_blocked);
reload_user_full(user_id); reload_user_full(user_id);
td_->messages_manager_->repair_dialog_action_bar(DialogId(user_id), "on_set_user_is_blocked_failed"); td_->messages_manager_->reget_dialog_action_bar(DialogId(user_id), "on_set_user_is_blocked_failed");
} }
bool ContactsManager::is_valid_username(const string &username) { bool ContactsManager::is_valid_username(const string &username) {

View File

@ -3441,7 +3441,7 @@ class UpdatePeerSettingsQuery : public Td::ResultHandler {
void on_error(uint64 id, Status status) override { void on_error(uint64 id, Status status) override {
LOG(INFO) << "Receive error for update peer settings: " << status; LOG(INFO) << "Receive error for update peer settings: " << status;
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "UpdatePeerSettingsQuery"); td->messages_manager_->on_get_dialog_error(dialog_id_, status, "UpdatePeerSettingsQuery");
td->messages_manager_->repair_dialog_action_bar(dialog_id_, "UpdatePeerSettingsQuery"); td->messages_manager_->reget_dialog_action_bar(dialog_id_, "UpdatePeerSettingsQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -3482,7 +3482,7 @@ class ReportEncryptedSpamQuery : public Td::ResultHandler {
void on_error(uint64 id, Status status) override { void on_error(uint64 id, Status status) override {
LOG(INFO) << "Receive error for report encrypted spam: " << status; LOG(INFO) << "Receive error for report encrypted spam: " << status;
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportEncryptedSpamQuery"); td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportEncryptedSpamQuery");
td->messages_manager_->repair_dialog_action_bar( td->messages_manager_->reget_dialog_action_bar(
DialogId(td->contacts_manager_->get_secret_chat_user_id(dialog_id_.get_secret_chat_id())), DialogId(td->contacts_manager_->get_secret_chat_user_id(dialog_id_.get_secret_chat_id())),
"ReportEncryptedSpamQuery"); "ReportEncryptedSpamQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
@ -3533,7 +3533,7 @@ class ReportPeerQuery : public Td::ResultHandler {
void on_error(uint64 id, Status status) override { void on_error(uint64 id, Status status) override {
LOG(INFO) << "Receive error for report peer: " << status; LOG(INFO) << "Receive error for report peer: " << status;
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportPeerQuery"); td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportPeerQuery");
td->messages_manager_->repair_dialog_action_bar(dialog_id_, "ReportPeerQuery"); td->messages_manager_->reget_dialog_action_bar(dialog_id_, "ReportPeerQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -6802,12 +6802,12 @@ bool MessagesManager::update_dialog_silent_send_message(Dialog *d, bool silent_s
return true; return true;
} }
void MessagesManager::repair_dialog_action_bar(DialogId dialog_id, const char *source) { void MessagesManager::reget_dialog_action_bar(DialogId dialog_id, const char *source) {
if (G()->close_flag() || !dialog_id.is_valid() || td_->auth_manager_->is_bot()) { if (G()->close_flag() || !dialog_id.is_valid() || td_->auth_manager_->is_bot()) {
return; return;
} }
LOG(INFO) << "Repair action bar in " << dialog_id << " from " << source; LOG(INFO) << "Reget action bar in " << dialog_id << " from " << source;
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: case DialogType::User:
td_->contacts_manager_->reload_user_full(dialog_id.get_user_id()); td_->contacts_manager_->reload_user_full(dialog_id.get_user_id());
@ -6826,6 +6826,21 @@ void MessagesManager::repair_dialog_action_bar(DialogId dialog_id, const char *s
} }
} }
void MessagesManager::repair_dialog_action_bar(Dialog *d, const char *source) {
CHECK(d != nullptr);
auto dialog_id = d->dialog_id;
d->know_action_bar = false;
if (have_input_peer(dialog_id, AccessRights::Read)) {
create_actor<SleepActor>("RepairDialogActionBarActor", 1.0,
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, source](Result<Unit> result) {
send_closure(actor_id, &MessagesManager::reget_dialog_action_bar, dialog_id, source);
}))
.release();
}
// there is no need to change action bar
on_dialog_updated(dialog_id, source);
}
void MessagesManager::hide_dialog_action_bar(DialogId dialog_id) { void MessagesManager::hide_dialog_action_bar(DialogId dialog_id) {
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) { if (d == nullptr) {
@ -15205,7 +15220,7 @@ void MessagesManager::open_dialog(Dialog *d) {
break; break;
case DialogType::Chat: case DialogType::Chat:
td_->contacts_manager_->repair_chat_participants(dialog_id.get_chat_id()); td_->contacts_manager_->repair_chat_participants(dialog_id.get_chat_id());
repair_dialog_action_bar(dialog_id, "open_dialog"); reget_dialog_action_bar(dialog_id, "open_dialog");
break; break;
case DialogType::Channel: case DialogType::Channel:
if (!is_broadcast_channel(dialog_id)) { if (!is_broadcast_channel(dialog_id)) {
@ -15218,7 +15233,7 @@ void MessagesManager::open_dialog(Dialog *d) {
} }
} }
get_channel_difference(dialog_id, d->pts, true, "open_dialog"); get_channel_difference(dialog_id, d->pts, true, "open_dialog");
repair_dialog_action_bar(dialog_id, "open_dialog"); reget_dialog_action_bar(dialog_id, "open_dialog");
break; break;
case DialogType::SecretChat: { case DialogType::SecretChat: {
// to repair dialog action bar // to repair dialog action bar
@ -24022,12 +24037,7 @@ void MessagesManager::on_dialog_user_is_contact_updated(DialogId dialog_id, bool
send_update_chat_action_bar(d); send_update_chat_action_bar(d);
} }
} else { } else {
d->know_action_bar = false; repair_dialog_action_bar(d, "on_dialog_user_is_contact_updated");
if (have_input_peer(dialog_id, AccessRights::Read)) {
repair_dialog_action_bar(dialog_id, "on_dialog_user_is_contact_updated");
}
// there is no need to change action bar
on_dialog_updated(dialog_id, "on_dialog_user_is_contact_updated");
} }
} }
} }
@ -24047,12 +24057,7 @@ void MessagesManager::on_dialog_user_is_blocked_updated(DialogId dialog_id, bool
send_update_chat_action_bar(d); send_update_chat_action_bar(d);
} }
} else { } else {
d->know_action_bar = false; repair_dialog_action_bar(d, "on_dialog_user_is_blocked_updated");
if (have_input_peer(dialog_id, AccessRights::Read)) {
repair_dialog_action_bar(dialog_id, "on_dialog_user_is_blocked_updated");
}
// there is no need to change action bar
on_dialog_updated(dialog_id, "on_dialog_user_is_blocked_updated");
} }
} }
} }
@ -24071,12 +24076,7 @@ void MessagesManager::on_dialog_user_is_deleted_updated(DialogId dialog_id, bool
send_update_chat_action_bar(d); send_update_chat_action_bar(d);
} }
} else { } else {
d->know_action_bar = false; repair_dialog_action_bar(d, "on_dialog_user_is_deleted_updated");
if (have_input_peer(dialog_id, AccessRights::Read)) {
repair_dialog_action_bar(dialog_id, "on_dialog_user_is_deleted_updated");
}
// there is no need to change action bar
on_dialog_updated(dialog_id, "on_dialog_user_is_deleted_updated");
} }
} }
} }
@ -27852,7 +27852,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
force_create_dialog(DialogId(user_id), "add chat with user to load/store action_bar"); force_create_dialog(DialogId(user_id), "add chat with user to load/store action_bar");
} }
} else { } else {
repair_dialog_action_bar(dialog_id, "fix_new_dialog"); reget_dialog_action_bar(dialog_id, "fix_new_dialog");
} }
} }

View File

@ -699,7 +699,7 @@ class MessagesManager : public Actor {
void remove_dialog_action_bar(DialogId dialog_id, Promise<Unit> &&promise); void remove_dialog_action_bar(DialogId dialog_id, Promise<Unit> &&promise);
void repair_dialog_action_bar(DialogId dialog_id, const char *source); void reget_dialog_action_bar(DialogId dialog_id, const char *source);
void report_dialog(DialogId dialog_id, const tl_object_ptr<td_api::ChatReportReason> &reason, void report_dialog(DialogId dialog_id, const tl_object_ptr<td_api::ChatReportReason> &reason,
const vector<MessageId> &message_ids, Promise<Unit> &&promise); const vector<MessageId> &message_ids, Promise<Unit> &&promise);
@ -1933,6 +1933,8 @@ class MessagesManager : public Actor {
void send_update_chat_has_scheduled_messages(Dialog *d, bool from_deletion); void send_update_chat_has_scheduled_messages(Dialog *d, bool from_deletion);
void repair_dialog_action_bar(Dialog *d, const char *source);
void hide_dialog_action_bar(Dialog *d); void hide_dialog_action_bar(Dialog *d);
static Result<int32> get_message_schedule_date(td_api::object_ptr<td_api::MessageSchedulingState> &&scheduling_state); static Result<int32> get_message_schedule_date(td_api::object_ptr<td_api::MessageSchedulingState> &&scheduling_state);