/****************************************************************************** * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN */ #include "search.h" #include "converters.h" #include using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); namespace QMatrixClient { // Converters QJsonObject toJson(const SearchJob::IncludeEventContext& pod) { QJsonObject o; o.insert("before_limit", toJson(pod.beforeLimit)); o.insert("after_limit", toJson(pod.afterLimit)); o.insert("include_profile", toJson(pod.includeProfile)); return o; } QJsonObject toJson(const SearchJob::Group& pod) { QJsonObject o; o.insert("key", toJson(pod.key)); return o; } QJsonObject toJson(const SearchJob::Groupings& pod) { QJsonObject o; o.insert("group_by", toJson(pod.groupBy)); return o; } QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod) { QJsonObject o; o.insert("search_term", toJson(pod.searchTerm)); o.insert("keys", toJson(pod.keys)); o.insert("filter", toJson(pod.filter)); o.insert("order_by", toJson(pod.orderBy)); o.insert("event_context", toJson(pod.eventContext)); o.insert("include_state", toJson(pod.includeState)); o.insert("groupings", toJson(pod.groupings)); return o; } QJsonObject toJson(const SearchJob::Categories& pod) { QJsonObject o; o.insert("room_events", toJson(pod.roomEvents)); return o; } template <> struct FromJson { SearchJob::UserProfile operator()(const QJsonValue& jv) { const auto& o = jv.toObject(); SearchJob::UserProfile result; result.displayname = fromJson(o.value("displayname")); result.avatarUrl = fromJson(o.value("avatar_url")); return result; } }; template <> struct FromJson { SearchJob::EventContext operator()(const QJsonValue& jv) { const auto& o = jv.toObject(); SearchJob::EventContext result; result.begin = fromJson(o.value("start")); result.end = fromJson(o.value("end")); result.profileInfo = fromJson>(o.value("profile_info")); result.eventsBefore = fromJson(o.value("events_before")); result.eventsAfter = fromJson(o.value("events_after")); return result; } }; template <> struct FromJson { SearchJob::Result operator()(const QJsonValue& jv) { const auto& o = jv.toObject(); SearchJob::Result result; result.rank = fromJson(o.value("rank")); result.result = fromJson(o.value("result")); result.context = fromJson(o.value("context")); return result; } }; template <> struct FromJson { SearchJob::GroupValue operator()(const QJsonValue& jv) { const auto& o = jv.toObject(); SearchJob::GroupValue result; result.nextBatch = fromJson(o.value("next_batch")); result.order = fromJson(o.value("order")); result.results = fromJson(o.value("results")); return result; } }; template <> struct FromJson { SearchJob::ResultRoomEvents operator()(const QJsonValue& jv) { const auto& o = jv.toObject(); SearchJob::ResultRoomEvents result; result.count = fromJson(o.value("count")); result.results = fromJson>(o.value("results")); result.state = fromJson>(o.value("state")); result.groups = fromJson>>(o.value("groups")); result.nextBatch = fromJson(o.value("next_batch")); return result; } }; template <> struct FromJson { SearchJob::ResultCategories operator()(const QJsonValue& jv) { const auto& o = jv.toObject(); SearchJob::ResultCategories result; result.roomEvents = fromJson(o.value("room_events")); return result; } }; } // namespace QMatrixClient class SearchJob::Private { public: ResultCategories searchCategories; }; BaseJob::Query queryToSearch(const QString& nextBatch) { BaseJob::Query _q; if (!nextBatch.isEmpty()) _q.addQueryItem("next_batch", nextBatch); return _q; } SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatch) : BaseJob(HttpVerb::Post, "SearchJob", basePath % "/search", queryToSearch(nextBatch)) , d(new Private) { QJsonObject _data; _data.insert("search_categories", toJson(searchCategories)); setRequestData(_data); } SearchJob::~SearchJob() = default; const SearchJob::ResultCategories& SearchJob::searchCategories() const { return d->searchCategories; } BaseJob::Status SearchJob::parseJson(const QJsonDocument& data) { auto json = data.object(); if (!json.contains("search_categories")) return { JsonParseError, "The key 'search_categories' not found in the response" }; d->searchCategories = fromJson(json.value("search_categories")); return Success; }