diff options
author | Andres Salomon <dilinger@queued.net> | 2021-01-18 04:00:14 -0500 |
---|---|---|
committer | Andres Salomon <dilinger@queued.net> | 2021-01-18 04:00:14 -0500 |
commit | 09eb39236666e81d5da014acea011dcd74d0999b (patch) | |
tree | 52876d96be71be1a39d5d935c1295a51995e8949 /lib/csapi/users.cpp | |
parent | f1788ee27f33e9339334e0d79bde9a27d9ce2e44 (diff) | |
parent | a4e78956f105875625b572d8b98459ffa86fafe5 (diff) | |
download | libquotient-09eb39236666e81d5da014acea011dcd74d0999b.tar.gz libquotient-09eb39236666e81d5da014acea011dcd74d0999b.zip |
Update upstream source from tag 'upstream/0.6.4'
Update to upstream version '0.6.4'
with Debian dir aa8705fd74743e79c043bc9e3e425d5064404cfe
Diffstat (limited to 'lib/csapi/users.cpp')
-rw-r--r-- | lib/csapi/users.cpp | 69 |
1 files changed, 8 insertions, 61 deletions
diff --git a/lib/csapi/users.cpp b/lib/csapi/users.cpp index 97d8962d..a0279d7e 100644 --- a/lib/csapi/users.cpp +++ b/lib/csapi/users.cpp @@ -4,72 +4,19 @@ #include "users.h" -#include "converters.h" - #include <QtCore/QStringBuilder> -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -namespace QMatrixClient -{ - // Converters - - template <> struct JsonObjectConverter<SearchUserDirectoryJob::User> - { - static void fillFrom(const QJsonObject& jo, SearchUserDirectoryJob::User& result) - { - fromJson(jo.value("user_id"_ls), result.userId); - fromJson(jo.value("display_name"_ls), result.displayName); - fromJson(jo.value("avatar_url"_ls), result.avatarUrl); - } - }; -} // namespace QMatrixClient +using namespace Quotient; -class SearchUserDirectoryJob::Private -{ - public: - QVector<User> results; - bool limited; -}; - -static const auto SearchUserDirectoryJobName = QStringLiteral("SearchUserDirectoryJob"); - -SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, Omittable<int> limit) - : BaseJob(HttpVerb::Post, SearchUserDirectoryJobName, - basePath % "/user_directory/search") - , d(new Private) +SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, + Omittable<int> limit) + : BaseJob(HttpVerb::Post, QStringLiteral("SearchUserDirectoryJob"), + QStringLiteral("/_matrix/client/r0") % "/user_directory/search") { QJsonObject _data; addParam<>(_data, QStringLiteral("search_term"), searchTerm); addParam<IfNotEmpty>(_data, QStringLiteral("limit"), limit); - setRequestData(_data); + setRequestData(std::move(_data)); + addExpectedKey("results"); + addExpectedKey("limited"); } - -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"_ls)) - return { JsonParseError, - "The key 'results' not found in the response" }; - fromJson(json.value("results"_ls), d->results); - if (!json.contains("limited"_ls)) - return { JsonParseError, - "The key 'limited' not found in the response" }; - fromJson(json.value("limited"_ls), d->limited); - return Success; -} - |