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