diff options
-rw-r--r-- | jobs/generated/users.cpp | 85 | ||||
-rw-r--r-- | jobs/generated/users.h | 46 |
2 files changed, 131 insertions, 0 deletions
diff --git a/jobs/generated/users.cpp b/jobs/generated/users.cpp new file mode 100644 index 00000000..33da4b43 --- /dev/null +++ b/jobs/generated/users.cpp @@ -0,0 +1,85 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "users.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +SearchUserDirectoryJob::User::operator QJsonObject() const +{ + QJsonObject o; + o.insert("user_id", toJson(userId)); + o.insert("display_name", toJson(displayName)); + o.insert("avatar_url", toJson(avatarUrl)); + + return o; +} +namespace QMatrixClient +{ + template <> struct FromJson<SearchUserDirectoryJob::User> + { + SearchUserDirectoryJob::User operator()(QJsonValue jv) + { + QJsonObject o = jv.toObject(); + SearchUserDirectoryJob::User result; + result.userId = + fromJson<QString>(o.value("user_id")); + result.displayName = + fromJson<QString>(o.value("display_name")); + result.avatarUrl = + fromJson<QString>(o.value("avatar_url")); + + return result; + } + }; +} // namespace QMatrixClient + +class SearchUserDirectoryJob::Private +{ + public: + QVector<User> results; + bool limited; +}; + +SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, double limit) + : BaseJob(HttpVerb::Post, "SearchUserDirectoryJob", + basePath % "/user_directory/search") + , d(new Private) +{ + QJsonObject _data; + _data.insert("search_term", toJson(searchTerm)); + _data.insert("limit", toJson(limit)); + setRequestData(_data); +} + +SearchUserDirectoryJob::~SearchUserDirectoryJob() = default; + +const QVector<SearchUserDirectoryJob::User>& SearchUserDirectoryJob::results() const +{ + return d->results; +} + +bool SearchUserDirectoryJob::limited() const +{ + return d->limited; +} + +BaseJob::Status SearchUserDirectoryJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("results")) + return { JsonParseError, + "The key 'results' not found in the response" }; + d->results = fromJson<QVector<User>>(json.value("results")); + if (!json.contains("limited")) + return { JsonParseError, + "The key 'limited' not found in the response" }; + d->limited = fromJson<bool>(json.value("limited")); + return Success; +} + diff --git a/jobs/generated/users.h b/jobs/generated/users.h new file mode 100644 index 00000000..7be250a5 --- /dev/null +++ b/jobs/generated/users.h @@ -0,0 +1,46 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "../basejob.h" + +#include <QtCore/QVector> + +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class SearchUserDirectoryJob : public BaseJob + { + public: + // Inner data structures + + struct User + { + QString userId; + QString displayName; + QString avatarUrl; + + operator QJsonObject() const; + }; + + // End of inner data structures + + explicit SearchUserDirectoryJob(const QString& searchTerm, double limit = {}); + ~SearchUserDirectoryJob() override; + + const QVector<User>& results() const; + bool limited() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient |