diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index bbb363dc5e6d0..4eb403263838a 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -370,8 +370,10 @@ std::vector ParseReactions(const MTPMessageReactions &data) { for (const auto &single : data.data().vresults().v) { auto reaction = ParseReaction(single.data().vreaction()); reaction.count = single.data().vcount().v; - auto id = Reaction::Id(reaction); - auto const &[_, inserted] = reactionsMap.try_emplace(id, reaction); + const auto id = Reaction::Id(reaction); + auto const &[_, inserted] = reactionsMap.try_emplace( + id, + std::move(reaction)); if (inserted) { reactionsOrder.push_back(id); } @@ -380,8 +382,10 @@ std::vector ParseReactions(const MTPMessageReactions &data) { if (const auto list = data.data().vrecent_reactions()) { for (const auto &single : list->v) { auto reaction = ParseReaction(single.data().vreaction()); - auto id = Reaction::Id(reaction); - auto const &[it, inserted] = reactionsMap.try_emplace(id, reaction); + const auto id = Reaction::Id(reaction); + auto const &[it, inserted] = reactionsMap.try_emplace( + id, + std::move(reaction)); if (inserted) { reactionsOrder.push_back(id); } @@ -392,11 +396,11 @@ std::vector ParseReactions(const MTPMessageReactions &data) { } } } - std::vector results; - for (const auto &id : reactionsOrder) { - results.push_back(reactionsMap[id]); - } - return results; + return ranges::views::all( + reactionsOrder + ) | ranges::views::transform([&](const Utf8String &id) { + return reactionsMap.at(id); + }) | ranges::to_vector; } Utf8String FillLeft(const Utf8String &data, int length, char filler) { diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h index 7d6c2e6681722..d07b4de559fad 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.h +++ b/Telegram/SourceFiles/export/data/export_data_types.h @@ -709,10 +709,10 @@ struct Reaction { CustomEmoji, Paid, }; - - static Utf8String TypeToString(const Reaction &); - static Utf8String Id(const Reaction &); + [[nodiscard]] static Utf8String TypeToString(const Reaction &); + + [[nodiscard]] static Utf8String Id(const Reaction &); struct Recent { PeerId peerId = 0; diff --git a/Telegram/SourceFiles/export/export_api_wrap.cpp b/Telegram/SourceFiles/export/export_api_wrap.cpp index 0d408f142bab9..b511b9fe3e6de 100644 --- a/Telegram/SourceFiles/export/export_api_wrap.cpp +++ b/Telegram/SourceFiles/export/export_api_wrap.cpp @@ -1826,9 +1826,7 @@ std::optional ApiWrap::getCustomEmoji(QByteArray &data) { file, { .customEmojiId = id }, fileProgress, - [=](const QString &path) { - loadMessageEmojiDone(id, path); - }); + [=](const QString &path) { loadMessageEmojiDone(id, path); }); if (!ready) { return std::nullopt; } @@ -1850,7 +1848,7 @@ bool ApiWrap::messageCustomEmojiReady(Data::Message &message) { if (part.type == Data::TextPart::Type::CustomEmoji) { auto data = getCustomEmoji(part.additional); if (data.has_value()) { - part.additional = *data; + part.additional = base::take(*data); } else { return false; } @@ -1860,7 +1858,7 @@ bool ApiWrap::messageCustomEmojiReady(Data::Message &message) { if (reaction.type == Data::Reaction::Type::CustomEmoji) { auto data = getCustomEmoji(reaction.documentId); if (data.has_value()) { - reaction.documentId = *data; + reaction.documentId = base::take(*data); } else { return false; } diff --git a/Telegram/SourceFiles/export/export_api_wrap.h b/Telegram/SourceFiles/export/export_api_wrap.h index 613d7c5881a0b..6073243152ab6 100644 --- a/Telegram/SourceFiles/export/export_api_wrap.h +++ b/Telegram/SourceFiles/export/export_api_wrap.h @@ -183,7 +183,7 @@ class ApiWrap { void resolveCustomEmoji(); void loadMessagesFiles(Data::MessagesSlice &&slice); void loadNextMessageFile(); - std::optional getCustomEmoji(QByteArray &data); + [[nodiscard]] std::optional getCustomEmoji(QByteArray &data); bool messageCustomEmojiReady(Data::Message &message); bool loadMessageFileProgress(FileProgress value); void loadMessageFileDone(const QString &relativePath); diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index e9b180b40dd03..21e6b0893e661 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -1556,9 +1556,9 @@ auto HtmlWriter::Wrap::pushMessage( if (!message.reactions.empty()) { block.append(pushDiv("reactions")); for (const auto &reaction : message.reactions) { - QByteArray reactionClass = "reaction"; + auto reactionClass = QByteArray("reaction"); for (const auto &recent : reaction.recent) { - auto peer = peers.peer(recent.peerId); + const auto peer = peers.peer(recent.peerId); if (peer.user() && peer.user()->isSelf) { reactionClass += " active"; break; @@ -1594,7 +1594,7 @@ auto HtmlWriter::Wrap::pushMessage( { "class", "userpics" }, })); for (const auto &recent : reaction.recent) { - auto peer = peers.peer(recent.peerId); + const auto peer = peers.peer(recent.peerId); block.append(pushUserpic(UserpicData({ .colorIndex = peer.colorIndex(), .pixelSize = 20, @@ -1609,7 +1609,8 @@ auto HtmlWriter::Wrap::pushMessage( } block.append(popTag()); } - if (reaction.recent.empty() || reaction.count > reaction.recent.size()) { + if (reaction.recent.empty() + || (reaction.count > reaction.recent.size())) { block.append(pushTag("div", { { "class", "count" }, })); diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index 4acb12d2e5ace..3dba1a90e1221 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -918,7 +918,9 @@ QByteArray SerializeMessage( if (!message.reactions.empty()) { const auto serializeReaction = [&](const Reaction &reaction) { context.nesting.push_back(Context::kObject); - const auto guard = gsl::finally([&] { context.nesting.pop_back(); }); + const auto guard = gsl::finally([&] { + context.nesting.pop_back(); + }); auto pairs = std::vector>(); pairs.push_back({ @@ -948,9 +950,12 @@ QByteArray SerializeMessage( context.nesting.push_back(Context::kArray); const auto recents = ranges::views::all( reaction.recent - ) | ranges::views::transform([&](const Reaction::Recent &recent) { + ) | ranges::views::transform([&]( + const Reaction::Recent &recent) { context.nesting.push_back(Context::kArray); - const auto guard = gsl::finally([&] { context.nesting.pop_back(); }); + const auto guard = gsl::finally([&] { + context.nesting.pop_back(); + }); return SerializeObject(context, { { "from", wrapPeerName(recent.peerId) }, { "from_id", wrapPeerId(recent.peerId) },