aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/users.h
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2022-10-06 19:27:24 +0200
committern-peugnet <n.peugnet@free.fr>2022-10-06 19:27:24 +0200
commitd911b207f49e936b3e992200796110f0749ed150 (patch)
tree96d20ebb4d074a4c1755e21cb316a52d584daee3 /lib/csapi/users.h
parent8ad8a74152c5701b6ca1f9a00487ba9257a439b4 (diff)
parent56c2f2e2b809b9077393eb617828f33d144f5634 (diff)
downloadlibquotient-d911b207f49e936b3e992200796110f0749ed150.tar.gz
libquotient-d911b207f49e936b3e992200796110f0749ed150.zip
New upstream version 0.7.0
Diffstat (limited to 'lib/csapi/users.h')
-rw-r--r--lib/csapi/users.h121
1 files changed, 63 insertions, 58 deletions
diff --git a/lib/csapi/users.h b/lib/csapi/users.h
index 1e355b8f..3c99758b 100644
--- a/lib/csapi/users.h
+++ b/lib/csapi/users.h
@@ -6,73 +6,78 @@
#include "jobs/basejob.h"
-#include <QtCore/QVector>
-#include "converters.h"
+namespace Quotient {
-namespace QMatrixClient
-{
- // Operations
+/*! \brief Searches the user directory.
+ *
+ * Performs a search for users. The homeserver may
+ * determine which subset of users are searched, however the homeserver
+ * MUST at a minimum consider the users the requesting user shares a
+ * room with and those who reside in public rooms (known to the homeserver).
+ * The search MUST consider local users to the homeserver, and SHOULD
+ * query remote users as part of the search.
+ *
+ * The search is performed case-insensitively on user IDs and display
+ * names preferably using a collation determined based upon the
+ * `Accept-Language` header provided in the request, if present.
+ */
+class QUOTIENT_API SearchUserDirectoryJob : public BaseJob {
+public:
+ // Inner data structures
- /// Searches the user directory.
- ///
- /// Performs a search for users on the homeserver. The homeserver may
+ /// Performs a search for users. The homeserver may
/// determine which subset of users are searched, however the homeserver
/// MUST at a minimum consider the users the requesting user shares a
- /// room with and those who reside in public rooms (known to the homeserver).
- /// The search MUST consider local users to the homeserver, and SHOULD
- /// query remote users as part of the search.
- ///
+ /// room with and those who reside in public rooms (known to the
+ /// homeserver). The search MUST consider local users to the homeserver, and
+ /// SHOULD query remote users as part of the search.
+ ///
/// The search is performed case-insensitively on user IDs and display
- /// names preferably using a collation determined based upon the
- /// ``Accept-Language`` header provided in the request, if present.
- class SearchUserDirectoryJob : public BaseJob
- {
- public:
- // Inner data structures
+ /// names preferably using a collation determined based upon the
+ /// `Accept-Language` header provided in the request, if present.
+ struct User {
+ /// The user's matrix user ID.
+ QString userId;
+ /// The display name of the user, if one exists.
+ QString displayName;
+ /// The avatar url, as an MXC, if one exists.
+ QUrl avatarUrl;
+ };
- /// Performs a search for users on the homeserver. The homeserver may
- /// determine which subset of users are searched, however the homeserver
- /// MUST at a minimum consider the users the requesting user shares a
- /// room with and those who reside in public rooms (known to the homeserver).
- /// The search MUST consider local users to the homeserver, and SHOULD
- /// query remote users as part of the search.
- ///
- /// The search is performed case-insensitively on user IDs and display
- /// names preferably using a collation determined based upon the
- /// ``Accept-Language`` header provided in the request, if present.
- struct User
- {
- /// The user's matrix user ID.
- QString userId;
- /// The display name of the user, if one exists.
- QString displayName;
- /// The avatar url, as an MXC, if one exists.
- QString avatarUrl;
- };
+ // Construction/destruction
- // Construction/destruction
+ /*! \brief Searches the user directory.
+ *
+ * \param searchTerm
+ * The term to search for
+ *
+ * \param limit
+ * The maximum number of results to return. Defaults to 10.
+ */
+ explicit SearchUserDirectoryJob(const QString& searchTerm,
+ Omittable<int> limit = none);
- /*! Searches the user directory.
- * \param searchTerm
- * The term to search for
- * \param limit
- * The maximum number of results to return. Defaults to 10.
- */
- explicit SearchUserDirectoryJob(const QString& searchTerm, Omittable<int> limit = none);
- ~SearchUserDirectoryJob() override;
+ // Result properties
- // Result properties
+ /// Ordered by rank and then whether or not profile info is available.
+ QVector<User> results() const
+ {
+ return loadFromJson<QVector<User>>("results"_ls);
+ }
- /// Ordered by rank and then whether or not profile info is available.
- const QVector<User>& results() const;
- /// Indicates if the result list has been truncated by the limit.
- bool limited() const;
+ /// Indicates if the result list has been truncated by the limit.
+ bool limited() const { return loadFromJson<bool>("limited"_ls); }
+};
- protected:
- Status parseJson(const QJsonDocument& data) override;
+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);
+ }
+};
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-} // namespace QMatrixClient
+} // namespace Quotient