Don't dup file identifiers in forwarded messages.

This commit is contained in:
levlam 2024-07-02 14:58:25 +03:00
parent 35cfcf5d15
commit 91b8c93a81

View File

@ -6558,7 +6558,10 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
bool to_secret = dialog_id.get_type() == DialogType::SecretChat;
auto fix_file_id = [dialog_id, to_secret, file_manager = td->file_manager_.get()](FileId file_id) {
bool need_dup = type != MessageContentDupType::ServerCopy && type != MessageContentDupType::Forward;
CHECK(!to_secret || need_dup);
auto fix_file_id = [dialog_id, to_secret, need_dup, file_manager = td->file_manager_.get()](FileId file_id) {
CHECK(need_dup);
auto file_view = file_manager->get_file_view(file_id);
if (to_secret && !file_view.is_encrypted_secret()) {
file_id = file_manager->copy_file_id(file_id, FileType::Encrypted, dialog_id, "copy message content to secret");
@ -6578,7 +6581,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
if (!need_dup || td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->animations_manager_->dup_animation(fix_file_id(result->file_id), result->file_id);
@ -6590,7 +6593,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
if (!need_dup || td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->audios_manager_->dup_audio(fix_file_id(result->file_id), result->file_id);
@ -6611,7 +6614,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
if (!need_dup || td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->documents_manager_->dup_document(fix_file_id(result->file_id), result->file_id);
@ -6667,12 +6670,12 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
CHECK(!result->photo.photos.empty());
if ((result->photo.photos.size() > 2 || result->photo.photos.back().type != 'i') && !to_secret) {
if ((!need_dup || result->photo.photos.size() > 2 || result->photo.photos.back().type != 'i') && !to_secret) {
// already sent photo
// having remote location is not enough to have InputMedia, because the file may not have valid file_reference
// also file_id needs to be duped, because upload can be called to repair the file_reference and every upload
// request must have unique file_id
if (!td->auth_manager_->is_bot() && type != MessageContentDupType::Forward) {
if (!td->auth_manager_->is_bot() && need_dup) {
result->photo.photos.back().file_id = fix_file_id(result->photo.photos.back().file_id);
}
return std::move(result);
@ -6701,7 +6704,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
case MessageContentType::Sticker: {
auto result = make_unique<MessageSticker>(*static_cast<const MessageSticker *>(content));
result->is_premium = td->option_manager_->get_option_boolean("is_premium");
if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) {
if (!need_dup || td->stickers_manager_->has_input_media(result->file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->stickers_manager_->dup_sticker(fix_file_id(result->file_id), result->file_id);
@ -6724,7 +6727,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
if (!need_dup || td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->videos_manager_->dup_video(fix_file_id(result->file_id), result->file_id);
@ -6734,7 +6737,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
case MessageContentType::VideoNote: {
auto result = make_unique<MessageVideoNote>(*static_cast<const MessageVideoNote *>(content));
result->is_viewed = false;
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
if (!need_dup || td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->video_notes_manager_->dup_video_note(fix_file_id(result->file_id), result->file_id);
@ -6747,7 +6750,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
result->caption = std::move(copy_options.new_caption);
}
result->is_listened = false;
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
if (!need_dup || td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
}
result->file_id = td->voice_notes_manager_->dup_voice_note(fix_file_id(result->file_id), result->file_id);