diff options
author | n-peugnet <n.peugnet@free.fr> | 2022-10-06 19:27:24 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2022-10-06 19:27:24 +0200 |
commit | d911b207f49e936b3e992200796110f0749ed150 (patch) | |
tree | 96d20ebb4d074a4c1755e21cb316a52d584daee3 /lib/csapi/pushrules.h | |
parent | 8ad8a74152c5701b6ca1f9a00487ba9257a439b4 (diff) | |
parent | 56c2f2e2b809b9077393eb617828f33d144f5634 (diff) | |
download | libquotient-d911b207f49e936b3e992200796110f0749ed150.tar.gz libquotient-d911b207f49e936b3e992200796110f0749ed150.zip |
New upstream version 0.7.0
Diffstat (limited to 'lib/csapi/pushrules.h')
-rw-r--r-- | lib/csapi/pushrules.h | 523 |
1 files changed, 266 insertions, 257 deletions
diff --git a/lib/csapi/pushrules.h b/lib/csapi/pushrules.h index c038401c..d6c57efd 100644 --- a/lib/csapi/pushrules.h +++ b/lib/csapi/pushrules.h @@ -4,270 +4,279 @@ #pragma once -#include "jobs/basejob.h" - -#include "csapi/definitions/push_ruleset.h" -#include "converters.h" -#include "csapi/definitions/push_rule.h" -#include <QtCore/QVector> #include "csapi/definitions/push_condition.h" +#include "csapi/definitions/push_rule.h" +#include "csapi/definitions/push_ruleset.h" -namespace QMatrixClient -{ - // Operations - - /// Retrieve all push rulesets. - /// - /// Retrieve all push rulesets for this user. Clients can "drill-down" on - /// the rulesets by suffixing a ``scope`` to this path e.g. - /// ``/pushrules/global/``. This will return a subset of this data under the - /// specified key e.g. the ``global`` key. - class GetPushRulesJob : public BaseJob - { - public: - explicit GetPushRulesJob(); - - /*! Construct a URL without creating a full-fledged job object - * - * This function can be used when a URL for - * GetPushRulesJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl); - - ~GetPushRulesJob() override; - - // Result properties - - /// The global ruleset. - const PushRuleset& global() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - /// Retrieve a push rule. - /// - /// Retrieve a single specified push rule. - class GetPushRuleJob : public BaseJob - { - public: - /*! Retrieve a push rule. - * \param scope - * ``global`` to specify global rules. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - */ - explicit GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId); - - /*! Construct a URL without creating a full-fledged job object - * - * This function can be used when a URL for - * GetPushRuleJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); - - ~GetPushRuleJob() override; - - // Result properties - - /// The push rule. - const PushRule& data() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - /// Delete a push rule. - /// - /// This endpoint removes the push rule defined in the path. - class DeletePushRuleJob : public BaseJob - { - public: - /*! Delete a push rule. - * \param scope - * ``global`` to specify global rules. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - */ - explicit DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId); - - /*! Construct a URL without creating a full-fledged job object - * - * This function can be used when a URL for - * DeletePushRuleJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); - - }; - - /// Add or change a push rule. - /// - /// This endpoint allows the creation, modification and deletion of pushers - /// for this user ID. The behaviour of this endpoint varies depending on the - /// values in the JSON body. - /// - /// When creating push rules, they MUST be enabled by default. - class SetPushRuleJob : public BaseJob - { - public: - /*! Add or change a push rule. - * \param scope - * ``global`` to specify global rules. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - * \param actions - * The action(s) to perform when the conditions for this rule are met. - * \param before - * Use 'before' with a ``rule_id`` as its value to make the new rule the - * next-most important rule with respect to the given user defined rule. - * It is not possible to add a rule relative to a predefined server rule. - * \param after - * This makes the new rule the next-less important rule relative to the - * given user defined rule. It is not possible to add a rule relative - * to a predefined server rule. - * \param conditions - * 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. - * \param pattern - * Only applicable to ``content`` rules. The glob-style pattern to match against. - */ - explicit SetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions, const QString& before = {}, const QString& after = {}, const QVector<PushCondition>& conditions = {}, const QString& pattern = {}); - }; - - /// Get whether a push rule is enabled - /// - /// This endpoint gets whether the specified push rule is enabled. - class IsPushRuleEnabledJob : public BaseJob - { - public: - /*! Get whether a push rule is enabled - * \param scope - * Either ``global`` or ``device/<profile_tag>`` to specify global - * rules or device rules for the given ``profile_tag``. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - */ - explicit IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId); - - /*! Construct a URL without creating a full-fledged job object - * - * This function can be used when a URL for - * IsPushRuleEnabledJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); - - ~IsPushRuleEnabledJob() override; - - // Result properties +#include "jobs/basejob.h" - /// Whether the push rule is enabled or not. - bool enabled() const; +namespace Quotient { - protected: - Status parseJson(const QJsonDocument& data) override; +/*! \brief Retrieve all push rulesets. + * + * Retrieve all push rulesets for this user. Clients can "drill-down" on + * the rulesets by suffixing a `scope` to this path e.g. + * `/pushrules/global/`. This will return a subset of this data under the + * specified key e.g. the `global` key. + */ +class QUOTIENT_API GetPushRulesJob : public BaseJob { +public: + /// Retrieve all push rulesets. + explicit GetPushRulesJob(); - private: - class Private; - QScopedPointer<Private> d; - }; + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetPushRulesJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); - /// Enable or disable a push rule. - /// - /// This endpoint allows clients to enable or disable the specified push rule. - class SetPushRuleEnabledJob : public BaseJob - { - public: - /*! Enable or disable a push rule. - * \param scope - * ``global`` to specify global rules. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - * \param enabled - * Whether the push rule is enabled or not. - */ - explicit SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled); - }; + // Result properties - /// The actions for a push rule - /// - /// This endpoint get the actions for the specified push rule. - class GetPushRuleActionsJob : public BaseJob + /// The global ruleset. + PushRuleset global() const { - public: - /*! The actions for a push rule - * \param scope - * Either ``global`` or ``device/<profile_tag>`` to specify global - * rules or device rules for the given ``profile_tag``. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - */ - explicit GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId); - - /*! Construct a URL without creating a full-fledged job object - * - * This function can be used when a URL for - * GetPushRuleActionsJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); + return loadFromJson<PushRuleset>("global"_ls); + } +}; - ~GetPushRuleActionsJob() override; - - // Result properties - - /// The action(s) to perform for this rule. - const QStringList& actions() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - /// Set the actions for a push rule. - /// - /// This endpoint allows clients to change the actions of a push rule. - /// This can be used to change the actions of builtin rules. - class SetPushRuleActionsJob : public BaseJob +/*! \brief Retrieve a push rule. + * + * Retrieve a single specified push rule. + */ +class QUOTIENT_API GetPushRuleJob : public BaseJob { +public: + /*! \brief Retrieve a push rule. + * + * \param scope + * `global` to specify global rules. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + */ + explicit GetPushRuleJob(const QString& scope, const QString& kind, + const QString& ruleId); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetPushRuleJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, + const QString& kind, const QString& ruleId); + + // Result properties + + /// The specific push rule. This will also include keys specific to the + /// rule itself such as the rule's `actions` and `conditions` if set. + PushRule pushRule() const { return fromJson<PushRule>(jsonData()); } +}; + +/*! \brief Delete a push rule. + * + * This endpoint removes the push rule defined in the path. + */ +class QUOTIENT_API DeletePushRuleJob : public BaseJob { +public: + /*! \brief Delete a push rule. + * + * \param scope + * `global` to specify global rules. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + */ + explicit DeletePushRuleJob(const QString& scope, const QString& kind, + const QString& ruleId); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeletePushRuleJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, + const QString& kind, const QString& ruleId); +}; + +/*! \brief Add or change a push rule. + * + * This endpoint allows the creation, modification and deletion of pushers + * for this user ID. The behaviour of this endpoint varies depending on the + * values in the JSON body. + * + * When creating push rules, they MUST be enabled by default. + */ +class QUOTIENT_API SetPushRuleJob : public BaseJob { +public: + /*! \brief Add or change a push rule. + * + * \param scope + * `global` to specify global rules. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + * + * \param actions + * The action(s) to perform when the conditions for this rule are met. + * + * \param before + * Use 'before' with a `rule_id` as its value to make the new rule the + * next-most important rule with respect to the given user defined rule. + * It is not possible to add a rule relative to a predefined server rule. + * + * \param after + * This makes the new rule the next-less important rule relative to the + * given user defined rule. It is not possible to add a rule relative + * to a predefined server rule. + * + * \param conditions + * 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. + * + * \param pattern + * Only applicable to `content` rules. The glob-style pattern to match + * against. + */ + explicit SetPushRuleJob(const QString& scope, const QString& kind, + const QString& ruleId, + const QVector<QVariant>& actions, + const QString& before = {}, + const QString& after = {}, + const QVector<PushCondition>& conditions = {}, + const QString& pattern = {}); +}; + +/*! \brief Get whether a push rule is enabled + * + * This endpoint gets whether the specified push rule is enabled. + */ +class QUOTIENT_API IsPushRuleEnabledJob : public BaseJob { +public: + /*! \brief Get whether a push rule is enabled + * + * \param scope + * Either `global` or `device/<profile_tag>` to specify global + * rules or device rules for the given `profile_tag`. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + */ + explicit IsPushRuleEnabledJob(const QString& scope, const QString& kind, + const QString& ruleId); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for IsPushRuleEnabledJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, + const QString& kind, const QString& ruleId); + + // Result properties + + /// Whether the push rule is enabled or not. + bool enabled() const { return loadFromJson<bool>("enabled"_ls); } +}; + +/*! \brief Enable or disable a push rule. + * + * This endpoint allows clients to enable or disable the specified push rule. + */ +class QUOTIENT_API SetPushRuleEnabledJob : public BaseJob { +public: + /*! \brief Enable or disable a push rule. + * + * \param scope + * `global` to specify global rules. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + * + * \param enabled + * Whether the push rule is enabled or not. + */ + explicit SetPushRuleEnabledJob(const QString& scope, const QString& kind, + const QString& ruleId, bool enabled); +}; + +/*! \brief The actions for a push rule + * + * This endpoint get the actions for the specified push rule. + */ +class QUOTIENT_API GetPushRuleActionsJob : public BaseJob { +public: + /*! \brief The actions for a push rule + * + * \param scope + * Either `global` or `device/<profile_tag>` to specify global + * rules or device rules for the given `profile_tag`. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + */ + explicit GetPushRuleActionsJob(const QString& scope, const QString& kind, + const QString& ruleId); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetPushRuleActionsJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, + const QString& kind, const QString& ruleId); + + // Result properties + + /// The action(s) to perform for this rule. + QVector<QVariant> actions() const { - public: - /*! Set the actions for a push rule. - * \param scope - * ``global`` to specify global rules. - * \param kind - * The kind of rule - * \param ruleId - * The identifier for the rule. - * \param actions - * The action(s) to perform for this rule. - */ - explicit SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions); - }; -} // namespace QMatrixClient + return loadFromJson<QVector<QVariant>>("actions"_ls); + } +}; + +/*! \brief Set the actions for a push rule. + * + * This endpoint allows clients to change the actions of a push rule. + * This can be used to change the actions of builtin rules. + */ +class QUOTIENT_API SetPushRuleActionsJob : public BaseJob { +public: + /*! \brief Set the actions for a push rule. + * + * \param scope + * `global` to specify global rules. + * + * \param kind + * The kind of rule + * + * \param ruleId + * The identifier for the rule. + * + * \param actions + * The action(s) to perform for this rule. + */ + explicit SetPushRuleActionsJob(const QString& scope, const QString& kind, + const QString& ruleId, + const QVector<QVariant>& actions); +}; + +} // namespace Quotient |