Trying to keep files, needed for messages in other chats.
GitOrigin-RevId: 454f3143aec958a08ea35edecc808ef99eb795cf
This commit is contained in:
parent
8927a862e1
commit
b78db4d902
@ -124,7 +124,7 @@ bool FileReferenceManager::remove_file_source(NodeId node_id, FileSourceId file_
|
||||
return is_removed;
|
||||
}
|
||||
|
||||
std::vector<FileSourceId> FileReferenceManager::get_some_file_sources(NodeId node_id) {
|
||||
vector<FileSourceId> FileReferenceManager::get_some_file_sources(NodeId node_id) {
|
||||
auto it = nodes_.find(node_id);
|
||||
if (it == nodes_.end()) {
|
||||
return {};
|
||||
@ -132,6 +132,21 @@ std::vector<FileSourceId> FileReferenceManager::get_some_file_sources(NodeId nod
|
||||
return it->second.file_source_ids.get_some_elements();
|
||||
}
|
||||
|
||||
vector<FullMessageId> FileReferenceManager::get_some_message_file_sources(NodeId node_id) {
|
||||
auto file_source_ids = get_some_file_sources(node_id);
|
||||
|
||||
vector<FullMessageId> result;
|
||||
for (auto file_source_id : file_source_ids) {
|
||||
auto index = static_cast<size_t>(file_source_id.get()) - 1;
|
||||
CHECK(index < file_sources_.size());
|
||||
const auto &file_source = file_sources_[index];
|
||||
if (file_source.get_offset() == 0) {
|
||||
result.push_back(file_source.get<FileSourceMessage>().full_message_id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) {
|
||||
auto from_it = nodes_.find(from_node_id);
|
||||
if (from_it == nodes_.end()) {
|
||||
|
@ -50,7 +50,9 @@ class FileReferenceManager : public Actor {
|
||||
|
||||
bool add_file_source(NodeId node_id, FileSourceId file_source_id);
|
||||
|
||||
std::vector<FileSourceId> get_some_file_sources(NodeId node_id);
|
||||
vector<FileSourceId> get_some_file_sources(NodeId node_id);
|
||||
|
||||
vector<FullMessageId> get_some_message_file_sources(NodeId node_id);
|
||||
|
||||
bool remove_file_source(NodeId node_id, FileSourceId file_source_id);
|
||||
|
||||
|
@ -8945,7 +8945,7 @@ void MessagesManager::on_message_ttl_expired_impl(Dialog *d, Message *m) {
|
||||
CHECK(m != nullptr);
|
||||
CHECK(m->ttl > 0);
|
||||
CHECK(d->dialog_id.get_type() != DialogType::SecretChat);
|
||||
delete_message_files(m);
|
||||
delete_message_files(d->dialog_id, m);
|
||||
update_expired_message_content(m->content);
|
||||
m->ttl = 0;
|
||||
m->ttl_expires_at = 0;
|
||||
@ -22463,8 +22463,10 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
||||
auto new_file_ids = get_message_content_file_ids(m->content.get(), td_);
|
||||
if (new_file_ids != old_file_ids) {
|
||||
if (need_delete_message_files(d, m)) {
|
||||
FullMessageId full_message_id{dialog_id, message_id};
|
||||
for (auto file_id : old_file_ids) {
|
||||
if (std::find(new_file_ids.begin(), new_file_ids.end(), file_id) == new_file_ids.end()) {
|
||||
if (std::find(new_file_ids.begin(), new_file_ids.end(), file_id) == new_file_ids.end() &&
|
||||
need_delete_file(full_message_id, file_id)) {
|
||||
send_closure(G()->file_manager(), &FileManager::delete_file, file_id, Promise<>(),
|
||||
"edit message in add_message_to_dialog");
|
||||
}
|
||||
@ -23128,10 +23130,23 @@ class MessagesManager::DeleteMessageLogEvent {
|
||||
}
|
||||
};
|
||||
|
||||
void MessagesManager::delete_message_files(const Message *m) const {
|
||||
void MessagesManager::delete_message_files(DialogId dialog_id, const Message *m) const {
|
||||
for (auto file_id : get_message_file_ids(m)) {
|
||||
if (need_delete_file({dialog_id, m->message_id}, file_id)) {
|
||||
send_closure(G()->file_manager(), &FileManager::delete_file, file_id, Promise<>(), "delete_message_files");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MessagesManager::need_delete_file(FullMessageId full_message_id, FileId file_id) const {
|
||||
auto full_message_ids = td_->file_reference_manager_->get_some_message_file_sources(file_id);
|
||||
for (auto other_full_messsage_id : full_message_ids) {
|
||||
if (other_full_messsage_id != full_message_id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MessagesManager::need_delete_message_files(Dialog *d, const Message *m) {
|
||||
@ -23191,7 +23206,7 @@ void MessagesManager::delete_message_from_database(Dialog *d, MessageId message_
|
||||
|
||||
auto need_delete_files = need_delete_message_files(d, m);
|
||||
if (need_delete_files) {
|
||||
delete_message_files(m);
|
||||
delete_message_files(d->dialog_id, m);
|
||||
}
|
||||
|
||||
if (!G()->parameters().use_message_db) {
|
||||
@ -23230,9 +23245,11 @@ void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &lo
|
||||
|
||||
auto lock = mpas.get_promise();
|
||||
for (auto file_id : logevent.file_ids_) {
|
||||
if (need_delete_file(logevent.full_message_id_, file_id)) {
|
||||
send_closure(G()->file_manager(), &FileManager::delete_file, file_id, mpas.get_promise(),
|
||||
"do_delete_message_logevent");
|
||||
}
|
||||
}
|
||||
db_promise = mpas.get_promise();
|
||||
lock.set_value(Unit());
|
||||
}
|
||||
|
@ -1558,6 +1558,8 @@ class MessagesManager : public Actor {
|
||||
|
||||
void on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source);
|
||||
|
||||
bool need_delete_file(FullMessageId full_message_id, FileId file_id) const;
|
||||
|
||||
bool need_delete_message_files(Dialog *d, const Message *m);
|
||||
|
||||
void add_message_to_database(const Dialog *d, const Message *m, const char *source);
|
||||
@ -1566,7 +1568,7 @@ class MessagesManager : public Actor {
|
||||
|
||||
void delete_message_from_database(Dialog *d, MessageId message_id, const Message *m, bool is_permanently_deleted);
|
||||
|
||||
void delete_message_files(const Message *m) const;
|
||||
void delete_message_files(DialogId dialog_id, const Message *m) const;
|
||||
|
||||
static void add_random_id_to_message_id_correspondence(Dialog *d, int64 random_id, MessageId message_id);
|
||||
|
||||
|
Reference in New Issue
Block a user