libQuotient
A Qt library for building matrix clients
pushrules.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/csapi/definitions/push_condition.h>
6 #include <Quotient/csapi/definitions/push_rule.h>
7 #include <Quotient/csapi/definitions/push_ruleset.h>
8 
9 #include <Quotient/jobs/basejob.h>
10 
11 namespace Quotient {
12 
13 //! \brief Retrieve all push rulesets.
14 //!
15 //! Retrieve all push rulesets for this user. Currently the only push ruleset
16 //! defined is `global`.
17 class QUOTIENT_API GetPushRulesJob : public BaseJob {
18 public:
19  explicit GetPushRulesJob();
20 
21  //! \brief Construct a URL without creating a full-fledged job object
22  //!
23  //! This function can be used when a URL for GetPushRulesJob
24  //! is necessary but the job itself isn't.
25  static QUrl makeRequestUrl(const HomeserverData& hsData);
26 
27  // Result properties
28 
29  //! The global ruleset.
30  PushRuleset global() const { return loadFromJson<PushRuleset>("global"_L1); }
31 };
32 
33 inline auto collectResponse(const GetPushRulesJob* job) { return job->global(); }
34 
35 //! \brief Retrieve all push rules.
36 //!
37 //! Retrieve all push rules for this user.
38 class QUOTIENT_API GetPushRulesGlobalJob : public BaseJob {
39 public:
40  explicit GetPushRulesGlobalJob();
41 
42  //! \brief Construct a URL without creating a full-fledged job object
43  //!
44  //! This function can be used when a URL for GetPushRulesGlobalJob
45  //! is necessary but the job itself isn't.
46  static QUrl makeRequestUrl(const HomeserverData& hsData);
47 
48  // Result properties
49 
50  //! All the push rules for this user.
51  PushRuleset data() const { return fromJson<PushRuleset>(jsonData()); }
52 };
53 
54 inline auto collectResponse(const GetPushRulesGlobalJob* job) { return job->data(); }
55 
56 //! \brief Retrieve a push rule.
57 //!
58 //! Retrieve a single specified push rule.
59 class QUOTIENT_API GetPushRuleJob : public BaseJob {
60 public:
61  //! \param kind
62  //! The kind of rule
63  //!
64  //! \param ruleId
65  //! The identifier for the rule.
66  explicit GetPushRuleJob(const QString& kind, const QString& ruleId);
67 
68  //! \brief Construct a URL without creating a full-fledged job object
69  //!
70  //! This function can be used when a URL for GetPushRuleJob
71  //! is necessary but the job itself isn't.
72  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& kind,
73  const QString& ruleId);
74 
75  // Result properties
76 
77  //! The specific push rule. This will also include keys specific to the
78  //! rule itself such as the rule's `actions` and `conditions` if set.
79  PushRule pushRule() const { return fromJson<PushRule>(jsonData()); }
80 };
81 
82 inline auto collectResponse(const GetPushRuleJob* job) { return job->pushRule(); }
83 
84 //! \brief Delete a push rule.
85 //!
86 //! This endpoint removes the push rule defined in the path.
87 class QUOTIENT_API DeletePushRuleJob : public BaseJob {
88 public:
89  //! \param kind
90  //! The kind of rule
91  //!
92  //! \param ruleId
93  //! The identifier for the rule.
94  explicit DeletePushRuleJob(const QString& kind, const QString& ruleId);
95 
96  //! \brief Construct a URL without creating a full-fledged job object
97  //!
98  //! This function can be used when a URL for DeletePushRuleJob
99  //! is necessary but the job itself isn't.
100  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& kind,
101  const QString& ruleId);
102 };
103 
104 //! \brief Add or change a push rule.
105 //!
106 //! This endpoint allows the creation and modification of user defined push
107 //! rules.
108 //!
109 //! If a rule with the same `rule_id` already exists among rules of the same
110 //! kind, it is updated with the new parameters, otherwise a new rule is
111 //! created.
112 //!
113 //! If both `after` and `before` are provided, the new or updated rule must
114 //! be the next most important rule with respect to the rule identified by
115 //! `before`.
116 //!
117 //! If neither `after` nor `before` are provided and the rule is created, it
118 //! should be added as the most important user defined rule among rules of
119 //! the same kind.
120 //!
121 //! When creating push rules, they MUST be enabled by default.
122 class QUOTIENT_API SetPushRuleJob : public BaseJob {
123 public:
124  //! \param kind
125  //! The kind of rule
126  //!
127  //! \param ruleId
128  //! The identifier for the rule. If the string starts with a dot ("."),
129  //! the request MUST be rejected as this is reserved for server-default
130  //! rules. Slashes ("/") and backslashes ("\\") are also not allowed.
131  //!
132  //! \param actions
133  //! The action(s) to perform when the conditions for this rule are met.
134  //!
135  //! \param before
136  //! Use 'before' with a `rule_id` as its value to make the new rule the
137  //! next-most important rule with respect to the given user defined rule.
138  //! It is not possible to add a rule relative to a predefined server rule.
139  //!
140  //! \param after
141  //! This makes the new rule the next-less important rule relative to the
142  //! given user defined rule. It is not possible to add a rule relative
143  //! to a predefined server rule.
144  //!
145  //! \param conditions
146  //! The conditions that must hold true for an event in order for a
147  //! rule to be applied to an event. A rule with no conditions
148  //! always matches. Only applicable to `underride` and `override` rules.
149  //!
150  //! \param pattern
151  //! Only applicable to `content` rules. The glob-style pattern to match against.
152  explicit SetPushRuleJob(const QString& kind, const QString& ruleId,
153  const QVector<QVariant>& actions, const QString& before = {},
154  const QString& after = {}, const QVector<PushCondition>& conditions = {},
155  const QString& pattern = {});
156 };
157 
158 //! \brief Get whether a push rule is enabled
159 //!
160 //! This endpoint gets whether the specified push rule is enabled.
161 class QUOTIENT_API IsPushRuleEnabledJob : public BaseJob {
162 public:
163  //! \param kind
164  //! The kind of rule
165  //!
166  //! \param ruleId
167  //! The identifier for the rule.
168  explicit IsPushRuleEnabledJob(const QString& kind, const QString& ruleId);
169 
170  //! \brief Construct a URL without creating a full-fledged job object
171  //!
172  //! This function can be used when a URL for IsPushRuleEnabledJob
173  //! is necessary but the job itself isn't.
174  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& kind,
175  const QString& ruleId);
176 
177  // Result properties
178 
179  //! Whether the push rule is enabled or not.
180  bool enabled() const { return loadFromJson<bool>("enabled"_L1); }
181 };
182 
183 inline auto collectResponse(const IsPushRuleEnabledJob* job) { return job->enabled(); }
184 
185 //! \brief Enable or disable a push rule.
186 //!
187 //! This endpoint allows clients to enable or disable the specified push rule.
188 class QUOTIENT_API SetPushRuleEnabledJob : public BaseJob {
189 public:
190  //! \param kind
191  //! The kind of rule
192  //!
193  //! \param ruleId
194  //! The identifier for the rule.
195  //!
196  //! \param enabled
197  //! Whether the push rule is enabled or not.
198  explicit SetPushRuleEnabledJob(const QString& kind, const QString& ruleId, bool enabled);
199 };
200 
201 //! \brief The actions for a push rule
202 //!
203 //! This endpoint get the actions for the specified push rule.
204 class QUOTIENT_API GetPushRuleActionsJob : public BaseJob {
205 public:
206  //! \param kind
207  //! The kind of rule
208  //!
209  //! \param ruleId
210  //! The identifier for the rule.
211  explicit GetPushRuleActionsJob(const QString& kind, const QString& ruleId);
212 
213  //! \brief Construct a URL without creating a full-fledged job object
214  //!
215  //! This function can be used when a URL for GetPushRuleActionsJob
216  //! is necessary but the job itself isn't.
217  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& kind,
218  const QString& ruleId);
219 
220  // Result properties
221 
222  //! The action(s) to perform for this rule.
223  QVector<QVariant> actions() const { return loadFromJson<QVector<QVariant>>("actions"_L1); }
224 };
225 
226 inline auto collectResponse(const GetPushRuleActionsJob* job) { return job->actions(); }
227 
228 //! \brief Set the actions for a push rule.
229 //!
230 //! This endpoint allows clients to change the actions of a push rule.
231 //! This can be used to change the actions of builtin rules.
232 class QUOTIENT_API SetPushRuleActionsJob : public BaseJob {
233 public:
234  //! \param kind
235  //! The kind of rule
236  //!
237  //! \param ruleId
238  //! The identifier for the rule.
239  //!
240  //! \param actions
241  //! The action(s) to perform for this rule.
242  explicit SetPushRuleActionsJob(const QString& kind, const QString& ruleId,
243  const QVector<QVariant>& actions);
244 };
245 
246 } // namespace Quotient