aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/definitions/push_rule.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/definitions/push_rule.h
parent8ad8a74152c5701b6ca1f9a00487ba9257a439b4 (diff)
parent56c2f2e2b809b9077393eb617828f33d144f5634 (diff)
downloadlibquotient-d911b207f49e936b3e992200796110f0749ed150.tar.gz
libquotient-d911b207f49e936b3e992200796110f0749ed150.zip
New upstream version 0.7.0
Diffstat (limited to 'lib/csapi/definitions/push_rule.h')
-rw-r--r--lib/csapi/definitions/push_rule.h77
1 files changed, 45 insertions, 32 deletions
diff --git a/lib/csapi/definitions/push_rule.h b/lib/csapi/definitions/push_rule.h
index 5f52876d..135537c1 100644
--- a/lib/csapi/definitions/push_rule.h
+++ b/lib/csapi/definitions/push_rule.h
@@ -7,39 +7,52 @@
#include "converters.h"
#include "csapi/definitions/push_condition.h"
-#include "converters.h"
-#include <QtCore/QVector>
-#include <QtCore/QVariant>
-#include <QtCore/QJsonObject>
-namespace QMatrixClient
-{
- // Data structures
+namespace Quotient {
+
+struct PushRule {
+ /// The actions to perform when this rule is matched.
+ QVector<QVariant> actions;
+
+ /// Whether this is a default rule, or has been set explicitly.
+ bool isDefault;
+
+ /// Whether the push rule is enabled or not.
+ bool enabled;
- struct PushRule
+ /// The ID of this rule.
+ QString ruleId;
+
+ /// The conditions that must hold true for an event in order for a rule to
+ /// be applied to an event. A rule with no conditions always matches. Only
+ /// applicable to `underride` and `override` rules.
+ QVector<PushCondition> conditions;
+
+ /// The glob-style pattern to match against. Only applicable to `content`
+ /// rules.
+ QString pattern;
+};
+
+template <>
+struct JsonObjectConverter<PushRule> {
+ static void dumpTo(QJsonObject& jo, const PushRule& pod)
{
- /// The actions to perform when this rule is matched.
- QVector<QVariant> actions;
- /// Whether this is a default rule, or has been set explicitly.
- bool isDefault;
- /// Whether the push rule is enabled or not.
- bool enabled;
- /// The ID of this rule.
- QString ruleId;
- /// The conditions that must hold true for an event in order for a rule to be
- /// applied to an event. A rule with no conditions always matches. Only
- /// applicable to ``underride`` and ``override`` rules.
- QVector<PushCondition> conditions;
- /// The glob-style pattern to match against. Only applicable to ``content``
- /// rules.
- QString pattern;
- };
-
- QJsonObject toJson(const PushRule& pod);
-
- template <> struct FromJsonObject<PushRule>
+ addParam<>(jo, QStringLiteral("actions"), pod.actions);
+ addParam<>(jo, QStringLiteral("default"), pod.isDefault);
+ addParam<>(jo, QStringLiteral("enabled"), pod.enabled);
+ addParam<>(jo, QStringLiteral("rule_id"), pod.ruleId);
+ addParam<IfNotEmpty>(jo, QStringLiteral("conditions"), pod.conditions);
+ addParam<IfNotEmpty>(jo, QStringLiteral("pattern"), pod.pattern);
+ }
+ static void fillFrom(const QJsonObject& jo, PushRule& pod)
{
- PushRule operator()(const QJsonObject& jo) const;
- };
-
-} // namespace QMatrixClient
+ fromJson(jo.value("actions"_ls), pod.actions);
+ fromJson(jo.value("default"_ls), pod.isDefault);
+ fromJson(jo.value("enabled"_ls), pod.enabled);
+ fromJson(jo.value("rule_id"_ls), pod.ruleId);
+ fromJson(jo.value("conditions"_ls), pod.conditions);
+ fromJson(jo.value("pattern"_ls), pod.pattern);
+ }
+};
+
+} // namespace Quotient