mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Copy single selected message without author.
This commit is contained in:
parent
813bbba8b7
commit
9b941bae97
2 changed files with 21 additions and 14 deletions
|
@ -2599,26 +2599,30 @@ TextForMimeData HistoryInner::getSelectedText() const {
|
||||||
return TextForMimeData();
|
return TextForMimeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Part {
|
||||||
|
QString name;
|
||||||
|
QString time;
|
||||||
|
TextForMimeData unwrapped;
|
||||||
|
};
|
||||||
|
|
||||||
const auto timeFormat = QString(", [%1 %2]\n")
|
const auto timeFormat = QString(", [%1 %2]\n")
|
||||||
.arg(cDateFormat())
|
.arg(cDateFormat())
|
||||||
.arg(cTimeFormat());
|
.arg(cTimeFormat());
|
||||||
auto groups = base::flat_set<not_null<const Data::Group*>>();
|
auto groups = base::flat_set<not_null<const Data::Group*>>();
|
||||||
auto fullSize = 0;
|
auto fullSize = 0;
|
||||||
auto texts = base::flat_map<Data::MessagePosition, TextForMimeData>();
|
auto texts = base::flat_map<Data::MessagePosition, Part>();
|
||||||
|
|
||||||
const auto wrapItem = [&](
|
const auto wrapItem = [&](
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
TextForMimeData &&unwrapped) {
|
TextForMimeData &&unwrapped) {
|
||||||
auto time = ItemDateTime(item).toString(timeFormat);
|
const auto i = texts.emplace(item->position(), Part{
|
||||||
auto part = TextForMimeData();
|
.name = item->author()->name,
|
||||||
auto size = item->author()->name.size()
|
.time = ItemDateTime(item).toString(timeFormat),
|
||||||
+ time.size()
|
.unwrapped = std::move(unwrapped),
|
||||||
+ unwrapped.expanded.size();
|
}).first;
|
||||||
part.reserve(size);
|
fullSize += i->second.name.size()
|
||||||
part.append(item->author()->name).append(time);
|
+ i->second.time.size()
|
||||||
part.append(std::move(unwrapped));
|
+ i->second.unwrapped.expanded.size();
|
||||||
texts.emplace(item->position(), part);
|
|
||||||
fullSize += size;
|
|
||||||
};
|
};
|
||||||
const auto addItem = [&](not_null<HistoryItem*> item) {
|
const auto addItem = [&](not_null<HistoryItem*> item) {
|
||||||
wrapItem(item, HistoryItemText(item));
|
wrapItem(item, HistoryItemText(item));
|
||||||
|
@ -2644,12 +2648,15 @@ TextForMimeData HistoryInner::getSelectedText() const {
|
||||||
addItem(item);
|
addItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (texts.size() == 1) {
|
||||||
|
return texts.front().second.unwrapped;
|
||||||
|
}
|
||||||
auto result = TextForMimeData();
|
auto result = TextForMimeData();
|
||||||
const auto sep = qstr("\n\n");
|
const auto sep = qstr("\n\n");
|
||||||
result.reserve(fullSize + (texts.size() - 1) * sep.size());
|
result.reserve(fullSize + (texts.size() - 1) * sep.size());
|
||||||
for (auto i = texts.begin(), e = texts.end(); i != e;) {
|
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) {
|
if (++i != e) {
|
||||||
result.append(sep);
|
result.append(sep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ 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 WrapAsItem(group->items.back(), Data::WithCaptionClipboardText(
|
return WrapAsItem(group->items.front(), Data::WithCaptionClipboardText(
|
||||||
tr::lng_in_dlg_album(tr::now),
|
tr::lng_in_dlg_album(tr::now),
|
||||||
std::move(caption)));
|
std::move(caption)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue