From 68358af90bdfbcb6f2884c6d1c795f1724cf840b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 29 Jul 2018 17:19:18 +0900 Subject: 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.) --- lib/csapi/definitions/push_rule.cpp | 18 ++++++++++++++++++ lib/csapi/definitions/push_rule.h | 27 +++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'lib') 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::operator()(const QJsonValue& jv) +{ + auto _json = jv.toObject(); + SetTweakAction result; + result.setTweak = + fromJson(_json.take("set_tweak"_ls)); + + result.additionalProperties = fromJson(_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 #include -#include +#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 operator()(const QJsonValue& jv); + }; + struct PushRule { /// The actions to perform when this rule is matched. -- cgit v1.2.3