/****************************************************************************** * 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 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 jo; addParam(jo, QStringLiteral("key"), pod.key); return jo; } QJsonObject toJson(const SearchJob::Groupings& pod) { QJsonObject jo; addParam(jo, QStringLiteral("group_by"), pod.groupBy); return jo; } QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod) { 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 jo; addParam(jo, QStringLiteral("room_events"), pod.roomEvents); return jo; } template <> struct FromJsonObject { SearchJob::UserProfile operator()(const QJsonObject& jo) const { SearchJob::UserProfile result; result.displayname = fromJson(jo.value("displayname"_ls)); result.avatarUrl = fromJson(jo.value("avatar_url"_ls)); return result; } }; template <> struct FromJsonObject { SearchJob::EventContext operator()(const QJsonObject& jo) const { SearchJob::EventContext result; result.begin = fromJson(jo.value("start"_ls)); result.end = fromJson(jo.value("end"_ls)); result.profileInfo = fromJson>(jo.value("profile_info"_ls)); result.eventsBefore = fromJson(jo.value("events_before"_ls)); result.eventsAfter = fromJson(jo.value("events_after"_ls)); return result; } }; template <> struct FromJsonObject { SearchJob::Result operator()(const QJsonObject& jo) const { SearchJob::Result result; result.rank = fromJson(jo.value("rank"_ls)); result.result = fromJson(jo.value("result"_ls)); result.context = fromJson(jo.value("context"_ls)); return result; } }; template <> struct FromJsonObject { SearchJob::GroupValue operator()(const QJsonObject& jo) const { SearchJob::GroupValue result; result.nextBatch = fromJson(jo.value("next_batch"_ls)); result.order = fromJson(jo.value("order"_ls)); result.results = fromJson(jo.value("results"_ls)); return result; } }; template <> struct FromJsonObject { SearchJob::ResultRoomEvents operator()(const QJsonObject& jo) const { SearchJob::ResultRoomEvents result; result.count = fromJson(jo.value("count"_ls)); result.highlights = fromJson(jo.value("highlights"_ls)); result.results = fromJson>(jo.value("results"_ls)); result.state = fromJson>(jo.value("state"_ls)); result.groups = fromJson>>(jo.value("groups"_ls)); result.nextBatch = fromJson(jo.value("next_batch"_ls)); return result; } }; template <> struct FromJsonObject { SearchJob::ResultCategories operator()(const QJsonObject& jo) const { SearchJob::ResultCategories result; result.roomEvents = fromJson(jo.value("room_events"_ls)); return result; } }; } // namespace QMatrixClient class SearchJob::Private { public: ResultCategories searchCategories; }; BaseJob::Query queryToSearch(const QString& nextBatch) { BaseJob::Query _q; addParam(_q, QStringLiteral("next_batch"), nextBatch); return _q; } static const auto SearchJobName = QStringLiteral("SearchJob"); SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatch) : BaseJob(HttpVerb::Post, SearchJobName, basePath % "/search", queryToSearch(nextBatch)) , d(new Private) { QJsonObject _data; addParam<>(_data, QStringLiteral("search_categories"), 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"_ls)) return { JsonParseError, "The key 'search_categories' not found in the response" }; d->searchCategories = fromJson(json.value("search_categories"_ls)); return Success; }