mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added strictly typed field to export JSON for text entities.
This commit is contained in:
parent
b28140c4b0
commit
84400f5912
1 changed files with 10 additions and 5 deletions
|
@ -145,11 +145,12 @@ QByteArray SerializeArray(
|
||||||
|
|
||||||
QByteArray SerializeText(
|
QByteArray SerializeText(
|
||||||
Context &context,
|
Context &context,
|
||||||
const std::vector<Data::TextPart> &data) {
|
const std::vector<Data::TextPart> &data,
|
||||||
|
bool serializeToObjects = false) {
|
||||||
using Type = Data::TextPart::Type;
|
using Type = Data::TextPart::Type;
|
||||||
|
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
return SerializeString("");
|
return serializeToObjects ? QByteArray("[]") : SerializeString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
context.nesting.push_back(Context::kArray);
|
context.nesting.push_back(Context::kArray);
|
||||||
|
@ -157,7 +158,7 @@ QByteArray SerializeText(
|
||||||
const auto text = ranges::views::all(
|
const auto text = ranges::views::all(
|
||||||
data
|
data
|
||||||
) | ranges::views::transform([&](const Data::TextPart &part) {
|
) | ranges::views::transform([&](const Data::TextPart &part) {
|
||||||
if (part.type == Type::Text) {
|
if ((part.type == Type::Text) && !serializeToObjects) {
|
||||||
return SerializeString(part.text);
|
return SerializeString(part.text);
|
||||||
}
|
}
|
||||||
const auto typeString = [&] {
|
const auto typeString = [&] {
|
||||||
|
@ -172,6 +173,7 @@ QByteArray SerializeText(
|
||||||
case Type::Italic: return "italic";
|
case Type::Italic: return "italic";
|
||||||
case Type::Code: return "code";
|
case Type::Code: return "code";
|
||||||
case Type::Pre: return "pre";
|
case Type::Pre: return "pre";
|
||||||
|
case Type::Text: return "plain";
|
||||||
case Type::TextUrl: return "text_link";
|
case Type::TextUrl: return "text_link";
|
||||||
case Type::MentionName: return "mention_name";
|
case Type::MentionName: return "mention_name";
|
||||||
case Type::Phone: return "phone";
|
case Type::Phone: return "phone";
|
||||||
|
@ -210,8 +212,10 @@ QByteArray SerializeText(
|
||||||
|
|
||||||
context.nesting.pop_back();
|
context.nesting.pop_back();
|
||||||
|
|
||||||
if (data.size() == 1 && data[0].type == Data::TextPart::Type::Text) {
|
if (!serializeToObjects) {
|
||||||
return text[0];
|
if (data.size() == 1 && data[0].type == Data::TextPart::Type::Text) {
|
||||||
|
return text[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return SerializeArray(context, text);
|
return SerializeArray(context, text);
|
||||||
}
|
}
|
||||||
|
@ -700,6 +704,7 @@ QByteArray SerializeMessage(
|
||||||
}, [](v::null_t) {});
|
}, [](v::null_t) {});
|
||||||
|
|
||||||
pushBare("text", SerializeText(context, message.text));
|
pushBare("text", SerializeText(context, message.text));
|
||||||
|
pushBare("text_entities", SerializeText(context, message.text, true));
|
||||||
|
|
||||||
return serialized();
|
return serialized();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue