mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved code style in newest code from export submodule.
This commit is contained in:
parent
a970fe93c1
commit
4582e61cfc
6 changed files with 33 additions and 25 deletions
|
@ -370,8 +370,10 @@ std::vector<Reaction> ParseReactions(const MTPMessageReactions &data) {
|
||||||
for (const auto &single : data.data().vresults().v) {
|
for (const auto &single : data.data().vresults().v) {
|
||||||
auto reaction = ParseReaction(single.data().vreaction());
|
auto reaction = ParseReaction(single.data().vreaction());
|
||||||
reaction.count = single.data().vcount().v;
|
reaction.count = single.data().vcount().v;
|
||||||
auto id = Reaction::Id(reaction);
|
const auto id = Reaction::Id(reaction);
|
||||||
auto const &[_, inserted] = reactionsMap.try_emplace(id, reaction);
|
auto const &[_, inserted] = reactionsMap.try_emplace(
|
||||||
|
id,
|
||||||
|
std::move(reaction));
|
||||||
if (inserted) {
|
if (inserted) {
|
||||||
reactionsOrder.push_back(id);
|
reactionsOrder.push_back(id);
|
||||||
}
|
}
|
||||||
|
@ -380,8 +382,10 @@ std::vector<Reaction> ParseReactions(const MTPMessageReactions &data) {
|
||||||
if (const auto list = data.data().vrecent_reactions()) {
|
if (const auto list = data.data().vrecent_reactions()) {
|
||||||
for (const auto &single : list->v) {
|
for (const auto &single : list->v) {
|
||||||
auto reaction = ParseReaction(single.data().vreaction());
|
auto reaction = ParseReaction(single.data().vreaction());
|
||||||
auto id = Reaction::Id(reaction);
|
const auto id = Reaction::Id(reaction);
|
||||||
auto const &[it, inserted] = reactionsMap.try_emplace(id, reaction);
|
auto const &[it, inserted] = reactionsMap.try_emplace(
|
||||||
|
id,
|
||||||
|
std::move(reaction));
|
||||||
if (inserted) {
|
if (inserted) {
|
||||||
reactionsOrder.push_back(id);
|
reactionsOrder.push_back(id);
|
||||||
}
|
}
|
||||||
|
@ -392,11 +396,11 @@ std::vector<Reaction> ParseReactions(const MTPMessageReactions &data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<Reaction> results;
|
return ranges::views::all(
|
||||||
for (const auto &id : reactionsOrder) {
|
reactionsOrder
|
||||||
results.push_back(reactionsMap[id]);
|
) | ranges::views::transform([&](const Utf8String &id) {
|
||||||
}
|
return reactionsMap.at(id);
|
||||||
return results;
|
}) | ranges::to_vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utf8String FillLeft(const Utf8String &data, int length, char filler) {
|
Utf8String FillLeft(const Utf8String &data, int length, char filler) {
|
||||||
|
|
|
@ -709,10 +709,10 @@ struct Reaction {
|
||||||
CustomEmoji,
|
CustomEmoji,
|
||||||
Paid,
|
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 {
|
struct Recent {
|
||||||
PeerId peerId = 0;
|
PeerId peerId = 0;
|
||||||
|
|
|
@ -1826,9 +1826,7 @@ std::optional<QByteArray> ApiWrap::getCustomEmoji(QByteArray &data) {
|
||||||
file,
|
file,
|
||||||
{ .customEmojiId = id },
|
{ .customEmojiId = id },
|
||||||
fileProgress,
|
fileProgress,
|
||||||
[=](const QString &path) {
|
[=](const QString &path) { loadMessageEmojiDone(id, path); });
|
||||||
loadMessageEmojiDone(id, path);
|
|
||||||
});
|
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -1850,7 +1848,7 @@ bool ApiWrap::messageCustomEmojiReady(Data::Message &message) {
|
||||||
if (part.type == Data::TextPart::Type::CustomEmoji) {
|
if (part.type == Data::TextPart::Type::CustomEmoji) {
|
||||||
auto data = getCustomEmoji(part.additional);
|
auto data = getCustomEmoji(part.additional);
|
||||||
if (data.has_value()) {
|
if (data.has_value()) {
|
||||||
part.additional = *data;
|
part.additional = base::take(*data);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1860,7 +1858,7 @@ bool ApiWrap::messageCustomEmojiReady(Data::Message &message) {
|
||||||
if (reaction.type == Data::Reaction::Type::CustomEmoji) {
|
if (reaction.type == Data::Reaction::Type::CustomEmoji) {
|
||||||
auto data = getCustomEmoji(reaction.documentId);
|
auto data = getCustomEmoji(reaction.documentId);
|
||||||
if (data.has_value()) {
|
if (data.has_value()) {
|
||||||
reaction.documentId = *data;
|
reaction.documentId = base::take(*data);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ private:
|
||||||
void resolveCustomEmoji();
|
void resolveCustomEmoji();
|
||||||
void loadMessagesFiles(Data::MessagesSlice &&slice);
|
void loadMessagesFiles(Data::MessagesSlice &&slice);
|
||||||
void loadNextMessageFile();
|
void loadNextMessageFile();
|
||||||
std::optional<QByteArray> getCustomEmoji(QByteArray &data);
|
[[nodiscard]] std::optional<QByteArray> getCustomEmoji(QByteArray &data);
|
||||||
bool messageCustomEmojiReady(Data::Message &message);
|
bool messageCustomEmojiReady(Data::Message &message);
|
||||||
bool loadMessageFileProgress(FileProgress value);
|
bool loadMessageFileProgress(FileProgress value);
|
||||||
void loadMessageFileDone(const QString &relativePath);
|
void loadMessageFileDone(const QString &relativePath);
|
||||||
|
|
|
@ -1556,9 +1556,9 @@ auto HtmlWriter::Wrap::pushMessage(
|
||||||
if (!message.reactions.empty()) {
|
if (!message.reactions.empty()) {
|
||||||
block.append(pushDiv("reactions"));
|
block.append(pushDiv("reactions"));
|
||||||
for (const auto &reaction : message.reactions) {
|
for (const auto &reaction : message.reactions) {
|
||||||
QByteArray reactionClass = "reaction";
|
auto reactionClass = QByteArray("reaction");
|
||||||
for (const auto &recent : reaction.recent) {
|
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) {
|
if (peer.user() && peer.user()->isSelf) {
|
||||||
reactionClass += " active";
|
reactionClass += " active";
|
||||||
break;
|
break;
|
||||||
|
@ -1594,7 +1594,7 @@ auto HtmlWriter::Wrap::pushMessage(
|
||||||
{ "class", "userpics" },
|
{ "class", "userpics" },
|
||||||
}));
|
}));
|
||||||
for (const auto &recent : reaction.recent) {
|
for (const auto &recent : reaction.recent) {
|
||||||
auto peer = peers.peer(recent.peerId);
|
const auto peer = peers.peer(recent.peerId);
|
||||||
block.append(pushUserpic(UserpicData({
|
block.append(pushUserpic(UserpicData({
|
||||||
.colorIndex = peer.colorIndex(),
|
.colorIndex = peer.colorIndex(),
|
||||||
.pixelSize = 20,
|
.pixelSize = 20,
|
||||||
|
@ -1609,7 +1609,8 @@ auto HtmlWriter::Wrap::pushMessage(
|
||||||
}
|
}
|
||||||
block.append(popTag());
|
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", {
|
block.append(pushTag("div", {
|
||||||
{ "class", "count" },
|
{ "class", "count" },
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -918,7 +918,9 @@ QByteArray SerializeMessage(
|
||||||
if (!message.reactions.empty()) {
|
if (!message.reactions.empty()) {
|
||||||
const auto serializeReaction = [&](const Reaction &reaction) {
|
const auto serializeReaction = [&](const Reaction &reaction) {
|
||||||
context.nesting.push_back(Context::kObject);
|
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>>();
|
auto pairs = std::vector<std::pair<QByteArray, QByteArray>>();
|
||||||
pairs.push_back({
|
pairs.push_back({
|
||||||
|
@ -948,9 +950,12 @@ QByteArray SerializeMessage(
|
||||||
context.nesting.push_back(Context::kArray);
|
context.nesting.push_back(Context::kArray);
|
||||||
const auto recents = ranges::views::all(
|
const auto recents = ranges::views::all(
|
||||||
reaction.recent
|
reaction.recent
|
||||||
) | ranges::views::transform([&](const Reaction::Recent &recent) {
|
) | ranges::views::transform([&](
|
||||||
|
const Reaction::Recent &recent) {
|
||||||
context.nesting.push_back(Context::kArray);
|
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, {
|
return SerializeObject(context, {
|
||||||
{ "from", wrapPeerName(recent.peerId) },
|
{ "from", wrapPeerName(recent.peerId) },
|
||||||
{ "from_id", wrapPeerId(recent.peerId) },
|
{ "from_id", wrapPeerId(recent.peerId) },
|
||||||
|
|
Loading…
Add table
Reference in a new issue