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

@ -617,6 +617,7 @@ User ParseUser(const MTPUser &data) {
auto result = User(); auto result = User();
result.info = ParseContactInfo(data); result.info = ParseContactInfo(data);
data.match([&](const MTPDuser &data) { data.match([&](const MTPDuser &data) {
result.id = data.vid.v;
if (data.has_username()) { if (data.has_username()) {
result.username = ParseString(data.vusername); result.username = ParseString(data.vusername);
} }

View File

@ -189,6 +189,7 @@ UserpicsSlice ParseUserpicsSlice(
struct User { struct User {
ContactInfo info; ContactInfo info;
Utf8String username; Utf8String username;
int32 id;
bool isBot = false; bool isBot = false;
bool isSelf = false; bool isSelf = false;

View File

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