From 4244cee8d5e0f760cccd2b45ad587670573ef03c Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 24 Sep 2018 19:20:10 +0900 Subject: Prepare for CS API 0.4.0 This commit consists of two parts: upgrading the API infrastructure and trivial but sweeping update to the generated files. 1. The API infrastructure (converters.h, *.mustache and some other non-generated files) now can deal with top-level JSON arrays and response inlining; better supports property maps; and gets some formatting fixes in generated code. 2. Generated files now use QJsonValue instead of QJsonObject as a default type to (un)marshall Matrix API data structures, to match the change in the infrastructure above This commit is still using the old Matrix API definitions, before CS API 0.4.0. Getting to CS API 0.4.0 will come next. --- lib/csapi/rooms.cpp | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'lib/csapi/rooms.cpp') diff --git a/lib/csapi/rooms.cpp b/lib/csapi/rooms.cpp index a70d9543..3befeee5 100644 --- a/lib/csapi/rooms.cpp +++ b/lib/csapi/rooms.cpp @@ -42,11 +42,7 @@ EventPtr&& GetOneRoomEventJob::data() BaseJob::Status GetOneRoomEventJob::parseJson(const QJsonDocument& data) { - auto json = data.object(); - if (!json.contains("data"_ls)) - return { JsonParseError, - "The key 'data' not found in the response" }; - d->data = fromJson(json.value("data"_ls)); + d->data = fromJson(data); return Success; } @@ -80,11 +76,7 @@ StateEventPtr&& GetRoomStateWithKeyJob::data() BaseJob::Status GetRoomStateWithKeyJob::parseJson(const QJsonDocument& data) { - auto json = data.object(); - if (!json.contains("data"_ls)) - return { JsonParseError, - "The key 'data' not found in the response" }; - d->data = fromJson(json.value("data"_ls)); + d->data = fromJson(data); return Success; } @@ -118,11 +110,7 @@ StateEventPtr&& GetRoomStateByTypeJob::data() BaseJob::Status GetRoomStateByTypeJob::parseJson(const QJsonDocument& data) { - auto json = data.object(); - if (!json.contains("data"_ls)) - return { JsonParseError, - "The key 'data' not found in the response" }; - d->data = fromJson(json.value("data"_ls)); + d->data = fromJson(data); return Success; } @@ -156,11 +144,7 @@ StateEvents&& GetRoomStateJob::data() BaseJob::Status GetRoomStateJob::parseJson(const QJsonDocument& data) { - auto json = data.object(); - if (!json.contains("data"_ls)) - return { JsonParseError, - "The key 'data' not found in the response" }; - d->data = fromJson(json.value("data"_ls)); + d->data = fromJson(data); return Success; } @@ -203,16 +187,15 @@ namespace QMatrixClient { // Converters - template <> struct FromJson + template <> struct FromJsonObject { - GetJoinedMembersByRoomJob::RoomMember operator()(const QJsonValue& jv) + GetJoinedMembersByRoomJob::RoomMember operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); GetJoinedMembersByRoomJob::RoomMember result; result.displayName = - fromJson(_json.value("display_name"_ls)); + fromJson(jo.value("display_name"_ls)); result.avatarUrl = - fromJson(_json.value("avatar_url"_ls)); + fromJson(jo.value("avatar_url"_ls)); return result; } -- cgit v1.2.3