diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index eee8ac7e1..7361373df 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -302,20 +302,27 @@ bool UpdateExtendedMedia( }); } -} // namespace - TextForMimeData WithCaptionClipboardText( const QString &attachType, TextForMimeData &&caption) { auto result = TextForMimeData(); - result.reserve(5 + attachType.size() + caption.expanded.size()); - result.append(u"[ "_q).append(attachType).append(u" ]"_q); - if (!caption.empty()) { - result.append('\n').append(std::move(caption)); + if (attachType.isEmpty()) { + result.reserve(1 + caption.expanded.size()); + if (!caption.empty()) { + result.append(std::move(caption)); + } + } else { + result.reserve(5 + attachType.size() + caption.expanded.size()); + result.append(u"[ "_q).append(attachType).append(u" ]"_q); + if (!caption.empty()) { + result.append('\n').append(std::move(caption)); + } } return result; } +} // namespace + Invoice ComputeInvoiceData( not_null item, const MTPDmessageMediaInvoice &data) { @@ -767,9 +774,7 @@ QString MediaPhoto::pinnedTextSubstring() const { } TextForMimeData MediaPhoto::clipboardText() const { - return WithCaptionClipboardText( - tr::lng_in_dlg_photo(tr::now), - parent()->clipboardText()); + return TextForMimeData(); } bool MediaPhoto::allowsEditCaption() const { @@ -1072,42 +1077,9 @@ QString MediaFile::pinnedTextSubstring() const { } TextForMimeData MediaFile::clipboardText() const { - const auto attachType = [&] { - const auto name = Ui::Text::FormatSongNameFor(_document).string(); - const auto addName = !name.isEmpty() - ? u" : "_q + name - : QString(); - if (const auto sticker = _document->sticker()) { - if (!_emoji.isEmpty()) { - return tr::lng_in_dlg_sticker_emoji( - tr::now, - lt_emoji, - _emoji); - } - return tr::lng_in_dlg_sticker(tr::now); - } else if (_document->isAnimation()) { - if (_document->isVideoMessage()) { - const auto media = parent()->media(); - return (media && media->ttlSeconds()) - ? tr::lng_in_dlg_video_message_ttl(tr::now) - : tr::lng_in_dlg_video_message(tr::now); - } - return u"GIF"_q; - } else if (_document->isVideoFile()) { - return tr::lng_in_dlg_video(tr::now); - } else if (_document->isVoiceMessage()) { - const auto media = parent()->media(); - return ((media && media->ttlSeconds()) - ? tr::lng_in_dlg_voice_message_ttl - : tr::lng_in_dlg_audio)(tr::now) + addName;; - } else if (_document->isSong()) { - return tr::lng_in_dlg_audio_file(tr::now) + addName; - } - return tr::lng_in_dlg_file(tr::now) + addName; - }(); auto caption = parent()->clipboardText(); - if (_document->isVoiceMessage()) { + if (_document->isVoiceMessage() || _document->isVideoMessage()) { const auto &entry = _document->session().api().transcribes().entry( parent()); if (!entry.requestId @@ -1115,17 +1087,18 @@ TextForMimeData MediaFile::clipboardText() const { && !entry.toolong && !entry.failed && (entry.pending || !entry.result.isEmpty())) { - const auto text = "{{\n" + const auto hasCaption = !caption.rich.text.isEmpty(); + const auto text = (hasCaption ? "{{\n" : "") + entry.result + (entry.result.isEmpty() ? "" : " ") + (entry.pending ? "[...]" : "") - + "\n}}" - + (caption.rich.text.isEmpty() ? "" : "\n"); - caption = TextForMimeData{ text, { text } }.append(std::move(caption)); + + (hasCaption ? "\n}}\n" : ""); + caption = TextForMimeData{ text, { text } }.append( + std::move(caption)); } } - return WithCaptionClipboardText(attachType, std::move(caption)); + return caption; } bool MediaFile::allowsEditCaption() const { diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index b2323af8a..1aae67928 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -709,10 +709,6 @@ private: }; -[[nodiscard]] TextForMimeData WithCaptionClipboardText( - const QString &attachType, - TextForMimeData &&caption); - [[nodiscard]] Invoice ComputeInvoiceData( not_null item, const MTPDmessageMediaInvoice &data); diff --git a/Telegram/SourceFiles/history/history_item_text.cpp b/Telegram/SourceFiles/history/history_item_text.cpp index 9bcbee704..1c66c59a4 100644 --- a/Telegram/SourceFiles/history/history_item_text.cpp +++ b/Telegram/SourceFiles/history/history_item_text.cpp @@ -17,15 +17,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_options.h" TextForMimeData HistoryItemText(not_null item) { - auto textResult = item->clipboardText(); + const auto media = item->media(); + + auto mediaResult = media ? media->clipboardText() : TextForMimeData(); + auto textResult = mediaResult.empty() + ? item->clipboardText() + : TextForMimeData(); auto logEntryOriginalResult = [&] { const auto entry = item->Get(); if (!entry) { return TextForMimeData(); } - const auto title = TextUtilities::SingleLine(entry->page->title.isEmpty() - ? entry->page->author - : entry->page->title); + const auto title = TextUtilities::SingleLine( + entry->page->title.isEmpty() + ? entry->page->author + : entry->page->title); auto titleResult = TextForMimeData::Rich( TextUtilities::ParseEntities( title, @@ -41,6 +47,11 @@ TextForMimeData HistoryItemText(not_null item) { return titleResult; }(); auto result = textResult; + if (result.empty()) { + result = std::move(mediaResult); + } else if (!mediaResult.empty()) { + result.append(qstr("\n\n")).append(std::move(mediaResult)); + } if (result.empty()) { result = std::move(logEntryOriginalResult); } else if (!logEntryOriginalResult.empty()) { @@ -78,7 +89,7 @@ TextForMimeData HistoryGroupText(not_null group) { return result; } } - auto caption = [&] { + return [&] { auto &&nonempty = ranges::views::all( group->items ) | ranges::views::filter( @@ -92,7 +103,4 @@ TextForMimeData HistoryGroupText(not_null group) { auto result = (*first)->clipboardText(); return (++first == end) ? result : TextForMimeData(); }(); - return Data::WithCaptionClipboardText( - tr::lng_in_dlg_album(tr::now), - std::move(caption)); }