mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 22:57:11 +02:00
Fixed ability to copy whole transcribed text and copy album captions.
This commit is contained in:
parent
0e571ea679
commit
5d3400033a
3 changed files with 37 additions and 60 deletions
|
@ -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<HistoryItem*> 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 {
|
||||
|
|
|
@ -709,10 +709,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
[[nodiscard]] TextForMimeData WithCaptionClipboardText(
|
||||
const QString &attachType,
|
||||
TextForMimeData &&caption);
|
||||
|
||||
[[nodiscard]] Invoice ComputeInvoiceData(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPDmessageMediaInvoice &data);
|
||||
|
|
|
@ -17,15 +17,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/text/text_options.h"
|
||||
|
||||
TextForMimeData HistoryItemText(not_null<HistoryItem*> 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<HistoryMessageLogEntryOriginal>();
|
||||
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<HistoryItem*> 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<const Data::Group*> group) {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
auto caption = [&] {
|
||||
return [&] {
|
||||
auto &&nonempty = ranges::views::all(
|
||||
group->items
|
||||
) | ranges::views::filter(
|
||||
|
@ -92,7 +103,4 @@ TextForMimeData HistoryGroupText(not_null<const Data::Group*> group) {
|
|||
auto result = (*first)->clipboardText();
|
||||
return (++first == end) ? result : TextForMimeData();
|
||||
}();
|
||||
return Data::WithCaptionClipboardText(
|
||||
tr::lng_in_dlg_album(tr::now),
|
||||
std::move(caption));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue