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/search.cpp | 116 ++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 61 deletions(-) (limited to 'lib/csapi/search.cpp') diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp index b2e58931..ad54b39f 100644 --- a/lib/csapi/search.cpp +++ b/lib/csapi/search.cpp @@ -18,148 +18,142 @@ namespace QMatrixClient QJsonObject toJson(const SearchJob::IncludeEventContext& pod) { - QJsonObject _json; - addParam(_json, QStringLiteral("before_limit"), pod.beforeLimit); - addParam(_json, QStringLiteral("after_limit"), pod.afterLimit); - addParam(_json, QStringLiteral("include_profile"), pod.includeProfile); - return _json; + QJsonObject jo; + addParam(jo, QStringLiteral("before_limit"), pod.beforeLimit); + addParam(jo, QStringLiteral("after_limit"), pod.afterLimit); + addParam(jo, QStringLiteral("include_profile"), pod.includeProfile); + return jo; } QJsonObject toJson(const SearchJob::Group& pod) { - QJsonObject _json; - addParam(_json, QStringLiteral("key"), pod.key); - return _json; + QJsonObject jo; + addParam(jo, QStringLiteral("key"), pod.key); + return jo; } QJsonObject toJson(const SearchJob::Groupings& pod) { - QJsonObject _json; - addParam(_json, QStringLiteral("group_by"), pod.groupBy); - return _json; + QJsonObject jo; + addParam(jo, QStringLiteral("group_by"), pod.groupBy); + return jo; } QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod) { - QJsonObject _json; - addParam<>(_json, QStringLiteral("search_term"), pod.searchTerm); - addParam(_json, QStringLiteral("keys"), pod.keys); - addParam(_json, QStringLiteral("filter"), pod.filter); - addParam(_json, QStringLiteral("order_by"), pod.orderBy); - addParam(_json, QStringLiteral("event_context"), pod.eventContext); - addParam(_json, QStringLiteral("include_state"), pod.includeState); - addParam(_json, QStringLiteral("groupings"), pod.groupings); - return _json; + QJsonObject jo; + addParam<>(jo, QStringLiteral("search_term"), pod.searchTerm); + addParam(jo, QStringLiteral("keys"), pod.keys); + addParam(jo, QStringLiteral("filter"), pod.filter); + addParam(jo, QStringLiteral("order_by"), pod.orderBy); + addParam(jo, QStringLiteral("event_context"), pod.eventContext); + addParam(jo, QStringLiteral("include_state"), pod.includeState); + addParam(jo, QStringLiteral("groupings"), pod.groupings); + return jo; } QJsonObject toJson(const SearchJob::Categories& pod) { - QJsonObject _json; - addParam(_json, QStringLiteral("room_events"), pod.roomEvents); - return _json; + QJsonObject jo; + addParam(jo, QStringLiteral("room_events"), pod.roomEvents); + return jo; } - template <> struct FromJson + template <> struct FromJsonObject { - SearchJob::UserProfile operator()(const QJsonValue& jv) + SearchJob::UserProfile operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); SearchJob::UserProfile result; result.displayname = - fromJson(_json.value("displayname"_ls)); + fromJson(jo.value("displayname"_ls)); result.avatarUrl = - fromJson(_json.value("avatar_url"_ls)); + fromJson(jo.value("avatar_url"_ls)); return result; } }; - template <> struct FromJson + template <> struct FromJsonObject { - SearchJob::EventContext operator()(const QJsonValue& jv) + SearchJob::EventContext operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); SearchJob::EventContext result; result.begin = - fromJson(_json.value("start"_ls)); + fromJson(jo.value("start"_ls)); result.end = - fromJson(_json.value("end"_ls)); + fromJson(jo.value("end"_ls)); result.profileInfo = - fromJson>(_json.value("profile_info"_ls)); + fromJson>(jo.value("profile_info"_ls)); result.eventsBefore = - fromJson(_json.value("events_before"_ls)); + fromJson(jo.value("events_before"_ls)); result.eventsAfter = - fromJson(_json.value("events_after"_ls)); + fromJson(jo.value("events_after"_ls)); return result; } }; - template <> struct FromJson + template <> struct FromJsonObject { - SearchJob::Result operator()(const QJsonValue& jv) + SearchJob::Result operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); SearchJob::Result result; result.rank = - fromJson(_json.value("rank"_ls)); + fromJson(jo.value("rank"_ls)); result.result = - fromJson(_json.value("result"_ls)); + fromJson(jo.value("result"_ls)); result.context = - fromJson(_json.value("context"_ls)); + fromJson(jo.value("context"_ls)); return result; } }; - template <> struct FromJson + template <> struct FromJsonObject { - SearchJob::GroupValue operator()(const QJsonValue& jv) + SearchJob::GroupValue operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); SearchJob::GroupValue result; result.nextBatch = - fromJson(_json.value("next_batch"_ls)); + fromJson(jo.value("next_batch"_ls)); result.order = - fromJson(_json.value("order"_ls)); + fromJson(jo.value("order"_ls)); result.results = - fromJson(_json.value("results"_ls)); + fromJson(jo.value("results"_ls)); return result; } }; - template <> struct FromJson + template <> struct FromJsonObject { - SearchJob::ResultRoomEvents operator()(const QJsonValue& jv) + SearchJob::ResultRoomEvents operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); SearchJob::ResultRoomEvents result; result.count = - fromJson(_json.value("count"_ls)); + fromJson(jo.value("count"_ls)); result.highlights = - fromJson(_json.value("highlights"_ls)); + fromJson(jo.value("highlights"_ls)); result.results = - fromJson>(_json.value("results"_ls)); + fromJson>(jo.value("results"_ls)); result.state = - fromJson>(_json.value("state"_ls)); + fromJson>(jo.value("state"_ls)); result.groups = - fromJson>>(_json.value("groups"_ls)); + fromJson>>(jo.value("groups"_ls)); result.nextBatch = - fromJson(_json.value("next_batch"_ls)); + fromJson(jo.value("next_batch"_ls)); return result; } }; - template <> struct FromJson + template <> struct FromJsonObject { - SearchJob::ResultCategories operator()(const QJsonValue& jv) + SearchJob::ResultCategories operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); SearchJob::ResultCategories result; result.roomEvents = - fromJson(_json.value("room_events"_ls)); + fromJson(jo.value("room_events"_ls)); return result; } -- cgit v1.2.3 From 1e6510790dab6b9141ae52993987b406399668cd Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 2 Sep 2018 16:08:13 +0900 Subject: Support CS API 0.4.0 Numerous changes in CS (and now also AS) API, including compatibility-breaking ones - see the diff for details. --- lib/csapi/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/csapi/search.cpp') diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp index ad54b39f..9436eb47 100644 --- a/lib/csapi/search.cpp +++ b/lib/csapi/search.cpp @@ -131,7 +131,7 @@ namespace QMatrixClient { SearchJob::ResultRoomEvents result; result.count = - fromJson(jo.value("count"_ls)); + fromJson(jo.value("count"_ls)); result.highlights = fromJson(jo.value("highlights"_ls)); result.results = -- cgit v1.2.3