diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 8c91d6723..420fbbb59 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -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; }