Merge always 'i' photo size to repair access_hash and file_reference.
GitOrigin-RevId: 0373f4ab6c13cc03d94a839d1191c50f8163618d
This commit is contained in:
parent
31e26a7004
commit
95c0b286a5
@ -2902,22 +2902,50 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
|
||||
need_update = true;
|
||||
}
|
||||
if (old_photo->photos != new_photo->photos) {
|
||||
if (need_merge_files &&
|
||||
(old_photo->photos.size() == 1 || (old_photo->photos.size() == 2 && old_photo->photos[0].type == 't')) &&
|
||||
old_photo->photos.back().type == 'i' && !new_photo->photos.empty()) {
|
||||
LOG(DEBUG) << "Merge photos " << old_photo->photos << " and " << new_photo->photos
|
||||
<< ", need_merge_files = " << need_merge_files;
|
||||
auto new_photos_size = new_photo->photos.size();
|
||||
auto old_photos_size = old_photo->photos.size();
|
||||
|
||||
bool need_merge = false;
|
||||
if (need_merge_files && (old_photos_size == 1 || (old_photos_size == 2 && old_photo->photos[0].type == 't')) &&
|
||||
old_photo->photos.back().type == 'i') {
|
||||
// first time get info about sent photo
|
||||
if (old_photo->photos.size() == 2) {
|
||||
if (old_photos_size == 2) {
|
||||
new_photo->photos.push_back(old_photo->photos[0]);
|
||||
}
|
||||
new_photo->photos.push_back(old_photo->photos.back());
|
||||
need_merge = true;
|
||||
} else {
|
||||
// get sent photo again
|
||||
if (old_photos_size == 2 + new_photos_size && old_photo->photos[new_photos_size].type == 't') {
|
||||
new_photo->photos.push_back(old_photo->photos[new_photos_size]);
|
||||
}
|
||||
if (old_photos_size == 1 + new_photo->photos.size() && old_photo->photos.back().type == 'i') {
|
||||
new_photo->photos.push_back(old_photo->photos.back());
|
||||
need_merge = true;
|
||||
}
|
||||
if (old_photo->photos != new_photo->photos) {
|
||||
new_photo->photos.resize(
|
||||
new_photos_size); // return previous size, because we shouldn't add local photo sizes
|
||||
need_merge = false;
|
||||
need_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (need_merge && new_photos_size != 0) {
|
||||
FileId old_file_id = get_message_content_upload_file_id(old_content);
|
||||
FileView old_file_view = td->file_manager_->get_file_view(old_file_id);
|
||||
FileId new_file_id = new_photo->photos[0].file_id;
|
||||
FileView new_file_view = td->file_manager_->get_file_view(new_file_id);
|
||||
if (!old_file_view.has_remote_location()) {
|
||||
CHECK(new_file_view.has_remote_location());
|
||||
CHECK(!new_file_view.remote_location().is_web());
|
||||
CHECK(new_file_view.has_remote_location());
|
||||
if (new_file_view.remote_location().is_web()) {
|
||||
LOG(ERROR) << "Have remote web photo location";
|
||||
} else if (!old_file_view.has_remote_location() ||
|
||||
old_file_view.remote_location().get_file_reference() !=
|
||||
new_file_view.remote_location().get_file_reference() ||
|
||||
old_file_view.remote_location().get_access_hash() !=
|
||||
new_file_view.remote_location().get_access_hash()) {
|
||||
FileId file_id = td->file_manager_->register_remote(
|
||||
FullRemoteFileLocation({FileType::Photo, 'i'}, new_file_view.remote_location().get_id(),
|
||||
new_file_view.remote_location().get_access_hash(), 0, 0, DcId::invalid(),
|
||||
@ -2926,21 +2954,6 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
|
||||
LOG_STATUS(td->file_manager_->merge(file_id, old_file_id));
|
||||
}
|
||||
}
|
||||
|
||||
// get sent photo again
|
||||
auto new_photos_size = new_photo->photos.size();
|
||||
auto old_photos_size = old_photo->photos.size();
|
||||
if (old_photos_size == 2 + new_photos_size && old_photo->photos[new_photos_size].type == 't') {
|
||||
new_photo->photos.push_back(old_photo->photos[new_photos_size]);
|
||||
}
|
||||
if (old_photos_size == 1 + new_photo->photos.size() && old_photo->photos.back().type == 'i') {
|
||||
new_photo->photos.push_back(old_photo->photos.back());
|
||||
}
|
||||
if (old_photo->photos != new_photo->photos) {
|
||||
new_photo->photos.resize(
|
||||
new_photos_size); // return previous size, because we shouldn't add local photo sizes
|
||||
need_update = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user