libQuotient
A Qt library for building matrix clients
users.h
Go to the documentation of this file.
1 // THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
2 
3 #pragma once
4 
5 #include <Quotient/jobs/basejob.h>
6 
7 namespace Quotient {
8 
9 //! \brief Searches the user directory.
10 //!
11 //! Performs a search for users. The homeserver may
12 //! determine which subset of users are searched, however the homeserver
13 //! MUST at a minimum consider the users the requesting user shares a
14 //! room with and those who reside in public rooms (known to the homeserver).
15 //! The search MUST consider local users to the homeserver, and SHOULD
16 //! query remote users as part of the search.
17 //!
18 //! The search is performed case-insensitively on user IDs and display
19 //! names preferably using a collation determined based upon the
20 //! `Accept-Language` header provided in the request, if present.
21 class QUOTIENT_API SearchUserDirectoryJob : public BaseJob {
22 public:
23  // Inner data structures
24 
25  struct QUOTIENT_API User {
26  //! The user's matrix user ID.
27  QString userId;
28 
29  //! The display name of the user, if one exists.
30  QString displayName{};
31 
32  //! The avatar url, as an [`mxc://` URI](/client-server-api/#matrix-content-mxc-uris), if
33  //! one exists.
34  QUrl avatarUrl{};
35  };
36 
37  // Construction/destruction
38 
39  //! \param searchTerm
40  //! The term to search for
41  //!
42  //! \param limit
43  //! The maximum number of results to return. Defaults to 10.
44  explicit SearchUserDirectoryJob(const QString& searchTerm,
45  std::optional<int> limit = std::nullopt);
46 
47  // Result properties
48 
49  //! Ordered by rank and then whether or not profile info is available.
50  QVector<User> results() const { return loadFromJson<QVector<User>>("results"_L1); }
51 
52  //! Indicates if the result list has been truncated by the limit.
53  bool limited() const { return loadFromJson<bool>("limited"_L1); }
54 
55  struct Response {
56  //! Ordered by rank and then whether or not profile info is available.
57  QVector<User> results{};
58 
59  //! Indicates if the result list has been truncated by the limit.
60  bool limited{};
61  };
62 };
63 
64 template <std::derived_from<SearchUserDirectoryJob> JobT>
65 constexpr inline auto doCollectResponse<JobT> =
66  [](JobT* j) -> SearchUserDirectoryJob::Response { return { j->results(), j->limited() }; };
67 
68 template <>
69 struct QUOTIENT_API JsonObjectConverter<SearchUserDirectoryJob::User> {
70  static void fillFrom(const QJsonObject& jo, SearchUserDirectoryJob::User& result)
71  {
72  fillFromJson(jo.value("user_id"_L1), result.userId);
73  fillFromJson(jo.value("display_name"_L1), result.displayName);
74  fillFromJson(jo.value("avatar_url"_L1), result.avatarUrl);
75  }
76 };
77 
78 } // namespace Quotient