Delete topic from database after it was deleted locally.

This commit is contained in:
levlam 2022-11-16 17:45:47 +03:00
parent 0dc327bd3f
commit b3fe271782
2 changed files with 34 additions and 1 deletions

View File

@ -316,7 +316,25 @@ 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));
auto delete_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, top_thread_message_id,
promise = std::move(promise)](Result<Unit> result) mutable {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
send_closure(actor_id, &ForumTopicManager::on_delete_forum_topic, dialog_id, top_thread_message_id,
std::move(promise));
});
td_->messages_manager_->delete_topic_history(dialog_id, top_thread_message_id, std::move(delete_promise));
}
void ForumTopicManager::on_delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto *dialog_topics = dialog_topics_.get_pointer(dialog_id);
if (dialog_topics != nullptr) {
dialog_topics->topics_.erase(top_thread_message_id);
}
delete_topic_from_database(dialog_id, top_thread_message_id, std::move(promise));
}
void ForumTopicManager::delete_all_dialog_topics(DialogId dialog_id) {
@ -472,6 +490,17 @@ void ForumTopicManager::save_topic_to_database(DialogId dialog_id, const Topic *
message_thread_db->add_message_thread(dialog_id, top_thread_message_id, 0, log_event_store(*topic), Auto());
}
void ForumTopicManager::delete_topic_from_database(DialogId dialog_id, MessageId top_thread_message_id,
Promise<Unit> &&promise) {
auto message_thread_db = G()->td_db()->get_message_thread_db_async();
if (message_thread_db == nullptr) {
return;
}
LOG(INFO) << "Delete topic of " << top_thread_message_id << " in " << dialog_id << " from database";
message_thread_db->delete_message_thread(dialog_id, top_thread_message_id, Auto());
}
void ForumTopicManager::on_topic_message_count_changed(DialogId dialog_id, MessageId top_thread_message_id, int diff) {
if (!can_be_forum(dialog_id) || !top_thread_message_id.is_valid()) {
LOG(ERROR) << "Change by " << diff << " number of loaded messages in thread of " << top_thread_message_id << " in "

View File

@ -98,6 +98,8 @@ class ForumTopicManager final : public Actor {
const ForumTopicInfo *get_topic_info(DialogId dialog_id, MessageId top_thread_message_id) const;
void on_delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
td_api::object_ptr<td_api::updateForumTopicInfo> get_update_forum_topic_info(DialogId dialog_id,
const ForumTopicInfo *topic_info) const;
@ -105,6 +107,8 @@ class ForumTopicManager final : public Actor {
void save_topic_to_database(DialogId dialog_id, const Topic *topic);
void delete_topic_from_database(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
Td *td_;
ActorShared<> parent_;