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