Add and use FileManager::try_merge_documents.
This commit is contained in:
parent
ce50d0519f
commit
4c72dc8ec5
@ -937,28 +937,7 @@ void BusinessConnectionManager::complete_upload_media(unique_ptr<PendingMessage>
|
|||||||
if (old_content_type != new_content_type) {
|
if (old_content_type != new_content_type) {
|
||||||
need_update = true;
|
need_update = true;
|
||||||
|
|
||||||
auto new_file_id = get_message_content_any_file_id(new_content.get());
|
td_->file_manager_->try_merge_documents(old_file_id, get_message_content_any_file_id(new_content.get()));
|
||||||
if (new_file_id.is_valid()) {
|
|
||||||
FileView old_file_view = td_->file_manager_->get_file_view(old_file_id);
|
|
||||||
FileView new_file_view = td_->file_manager_->get_file_view(new_file_id);
|
|
||||||
// if file type has changed, but file size remains the same, we are trying to update local location of the new
|
|
||||||
// file with the old local location
|
|
||||||
if (old_file_view.has_local_location() && !new_file_view.has_local_location() && old_file_view.size() != 0 &&
|
|
||||||
old_file_view.size() == new_file_view.size()) {
|
|
||||||
auto old_file_type = old_file_view.get_type();
|
|
||||||
auto new_file_type = new_file_view.get_type();
|
|
||||||
|
|
||||||
if (is_document_file_type(old_file_type) && is_document_file_type(new_file_type)) {
|
|
||||||
auto &old_location = old_file_view.local_location();
|
|
||||||
auto r_file_id = td_->file_manager_->register_local(
|
|
||||||
FullLocalFileLocation(new_file_type, old_location.path_, old_location.mtime_nsec_), DialogId(),
|
|
||||||
old_file_view.size());
|
|
||||||
if (r_file_id.is_ok()) {
|
|
||||||
LOG_STATUS(td_->file_manager_->merge(new_file_id, r_file_id.ok()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
merge_message_contents(td_, old_content.get(), new_content.get(), false, DialogId(), true, is_content_changed,
|
merge_message_contents(td_, old_content.get(), new_content.get(), false, DialogId(), true, is_content_changed,
|
||||||
need_update);
|
need_update);
|
||||||
|
@ -34002,28 +34002,7 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (need_merge_files && old_file_id.is_valid()) {
|
if (need_merge_files && old_file_id.is_valid()) {
|
||||||
auto new_file_id = get_message_content_any_file_id(new_content.get());
|
td_->file_manager_->try_merge_documents(old_file_id, get_message_content_any_file_id(new_content.get()));
|
||||||
if (new_file_id.is_valid()) {
|
|
||||||
FileView old_file_view = td_->file_manager_->get_file_view(old_file_id);
|
|
||||||
FileView new_file_view = td_->file_manager_->get_file_view(new_file_id);
|
|
||||||
// if file type has changed, but file size remains the same, we are trying to update local location of the new
|
|
||||||
// file with the old local location
|
|
||||||
if (old_file_view.has_local_location() && !new_file_view.has_local_location() && old_file_view.size() != 0 &&
|
|
||||||
old_file_view.size() == new_file_view.size()) {
|
|
||||||
auto old_file_type = old_file_view.get_type();
|
|
||||||
auto new_file_type = new_file_view.get_type();
|
|
||||||
|
|
||||||
if (is_document_file_type(old_file_type) && is_document_file_type(new_file_type)) {
|
|
||||||
auto &old_location = old_file_view.local_location();
|
|
||||||
auto r_file_id = td_->file_manager_->register_local(
|
|
||||||
FullLocalFileLocation(new_file_type, old_location.path_, old_location.mtime_nsec_), dialog_id,
|
|
||||||
old_file_view.size());
|
|
||||||
if (r_file_id.is_ok()) {
|
|
||||||
LOG_STATUS(td_->file_manager_->merge(new_file_id, r_file_id.ok()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
merge_message_contents(td_, old_content.get(), new_content.get(), need_message_changed_warning(old_message),
|
merge_message_contents(td_, old_content.get(), new_content.get(), need_message_changed_warning(old_message),
|
||||||
|
@ -1903,6 +1903,31 @@ Status FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sync) {
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileManager::try_merge_documents(FileId old_file_id, FileId new_file_id) {
|
||||||
|
if (!old_file_id.is_valid() || !new_file_id.is_valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FileView old_file_view = get_file_view(old_file_id);
|
||||||
|
FileView new_file_view = get_file_view(new_file_id);
|
||||||
|
// if file type has changed, but file size remains the same, we are trying to update local location of the new
|
||||||
|
// file with the old local location
|
||||||
|
if (old_file_view.has_local_location() && !new_file_view.has_local_location() && old_file_view.size() != 0 &&
|
||||||
|
old_file_view.size() == new_file_view.size()) {
|
||||||
|
auto old_file_type = old_file_view.get_type();
|
||||||
|
auto new_file_type = new_file_view.get_type();
|
||||||
|
|
||||||
|
if (is_document_file_type(old_file_type) && is_document_file_type(new_file_type)) {
|
||||||
|
auto &old_location = old_file_view.local_location();
|
||||||
|
auto r_file_id =
|
||||||
|
register_local(FullLocalFileLocation(new_file_type, old_location.path_, old_location.mtime_nsec_), DialogId(),
|
||||||
|
old_file_view.size());
|
||||||
|
if (r_file_id.is_ok()) {
|
||||||
|
LOG_STATUS(merge(new_file_id, r_file_id.ok()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileManager::add_file_source(FileId file_id, FileSourceId file_source_id) {
|
void FileManager::add_file_source(FileId file_id, FileSourceId file_source_id) {
|
||||||
auto node = get_sync_file_node(file_id); // synchronously load the file to preload known file sources
|
auto node = get_sync_file_node(file_id); // synchronously load the file to preload known file sources
|
||||||
if (!node) {
|
if (!node) {
|
||||||
|
@ -472,6 +472,8 @@ class FileManager final : public FileLoadManager::Callback {
|
|||||||
|
|
||||||
Status merge(FileId x_file_id, FileId y_file_id, bool no_sync = false);
|
Status merge(FileId x_file_id, FileId y_file_id, bool no_sync = false);
|
||||||
|
|
||||||
|
void try_merge_documents(FileId old_file_id, FileId new_file_id);
|
||||||
|
|
||||||
void add_file_source(FileId file_id, FileSourceId file_source_id);
|
void add_file_source(FileId file_id, FileSourceId file_source_id);
|
||||||
|
|
||||||
void remove_file_source(FileId file_id, FileSourceId file_source_id);
|
void remove_file_source(FileId file_id, FileSourceId file_source_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user