2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-10-23 15:06:09 +00:00

Add IDs to JSON exports (#5426)

* Added IDs to various JSON objects.

Including an `_id` addition inside chat message, which get appended to `actor` or `from` entries.
This commit is contained in:
Jonathan de Jong
2018-12-04 16:22:17 +01:00
committed by John Preston
parent 61add763ae
commit 87d4d46ce7
3 changed files with 10 additions and 2 deletions

View File

@@ -219,7 +219,7 @@ QByteArray SerializeMessage(
if (message.media.content.is<UnsupportedMedia>()) {
return SerializeObject(context, {
{ "id", NumberToString(message.id) },
{ "id", Data::NumberToString(message.id) },
{ "type", SerializeString("unsupported") }
});
}
@@ -271,7 +271,7 @@ QByteArray SerializeMessage(
};
const auto push = [&](const QByteArray &key, const auto &value) {
if constexpr (std::is_arithmetic_v<std::decay_t<decltype(value)>>) {
pushBare(key, NumberToString(value));
pushBare(key, Data::NumberToString(value));
} else {
const auto wrapped = QByteArray(value);
if (!wrapped.isEmpty()) {
@@ -288,6 +288,7 @@ QByteArray SerializeMessage(
const auto pushFrom = [&](const QByteArray &label = "from") {
if (message.fromId) {
pushBare(label, wrapUserName(message.fromId));
pushBare(label+"_id", Data::NumberToString(message.fromId));
}
};
const auto pushReplyToMsgId = [&](
@@ -640,6 +641,7 @@ Result JsonWriter::writePersonal(const Data::PersonalInfo &data) {
return _output->writeBlock(
prepareObjectItemStart("personal_information")
+ SerializeObject(_context, {
{ "user_id", Data::NumberToString(data.user.id) },
{ "first_name", SerializeString(info.firstName) },
{ "last_name", SerializeString(info.lastName) },
{
@@ -745,6 +747,7 @@ Result JsonWriter::writeSavedContacts(const Data::ContactsList &data) {
}));
} else {
block.append(SerializeObject(_context, {
{ "user_id", Data::NumberToString(contact.userId) },
{ "first_name", SerializeString(contact.firstName) },
{ "last_name", SerializeString(contact.lastName) },
{
@@ -789,6 +792,7 @@ Result JsonWriter::writeFrequentContacts(const Data::ContactsList &data) {
}();
block.append(prepareArrayItemStart());
block.append(SerializeObject(_context, {
{ "id", Data::NumberToString(top.peer.id()) },
{ "category", SerializeString(category) },
{ "type", SerializeString(type) },
{ "name", StringAllowNull(top.peer.name()) },
@@ -981,6 +985,8 @@ Result JsonWriter::writeDialogStart(const Data::DialogInfo &data) {
}
block.append(prepareObjectItemStart("type")
+ StringAllowNull(TypeString(data.type)));
block.append(prepareObjectItemStart("id")
+ Data::NumberToString(data.peerId));
block.append(prepareObjectItemStart("messages"));
block.append(pushNesting(Context::kArray));
return _output->writeBlock(block);