aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-06-24 19:09:12 +0300
committerlevlam <levlam@telegram.org>2026-06-24 19:09:12 +0300
commitb78c541f1d12288fead849720fdeeef9f6ebb38f (patch)
tree83938c3d481bdd91f9b4f08192719a7421902663
parent4a247b6dfc4095b715156d8bcab01da7e3a682f0 (diff)
Register forum topic draft files.
-rw-r--r--td/telegram/DraftMessageManager.cpp23
-rw-r--r--td/telegram/DraftMessageManager.h4
-rw-r--r--td/telegram/ForumTopicManager.cpp16
-rw-r--r--td/telegram/ForumTopicManager.h3
4 files changed, 46 insertions, 0 deletions
diff --git a/td/telegram/DraftMessageManager.cpp b/td/telegram/DraftMessageManager.cpp
index 0030b23d8..46a91e249 100644
--- a/td/telegram/DraftMessageManager.cpp
+++ b/td/telegram/DraftMessageManager.cpp
@@ -9,6 +9,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/DialogManager.h"
#include "td/telegram/FileReferenceManager.h"
+#include "td/telegram/files/FileManager.h"
#include "td/telegram/ForumTopicManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageInputReplyTo.h"
@@ -266,4 +267,26 @@ FileSourceId DraftMessageManager::get_draft_message_file_source_id(DialogId dial
return *source_id;
}
+void DraftMessageManager::change_draft_message_files(DialogId dialog_id, const MessageTopic &message_topic,
+ const vector<FileId> &old_file_ids,
+ const vector<FileId> &new_file_ids, bool need_delete_files) {
+ if (new_file_ids == old_file_ids) {
+ return;
+ }
+
+ if (need_delete_files) {
+ for (auto file_id : old_file_ids) {
+ if (!td::contains(new_file_ids, file_id)) {
+ send_closure(G()->file_manager(), &FileManager::delete_file, file_id, Promise<Unit>(),
+ "change_draft_message_files");
+ }
+ }
+ }
+
+ auto file_source_id = get_draft_message_file_source_id(dialog_id, message_topic);
+ if (file_source_id.is_valid()) {
+ td_->file_manager_->change_files_source(file_source_id, old_file_ids, new_file_ids, "change_draft_message_files");
+ }
+}
+
} // namespace td
diff --git a/td/telegram/DraftMessageManager.h b/td/telegram/DraftMessageManager.h
index d8811c372..0481347e1 100644
--- a/td/telegram/DraftMessageManager.h
+++ b/td/telegram/DraftMessageManager.h
@@ -38,6 +38,10 @@ class DraftMessageManager final : public Actor {
FileSourceId get_draft_message_file_source_id(DialogId dialog_id, const MessageTopic &message_topic);
+ void change_draft_message_files(DialogId dialog_id, const MessageTopic &message_topic,
+ const vector<FileId> &old_file_ids, const vector<FileId> &new_file_ids,
+ bool need_delete_files);
+
private:
void tear_down() final;
diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp
index 6588257a5..b4379c575 100644
--- a/td/telegram/ForumTopicManager.cpp
+++ b/td/telegram/ForumTopicManager.cpp
@@ -688,8 +688,11 @@ void ForumTopicManager::on_update_forum_topic_draft_message(DialogId dialog_id,
LOG(DEBUG) << "Ignore update about unknown " << forum_topic_id << " in " << dialog_id;
return;
}
+ auto old_file_ids = get_topic_file_ids(topic);
if (topic->topic_->set_draft_message(std::move(draft_message), true)) {
on_forum_topic_changed(dialog_id, topic);
+ td_->draft_message_manager_->change_draft_message_files(dialog_id, MessageTopic::forum(dialog_id, forum_topic_id),
+ old_file_ids, get_topic_file_ids(topic), true);
}
}
@@ -711,8 +714,11 @@ void ForumTopicManager::clear_forum_topic_draft_by_sent_message(DialogId dialog_
return;
}
}
+ auto old_file_ids = get_topic_file_ids(topic);
if (topic->topic_->set_draft_message(nullptr, false)) {
on_forum_topic_changed(dialog_id, topic);
+ td_->draft_message_manager_->change_draft_message_files(dialog_id, MessageTopic::forum(dialog_id, forum_topic_id),
+ old_file_ids, get_topic_file_ids(topic), false);
}
}
@@ -1171,8 +1177,11 @@ ForumTopicId ForumTopicManager::on_get_forum_topic_impl(DialogId dialog_id,
return ForumTopicId();
}
if (topic->topic_ == nullptr || true) {
+ auto old_file_ids = get_topic_file_ids(topic);
topic->topic_ = std::move(forum_topic_full);
topic->need_save_to_database_ = true; // TODO temporary
+ td_->draft_message_manager_->change_draft_message_files(
+ dialog_id, MessageTopic::forum(dialog_id, forum_topic_id), old_file_ids, get_topic_file_ids(topic), true);
}
topic->receive_date_ = G()->unix_time();
set_topic_info(dialog_id, topic, std::move(forum_topic_info));
@@ -1186,6 +1195,13 @@ ForumTopicId ForumTopicManager::on_get_forum_topic_impl(DialogId dialog_id,
}
}
+vector<FileId> ForumTopicManager::get_topic_file_ids(const Topic *topic) const {
+ if (topic == nullptr || topic->topic_ == nullptr) {
+ return {};
+ }
+ return get_draft_message_file_ids(td_, topic->topic_->get_draft_message());
+}
+
int32 ForumTopicManager::get_forum_topic_id_object(DialogId dialog_id, ForumTopicId forum_topic_id) {
if (forum_topic_id == ForumTopicId()) {
return 0;
diff --git a/td/telegram/ForumTopicManager.h b/td/telegram/ForumTopicManager.h
index 2cf1653e6..2432a5443 100644
--- a/td/telegram/ForumTopicManager.h
+++ b/td/telegram/ForumTopicManager.h
@@ -9,6 +9,7 @@
#include "td/telegram/CustomEmojiId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogNotificationSettings.h"
+#include "td/telegram/files/FileId.h"
#include "td/telegram/ForumTopic.h"
#include "td/telegram/ForumTopicEditedData.h"
#include "td/telegram/ForumTopicId.h"
@@ -205,6 +206,8 @@ class ForumTopicManager final : public Actor {
void on_delete_forum_topic(DialogId dialog_id, ForumTopicId forum_topic_id, Promise<Unit> &&promise);
+ vector<FileId> get_topic_file_ids(const Topic *topic) const;
+
td_api::object_ptr<td_api::forumTopic> get_forum_topic_object(DialogId dialog_id, ForumTopicId forum_topic_id) const;
td_api::object_ptr<td_api::updateForumTopicInfo> get_update_forum_topic_info_object(