diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-05 19:36:15 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-05 19:36:15 +0900 |
commit | a8d2a73c771f188fc0fdc6351b4923af788317d5 (patch) | |
tree | b2795b93149f7c0ae3cd5005331b650a8eb6fd1e /lib/csapi/users.cpp | |
parent | da16225dfbec9b155c2c299757203f7676ac6ccf (diff) | |
parent | a63838235134b066c092ad98e1f18ff7991c91c1 (diff) | |
download | libquotient-a8d2a73c771f188fc0fdc6351b4923af788317d5.tar.gz libquotient-a8d2a73c771f188fc0fdc6351b4923af788317d5.zip |
Merge branch 'kitsune-gtad'
Diffstat (limited to 'lib/csapi/users.cpp')
-rw-r--r-- | lib/csapi/users.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/csapi/users.cpp b/lib/csapi/users.cpp new file mode 100644 index 00000000..fd2944e4 --- /dev/null +++ b/lib/csapi/users.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** + * 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"); + +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson<SearchUserDirectoryJob::User> + { + SearchUserDirectoryJob::User operator()(const QJsonValue& jv) + { + const auto& 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, int 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; +} + |