mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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(
|
TextForMimeData WithCaptionClipboardText(
|
||||||
const QString &attachType,
|
const QString &attachType,
|
||||||
TextForMimeData &&caption) {
|
TextForMimeData &&caption) {
|
||||||
auto result = TextForMimeData();
|
auto result = TextForMimeData();
|
||||||
result.reserve(5 + attachType.size() + caption.expanded.size());
|
if (attachType.isEmpty()) {
|
||||||
result.append(u"[ "_q).append(attachType).append(u" ]"_q);
|
result.reserve(1 + caption.expanded.size());
|
||||||
if (!caption.empty()) {
|
if (!caption.empty()) {
|
||||||
result.append('\n').append(std::move(caption));
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
Invoice ComputeInvoiceData(
|
Invoice ComputeInvoiceData(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
const MTPDmessageMediaInvoice &data) {
|
const MTPDmessageMediaInvoice &data) {
|
||||||
|
@ -767,9 +774,7 @@ QString MediaPhoto::pinnedTextSubstring() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextForMimeData MediaPhoto::clipboardText() const {
|
TextForMimeData MediaPhoto::clipboardText() const {
|
||||||
return WithCaptionClipboardText(
|
return TextForMimeData();
|
||||||
tr::lng_in_dlg_photo(tr::now),
|
|
||||||
parent()->clipboardText());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaPhoto::allowsEditCaption() const {
|
bool MediaPhoto::allowsEditCaption() const {
|
||||||
|
@ -1072,42 +1077,9 @@ QString MediaFile::pinnedTextSubstring() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextForMimeData MediaFile::clipboardText() 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();
|
auto caption = parent()->clipboardText();
|
||||||
|
|
||||||
if (_document->isVoiceMessage()) {
|
if (_document->isVoiceMessage() || _document->isVideoMessage()) {
|
||||||
const auto &entry = _document->session().api().transcribes().entry(
|
const auto &entry = _document->session().api().transcribes().entry(
|
||||||
parent());
|
parent());
|
||||||
if (!entry.requestId
|
if (!entry.requestId
|
||||||
|
@ -1115,17 +1087,18 @@ TextForMimeData MediaFile::clipboardText() const {
|
||||||
&& !entry.toolong
|
&& !entry.toolong
|
||||||
&& !entry.failed
|
&& !entry.failed
|
||||||
&& (entry.pending || !entry.result.isEmpty())) {
|
&& (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
|
||||||
+ (entry.result.isEmpty() ? "" : " ")
|
+ (entry.result.isEmpty() ? "" : " ")
|
||||||
+ (entry.pending ? "[...]" : "")
|
+ (entry.pending ? "[...]" : "")
|
||||||
+ "\n}}"
|
+ (hasCaption ? "\n}}\n" : "");
|
||||||
+ (caption.rich.text.isEmpty() ? "" : "\n");
|
caption = TextForMimeData{ text, { text } }.append(
|
||||||
caption = TextForMimeData{ text, { text } }.append(std::move(caption));
|
std::move(caption));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return WithCaptionClipboardText(attachType, std::move(caption));
|
return caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaFile::allowsEditCaption() const {
|
bool MediaFile::allowsEditCaption() const {
|
||||||
|
|
|
@ -709,10 +709,6 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] TextForMimeData WithCaptionClipboardText(
|
|
||||||
const QString &attachType,
|
|
||||||
TextForMimeData &&caption);
|
|
||||||
|
|
||||||
[[nodiscard]] Invoice ComputeInvoiceData(
|
[[nodiscard]] Invoice ComputeInvoiceData(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
const MTPDmessageMediaInvoice &data);
|
const MTPDmessageMediaInvoice &data);
|
||||||
|
|
|
@ -17,15 +17,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/text/text_options.h"
|
#include "ui/text/text_options.h"
|
||||||
|
|
||||||
TextForMimeData HistoryItemText(not_null<HistoryItem*> item) {
|
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 = [&] {
|
auto logEntryOriginalResult = [&] {
|
||||||
const auto entry = item->Get<HistoryMessageLogEntryOriginal>();
|
const auto entry = item->Get<HistoryMessageLogEntryOriginal>();
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return TextForMimeData();
|
return TextForMimeData();
|
||||||
}
|
}
|
||||||
const auto title = TextUtilities::SingleLine(entry->page->title.isEmpty()
|
const auto title = TextUtilities::SingleLine(
|
||||||
? entry->page->author
|
entry->page->title.isEmpty()
|
||||||
: entry->page->title);
|
? entry->page->author
|
||||||
|
: entry->page->title);
|
||||||
auto titleResult = TextForMimeData::Rich(
|
auto titleResult = TextForMimeData::Rich(
|
||||||
TextUtilities::ParseEntities(
|
TextUtilities::ParseEntities(
|
||||||
title,
|
title,
|
||||||
|
@ -41,6 +47,11 @@ TextForMimeData HistoryItemText(not_null<HistoryItem*> item) {
|
||||||
return titleResult;
|
return titleResult;
|
||||||
}();
|
}();
|
||||||
auto result = textResult;
|
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()) {
|
if (result.empty()) {
|
||||||
result = std::move(logEntryOriginalResult);
|
result = std::move(logEntryOriginalResult);
|
||||||
} else if (!logEntryOriginalResult.empty()) {
|
} else if (!logEntryOriginalResult.empty()) {
|
||||||
|
@ -78,7 +89,7 @@ TextForMimeData HistoryGroupText(not_null<const Data::Group*> group) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto caption = [&] {
|
return [&] {
|
||||||
auto &&nonempty = ranges::views::all(
|
auto &&nonempty = ranges::views::all(
|
||||||
group->items
|
group->items
|
||||||
) | ranges::views::filter(
|
) | ranges::views::filter(
|
||||||
|
@ -92,7 +103,4 @@ TextForMimeData HistoryGroupText(not_null<const Data::Group*> group) {
|
||||||
auto result = (*first)->clipboardText();
|
auto result = (*first)->clipboardText();
|
||||||
return (++first == end) ? result : TextForMimeData();
|
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