Probably fix race in reusing notification group.
GitOrigin-RevId: d7359c1d22ad7aecead1844696915c3946c158dc
This commit is contained in:
parent
bcb7a9f6d2
commit
0184df07f3
@ -4390,8 +4390,10 @@ void MessagesManager::save_dialog_to_database(DialogId dialog_id) {
|
|||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
LOG(INFO) << "Save " << dialog_id << " to database";
|
LOG(INFO) << "Save " << dialog_id << " to database";
|
||||||
vector<NotificationGroupKey> changed_group_keys;
|
vector<NotificationGroupKey> changed_group_keys;
|
||||||
|
bool can_reuse_notification_group = false;
|
||||||
auto add_group_key = [&](auto &group_info) {
|
auto add_group_key = [&](auto &group_info) {
|
||||||
if (group_info.is_changed) {
|
if (group_info.is_changed) {
|
||||||
|
can_reuse_notification_group |= group_info.try_reuse;
|
||||||
changed_group_keys.emplace_back(group_info.group_id, group_info.try_reuse ? DialogId() : dialog_id,
|
changed_group_keys.emplace_back(group_info.group_id, group_info.try_reuse ? DialogId() : dialog_id,
|
||||||
group_info.last_notification_date);
|
group_info.last_notification_date);
|
||||||
group_info.is_changed = false;
|
group_info.is_changed = false;
|
||||||
@ -4401,15 +4403,16 @@ void MessagesManager::save_dialog_to_database(DialogId dialog_id) {
|
|||||||
add_group_key(d->mention_notification_group);
|
add_group_key(d->mention_notification_group);
|
||||||
G()->td_db()->get_dialog_db_async()->add_dialog(
|
G()->td_db()->get_dialog_db_async()->add_dialog(
|
||||||
dialog_id, d->order, get_dialog_database_value(d), std::move(changed_group_keys),
|
dialog_id, d->order, get_dialog_database_value(d), std::move(changed_group_keys),
|
||||||
PromiseCreator::lambda([dialog_id](Result<> result) {
|
PromiseCreator::lambda([dialog_id, can_reuse_notification_group](Result<> result) {
|
||||||
send_closure(G()->messages_manager(), &MessagesManager::on_save_dialog_to_database, dialog_id, result.is_ok());
|
send_closure(G()->messages_manager(), &MessagesManager::on_save_dialog_to_database, dialog_id,
|
||||||
|
can_reuse_notification_group, result.is_ok());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::on_save_dialog_to_database(DialogId dialog_id, bool success) {
|
void MessagesManager::on_save_dialog_to_database(DialogId dialog_id, bool can_reuse_notification_group, bool success) {
|
||||||
LOG(INFO) << "Successfully saved " << dialog_id << " to database";
|
LOG(INFO) << "Successfully saved " << dialog_id << " to database";
|
||||||
|
|
||||||
if (success) {
|
if (success && can_reuse_notification_group) {
|
||||||
auto d = get_dialog(dialog_id);
|
auto d = get_dialog(dialog_id);
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
try_reuse_notification_group(d->message_notification_group);
|
try_reuse_notification_group(d->message_notification_group);
|
||||||
@ -4423,11 +4426,11 @@ void MessagesManager::try_reuse_notification_group(NotificationGroupInfo &group_
|
|||||||
if (!group_info.try_reuse) {
|
if (!group_info.try_reuse) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
group_info.try_reuse = false;
|
|
||||||
if (group_info.is_changed) {
|
if (group_info.is_changed) {
|
||||||
LOG(ERROR) << "Failed to reuse changed " << group_info.group_id;
|
LOG(ERROR) << "Failed to reuse changed " << group_info.group_id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
group_info.try_reuse = false;
|
||||||
if (!group_info.group_id.is_valid()) {
|
if (!group_info.group_id.is_valid()) {
|
||||||
LOG(ERROR) << "Failed to reuse invalid " << group_info.group_id;
|
LOG(ERROR) << "Failed to reuse invalid " << group_info.group_id;
|
||||||
return;
|
return;
|
||||||
|
@ -1540,7 +1540,7 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
void save_dialog_to_database(DialogId dialog_id);
|
void save_dialog_to_database(DialogId dialog_id);
|
||||||
|
|
||||||
void on_save_dialog_to_database(DialogId dialog_id, bool success);
|
void on_save_dialog_to_database(DialogId dialog_id, bool can_reuse_notification_group, bool success);
|
||||||
|
|
||||||
void try_reuse_notification_group(NotificationGroupInfo &group_info);
|
void try_reuse_notification_group(NotificationGroupInfo &group_info);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user