aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-29 17:19:18 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-29 18:33:08 +0900
commit68358af90bdfbcb6f2884c6d1c795f1724cf840b (patch)
tree02ae3f7c8bc5cb49ee5cb35257aaf3b9443f7b7e
parent941cfdf8b591bf14002f28e99e06c200dc5bcc84 (diff)
downloadlibquotient-68358af90bdfbcb6f2884c6d1c795f1724cf840b.tar.gz
libquotient-68358af90bdfbcb6f2884c6d1c795f1724cf840b.zip
csapi: define PushRule more accurately
It's not always a JSON object; it's either a SetTweakAction object or a string. (Unfortunately, QVariant isn't a template type and there's no easy way to put Q_DECLARE_METATYPE(SetTweakAction) in a Mustache template, so adding one is left as an exercise to the user now.)
-rw-r--r--lib/csapi/definitions/push_rule.cpp18
-rw-r--r--lib/csapi/definitions/push_rule.h27
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp
index 833135ec..1ee57945 100644
--- a/lib/csapi/definitions/push_rule.cpp
+++ b/lib/csapi/definitions/push_rule.cpp
@@ -6,6 +6,24 @@
using namespace QMatrixClient;
+QJsonObject QMatrixClient::toJson(const SetTweakAction& pod)
+{
+ QJsonObject _json = toJson(pod.additionalProperties);
+ addParam<>(_json, QStringLiteral("set_tweak"), pod.setTweak);
+ return _json;
+}
+
+SetTweakAction FromJson<SetTweakAction>::operator()(const QJsonValue& jv)
+{
+ auto _json = jv.toObject();
+ SetTweakAction result;
+ result.setTweak =
+ fromJson<QString>(_json.take("set_tweak"_ls));
+
+ result.additionalProperties = fromJson<QVariantHash>(_json);
+ return result;
+}
+
QJsonObject QMatrixClient::toJson(const PushRule& pod)
{
QJsonObject _json;
diff --git a/lib/csapi/definitions/push_rule.h b/lib/csapi/definitions/push_rule.h
index c6542aa6..6959e9d1 100644
--- a/lib/csapi/definitions/push_rule.h
+++ b/lib/csapi/definitions/push_rule.h
@@ -7,15 +7,38 @@
#include "converters.h"
#include "csapi/definitions/push_condition.h"
-#include "converters.h"
#include <QtCore/QVector>
#include <QtCore/QVariant>
-#include <QtCore/QJsonObject>
+#include "converters.h"
namespace QMatrixClient
{
// Data structures
+ /// Specifies an entry to the 'tweaks' dictionary sent in
+ /// the notification request to the Push Gateway.
+ /// Tweak parameters, if any, are provided as additional
+ /// key-value pairs in this structure.
+ struct SetTweakAction
+ {
+ /// The tweak type. Two predefined types are `sound`
+ /// and `highlight`; client applications and Push Gateways
+ /// may agree on additional tweak types.
+ QString setTweak;
+ /// Specifies an entry to the 'tweaks' dictionary sent in
+ /// the notification request to the Push Gateway.
+ /// Tweak parameters, if any, are provided as additional
+ /// key-value pairs in this structure.
+ QVariantHash additionalProperties;
+ };
+
+ QJsonObject toJson(const SetTweakAction& pod);
+
+ template <> struct FromJson<SetTweakAction>
+ {
+ SetTweakAction operator()(const QJsonValue& jv);
+ };
+
struct PushRule
{
/// The actions to perform when this rule is matched.