From 9b941bae97a9767bac49687646d0b441d9c37c43 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 25 Jul 2022 15:41:05 +0300 Subject: [PATCH] Copy single selected message without author. --- .../history/history_inner_widget.cpp | 33 +++++++++++-------- .../SourceFiles/history/history_item_text.cpp | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 3150be5d7..bca0810ff 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2599,26 +2599,30 @@ TextForMimeData HistoryInner::getSelectedText() const { return TextForMimeData(); } + struct Part { + QString name; + QString time; + TextForMimeData unwrapped; + }; + const auto timeFormat = QString(", [%1 %2]\n") .arg(cDateFormat()) .arg(cTimeFormat()); auto groups = base::flat_set>(); auto fullSize = 0; - auto texts = base::flat_map(); + auto texts = base::flat_map(); const auto wrapItem = [&]( not_null item, TextForMimeData &&unwrapped) { - auto time = ItemDateTime(item).toString(timeFormat); - auto part = TextForMimeData(); - auto size = item->author()->name.size() - + time.size() - + unwrapped.expanded.size(); - part.reserve(size); - part.append(item->author()->name).append(time); - part.append(std::move(unwrapped)); - texts.emplace(item->position(), part); - fullSize += size; + const auto i = texts.emplace(item->position(), Part{ + .name = item->author()->name, + .time = ItemDateTime(item).toString(timeFormat), + .unwrapped = std::move(unwrapped), + }).first; + fullSize += i->second.name.size() + + i->second.time.size() + + i->second.unwrapped.expanded.size(); }; const auto addItem = [&](not_null item) { wrapItem(item, HistoryItemText(item)); @@ -2644,12 +2648,15 @@ TextForMimeData HistoryInner::getSelectedText() const { addItem(item); } } - + if (texts.size() == 1) { + return texts.front().second.unwrapped; + } auto result = TextForMimeData(); const auto sep = qstr("\n\n"); result.reserve(fullSize + (texts.size() - 1) * sep.size()); for (auto i = texts.begin(), e = texts.end(); i != e;) { - result.append(std::move(i->second)); + result.append(i->second.name).append(i->second.time); + result.append(std::move(i->second.unwrapped)); if (++i != e) { result.append(sep); } diff --git a/Telegram/SourceFiles/history/history_item_text.cpp b/Telegram/SourceFiles/history/history_item_text.cpp index b444d84a6..e5abe929e 100644 --- a/Telegram/SourceFiles/history/history_item_text.cpp +++ b/Telegram/SourceFiles/history/history_item_text.cpp @@ -148,7 +148,7 @@ TextForMimeData HistoryGroupText(not_null group) { auto result = (*first)->clipboardText(); return (++first == end) ? result : TextForMimeData(); }(); - return WrapAsItem(group->items.back(), Data::WithCaptionClipboardText( + return WrapAsItem(group->items.front(), Data::WithCaptionClipboardText( tr::lng_in_dlg_album(tr::now), std::move(caption))); }