From 0dc327bd3f8b0312b014622b83cb57dab8ceddf6 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 16 Nov 2022 17:35:12 +0300 Subject: [PATCH] Delete all topics from database when chat is deleted. --- td/telegram/ForumTopicManager.cpp | 12 ++++++++++++ td/telegram/ForumTopicManager.h | 2 ++ td/telegram/MessagesManager.cpp | 3 +++ 3 files changed, 17 insertions(+) diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index cd49120fa..5b84ad590 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -319,6 +319,18 @@ void ForumTopicManager::delete_forum_topic(DialogId dialog_id, MessageId top_thr td_->messages_manager_->delete_topic_history(dialog_id, top_thread_message_id, std::move(promise)); } +void ForumTopicManager::delete_all_dialog_topics(DialogId dialog_id) { + dialog_topics_.erase(dialog_id); + + auto message_thread_db = G()->td_db()->get_message_thread_db_async(); + if (message_thread_db == nullptr) { + return; + } + + LOG(INFO) << "Delete all topics in " << dialog_id << " from database"; + message_thread_db->delete_all_dialog_message_threads(dialog_id, Auto()); +} + void ForumTopicManager::on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id, const ForumTopicEditedData &edited_data) { auto topic = get_topic(dialog_id, top_thread_message_id); diff --git a/td/telegram/ForumTopicManager.h b/td/telegram/ForumTopicManager.h index 219156c26..335c69c6d 100644 --- a/td/telegram/ForumTopicManager.h +++ b/td/telegram/ForumTopicManager.h @@ -48,6 +48,8 @@ class ForumTopicManager final : public Actor { void delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise &&promise); + void delete_all_dialog_topics(DialogId dialog_id); + void on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id, const ForumTopicEditedData &edited_data); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 91f349452..be0e933c7 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -12143,6 +12143,9 @@ void MessagesManager::on_dialog_deleted(DialogId dialog_id, Promise &&prom } close_dialog(d); + + td_->forum_topic_manager_->delete_all_dialog_topics(dialog_id); + promise.set_value(Unit()); }