From 625359f18f05e0a2225089e92b25918f6dd79abd Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 17 Mar 2019 00:35:00 +0300 Subject: [PATCH] Try repair failed to reuse notification group id. GitOrigin-RevId: e7d5681c35f0f3838612c8f1ba0f2728d0f7b492 --- td/telegram/MessagesManager.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 211f1dd82..5f3c4b140 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -18201,6 +18201,26 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat if (d == nullptr) { return MessageNotificationGroup(); } + if (d->message_notification_group.group_id != group_id && d->mention_notification_group.group_id != group_id) { + if (d->dialog_id.get_type() == DialogType::SecretChat && !d->message_notification_group.group_id.is_valid() && + !d->mention_notification_group.group_id.is_valid()) { + // the group was reused, but wasn't deleted from the database, trying to resave it + auto &group_info = d->message_notification_group; + group_info.group_id = group_id; + group_info.is_changed = true; + group_info.try_reuse = true; + save_dialog_to_database(d->dialog_id); + group_info.group_id = NotificationGroupId(); + group_info.is_changed = false; + group_info.try_reuse = false; + + if (Random::fast(0, 9) > 0) { + // allow crash with probability 10% if resaving doesn't help + return MessageNotificationGroup(); + } + } + } + LOG_CHECK(d->message_notification_group.group_id == group_id || d->mention_notification_group.group_id == group_id) << group_id << " " << d->message_notification_group.group_id << " " << d->mention_notification_group.group_id << " " << d->dialog_id << " " << notification_group_id_to_dialog_id_[group_id] << " "