2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-10-19 14:46:58 +00:00

Simplest polls data export.

This commit is contained in:
John Preston
2018-12-23 00:08:15 +04:00
parent 93c8e9aa1f
commit ef1d38462f
6 changed files with 153 additions and 2 deletions

View File

@@ -574,6 +574,29 @@ QByteArray SerializeMessage(
? NumberToString(data.receiptMsgId)
: QByteArray()) }
}));
}, [&](const Poll &data) {
context.nesting.push_back(Context::kObject);
const auto answers = ranges::view::all(
data.answers
) | ranges::view::transform([&](const Poll::Answer &answer) {
context.nesting.push_back(Context::kArray);
auto result = SerializeObject(context, {
{ "text", SerializeString(answer.text) },
{ "voters", NumberToString(answer.votes) },
{ "chosen", answer.my ? "true" : "false" },
});
context.nesting.pop_back();
return result;
}) | ranges::to_vector;
const auto serialized = SerializeArray(context, answers);
context.nesting.pop_back();
pushBare("poll", SerializeObject(context, {
{ "question", SerializeString(data.question) },
{ "closed", data.closed ? "true" : "false" },
{ "total_voters", NumberToString(data.totalVotes) },
{ "answers", serialized }
}));
}, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message.");
}, [](std::nullopt_t) {});