1 /******************************************************************************
2  * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3  */
4 
5 #pragma once
6 
7 #include "jobs/basejob.h"
8 
9 namespace Quotient {
10 
11 /*! \brief Gets the current pushers for the authenticated user
12  *
13  * Gets all currently active pushers for the authenticated user.
14  */
15 class GetPushersJob : public BaseJob {
16 public:
17     // Inner data structures
18 
19     /// A dictionary of information for the pusher implementation
20     /// itself.
21     struct PusherData {
22         /// Required if `kind` is `http`. The URL to use to send
23         /// notifications to.
24         QString url;
25         /// The format to use when sending notifications to the Push
26         /// Gateway.
27         QString format;
28     };
29 
30     /// Gets all currently active pushers for the authenticated user.
31     struct Pusher {
32         /// This is a unique identifier for this pusher. See `/set` for
33         /// more detail.
34         /// Max length, 512 bytes.
35         QString pushkey;
36         /// The kind of pusher. `"http"` is a pusher that
37         /// sends HTTP pokes.
38         QString kind;
39         /// This is a reverse-DNS style identifier for the application.
40         /// Max length, 64 chars.
41         QString appId;
42         /// A string that will allow the user to identify what application
43         /// owns this pusher.
44         QString appDisplayName;
45         /// A string that will allow the user to identify what device owns
46         /// this pusher.
47         QString deviceDisplayName;
48         /// This string determines which set of device specific rules this
49         /// pusher executes.
50         QString profileTag;
51         /// The preferred language for receiving notifications (e.g. 'en'
52         /// or 'en-US')
53         QString lang;
54         /// A dictionary of information for the pusher implementation
55         /// itself.
56         PusherData data;
57     };
58 
59     // Construction/destruction
60 
61     /// Gets the current pushers for the authenticated user
62     explicit GetPushersJob();
63 
64     /*! \brief Construct a URL without creating a full-fledged job object
65      *
66      * This function can be used when a URL for GetPushersJob
67      * is necessary but the job itself isn't.
68      */
69     static QUrl makeRequestUrl(QUrl baseUrl);
70 
71     // Result properties
72 
73     /// An array containing the current pushers for the user
pushers()74     QVector<Pusher> pushers() const
75     {
76         return loadFromJson<QVector<Pusher>>("pushers"_ls);
77     }
78 };
79 
80 template <>
81 struct JsonObjectConverter<GetPushersJob::PusherData> {
82     static void fillFrom(const QJsonObject& jo,
83                          GetPushersJob::PusherData& result)
84     {
85         fromJson(jo.value("url"_ls), result.url);
86         fromJson(jo.value("format"_ls), result.format);
87     }
88 };
89 
90 template <>
91 struct JsonObjectConverter<GetPushersJob::Pusher> {
92     static void fillFrom(const QJsonObject& jo, GetPushersJob::Pusher& result)
93     {
94         fromJson(jo.value("pushkey"_ls), result.pushkey);
95         fromJson(jo.value("kind"_ls), result.kind);
96         fromJson(jo.value("app_id"_ls), result.appId);
97         fromJson(jo.value("app_display_name"_ls), result.appDisplayName);
98         fromJson(jo.value("device_display_name"_ls), result.deviceDisplayName);
99         fromJson(jo.value("profile_tag"_ls), result.profileTag);
100         fromJson(jo.value("lang"_ls), result.lang);
101         fromJson(jo.value("data"_ls), result.data);
102     }
103 };
104 
105 /*! \brief Modify a pusher for this user on the homeserver.
106  *
107  * This endpoint allows the creation, modification and deletion of
108  * [pushers](/client-server-api/#push-notifications) for this user ID. The
109  * behaviour of this endpoint varies depending on the values in the JSON body.
110  */
111 class PostPusherJob : public BaseJob {
112 public:
113     // Inner data structures
114 
115     /// A dictionary of information for the pusher implementation
116     /// itself. If `kind` is `http`, this should contain `url`
117     /// which is the URL to use to send notifications to.
118     struct PusherData {
119         /// Required if `kind` is `http`. The URL to use to send
120         /// notifications to. MUST be an HTTPS URL with a path of
121         /// `/_matrix/push/v1/notify`.
122         QString url;
123         /// The format to send notifications in to Push Gateways if the
124         /// `kind` is `http`. The details about what fields the
125         /// homeserver should send to the push gateway are defined in the
126         /// [Push Gateway Specification](/push-gateway-api/). Currently the only
127         /// format available is 'event_id_only'.
128         QString format;
129     };
130 
131     // Construction/destruction
132 
133     /*! \brief Modify a pusher for this user on the homeserver.
134      *
135      * \param pushkey
136      *   This is a unique identifier for this pusher. The value you
137      *   should use for this is the routing or destination address
138      *   information for the notification, for example, the APNS token
139      *   for APNS or the Registration ID for GCM. If your notification
140      *   client has no such concept, use any unique identifier.
141      *   Max length, 512 bytes.
142      *
143      *   If the `kind` is `"email"`, this is the email address to
144      *   send notifications to.
145      *
146      * \param kind
147      *   The kind of pusher to configure. `"http"` makes a pusher that
148      *   sends HTTP pokes. `"email"` makes a pusher that emails the
149      *   user with unread notifications. `null` deletes the pusher.
150      *
151      * \param appId
152      *   This is a reverse-DNS style identifier for the application.
153      *   It is recommended that this end with the platform, such that
154      *   different platform versions get different app identifiers.
155      *   Max length, 64 chars.
156      *
157      *   If the `kind` is `"email"`, this is `"m.email"`.
158      *
159      * \param appDisplayName
160      *   A string that will allow the user to identify what application
161      *   owns this pusher.
162      *
163      * \param deviceDisplayName
164      *   A string that will allow the user to identify what device owns
165      *   this pusher.
166      *
167      * \param lang
168      *   The preferred language for receiving notifications (e.g. 'en'
169      *   or 'en-US').
170      *
171      * \param data
172      *   A dictionary of information for the pusher implementation
173      *   itself. If `kind` is `http`, this should contain `url`
174      *   which is the URL to use to send notifications to.
175      *
176      * \param profileTag
177      *   This string determines which set of device specific rules this
178      *   pusher executes.
179      *
180      * \param append
181      *   If true, the homeserver should add another pusher with the
182      *   given pushkey and App ID in addition to any others with
183      *   different user IDs. Otherwise, the homeserver must remove any
184      *   other pushers with the same App ID and pushkey for different
185      *   users. The default is `false`.
186      */
187     explicit PostPusherJob(const QString& pushkey, const QString& kind,
188                            const QString& appId, const QString& appDisplayName,
189                            const QString& deviceDisplayName,
190                            const QString& lang, const PusherData& data,
191                            const QString& profileTag = {},
192                            Omittable<bool> append = none);
193 };
194 
195 template <>
196 struct JsonObjectConverter<PostPusherJob::PusherData> {
197     static void dumpTo(QJsonObject& jo, const PostPusherJob::PusherData& pod)
198     {
199         addParam<IfNotEmpty>(jo, QStringLiteral("url"), pod.url);
200         addParam<IfNotEmpty>(jo, QStringLiteral("format"), pod.format);
201     }
202 };
203 
204 } // namespace Quotient
205