Improved code style in newest code from export submodule.

This commit is contained in:
23rd 2024-09-30 13:12:28 +03:00
parent a970fe93c1
commit 4582e61cfc
6 changed files with 33 additions and 25 deletions

View file

@ -370,8 +370,10 @@ std::vector<Reaction> 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<Reaction> 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<Reaction> ParseReactions(const MTPMessageReactions &data) {
}
}
}
std::vector<Reaction> 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) {

View file

@ -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;

View file

@ -1826,9 +1826,7 @@ std::optional<QByteArray> 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;
}

View file

@ -183,7 +183,7 @@ private:
void resolveCustomEmoji();
void loadMessagesFiles(Data::MessagesSlice &&slice);
void loadNextMessageFile();
std::optional<QByteArray> getCustomEmoji(QByteArray &data);
[[nodiscard]] std::optional<QByteArray> getCustomEmoji(QByteArray &data);
bool messageCustomEmojiReady(Data::Message &message);
bool loadMessageFileProgress(FileProgress value);
void loadMessageFileDone(const QString &relativePath);

View file

@ -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" },
}));

View file

@ -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<std::pair<QByteArray, QByteArray>>();
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) },