aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-03 19:50:54 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-03 19:50:54 +0900
commitddf10847d496dd65b00bc2026412958acd09790d (patch)
treef7a90ff1177897095f705fec2d108cba2cc8a962
parent826b8fb5afc80dd6adcc7ecee22997365a59f9d0 (diff)
downloadlibquotient-ddf10847d496dd65b00bc2026412958acd09790d.tar.gz
libquotient-ddf10847d496dd65b00bc2026412958acd09790d.zip
csapi: jobs to setup push-rules
-rw-r--r--lib/csapi/definitions/push_condition.cpp34
-rw-r--r--lib/csapi/definitions/push_condition.h30
-rw-r--r--lib/csapi/definitions/push_rule.cpp40
-rw-r--r--lib/csapi/definitions/push_rule.h37
-rw-r--r--lib/csapi/definitions/push_ruleset.cpp37
-rw-r--r--lib/csapi/definitions/push_ruleset.h34
-rw-r--r--lib/csapi/pushrules.cpp210
-rw-r--r--lib/csapi/pushrules.h154
8 files changed, 576 insertions, 0 deletions
diff --git a/lib/csapi/definitions/push_condition.cpp b/lib/csapi/definitions/push_condition.cpp
new file mode 100644
index 00000000..149419f4
--- /dev/null
+++ b/lib/csapi/definitions/push_condition.cpp
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "push_condition.h"
+
+using namespace QMatrixClient;
+
+QJsonObject QMatrixClient::toJson(const PushCondition& pod)
+{
+ QJsonObject _json;
+ addToJson<>(_json, "kind", pod.kind);
+ addToJson<IfNotEmpty>(_json, "key", pod.key);
+ addToJson<IfNotEmpty>(_json, "pattern", pod.pattern);
+ addToJson<IfNotEmpty>(_json, "is", pod.is);
+ return _json;
+}
+
+PushCondition FromJson<PushCondition>::operator()(const QJsonValue& jv)
+{
+ const auto& _json = jv.toObject();
+ PushCondition result;
+ result.kind =
+ fromJson<QString>(_json.value("kind"));
+ result.key =
+ fromJson<QString>(_json.value("key"));
+ result.pattern =
+ fromJson<QString>(_json.value("pattern"));
+ result.is =
+ fromJson<QString>(_json.value("is"));
+
+ return result;
+}
+
diff --git a/lib/csapi/definitions/push_condition.h b/lib/csapi/definitions/push_condition.h
new file mode 100644
index 00000000..5744b9b8
--- /dev/null
+++ b/lib/csapi/definitions/push_condition.h
@@ -0,0 +1,30 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+
+
+#include "converters.h"
+
+namespace QMatrixClient
+{
+ // Data structures
+
+ struct PushCondition
+ {
+ QString kind;
+ QString key;
+ QString pattern;
+ QString is;
+ };
+
+ QJsonObject toJson(const PushCondition& pod);
+
+ template <> struct FromJson<PushCondition>
+ {
+ PushCondition operator()(const QJsonValue& jv);
+ };
+
+} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp
new file mode 100644
index 00000000..3a44a385
--- /dev/null
+++ b/lib/csapi/definitions/push_rule.cpp
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "push_rule.h"
+
+using namespace QMatrixClient;
+
+QJsonObject QMatrixClient::toJson(const PushRule& pod)
+{
+ QJsonObject _json;
+ addToJson<>(_json, "actions", pod.actions);
+ addToJson<>(_json, "default", pod.isDefault);
+ addToJson<>(_json, "enabled", pod.enabled);
+ addToJson<>(_json, "rule_id", pod.ruleId);
+ addToJson<IfNotEmpty>(_json, "conditions", pod.conditions);
+ addToJson<IfNotEmpty>(_json, "pattern", pod.pattern);
+ return _json;
+}
+
+PushRule FromJson<PushRule>::operator()(const QJsonValue& jv)
+{
+ const auto& _json = jv.toObject();
+ PushRule result;
+ result.actions =
+ fromJson<QVector<QVariant>>(_json.value("actions"));
+ result.isDefault =
+ fromJson<bool>(_json.value("default"));
+ result.enabled =
+ fromJson<bool>(_json.value("enabled"));
+ result.ruleId =
+ fromJson<QString>(_json.value("rule_id"));
+ result.conditions =
+ fromJson<QVector<PushCondition>>(_json.value("conditions"));
+ result.pattern =
+ fromJson<QString>(_json.value("pattern"));
+
+ return result;
+}
+
diff --git a/lib/csapi/definitions/push_rule.h b/lib/csapi/definitions/push_rule.h
new file mode 100644
index 00000000..853210d0
--- /dev/null
+++ b/lib/csapi/definitions/push_rule.h
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+
+#include "lib/csapi/definitions/push_condition.h"
+#include "converters.h"
+#include <QtCore/QVector>
+#include <QtCore/QVariant>
+#include <QtCore/QJsonObject>
+
+#include "converters.h"
+
+namespace QMatrixClient
+{
+ // Data structures
+
+ struct PushRule
+ {
+ QVector<QVariant> actions;
+ bool isDefault;
+ bool enabled;
+ QString ruleId;
+ QVector<PushCondition> conditions;
+ QString pattern;
+ };
+
+ QJsonObject toJson(const PushRule& pod);
+
+ template <> struct FromJson<PushRule>
+ {
+ PushRule operator()(const QJsonValue& jv);
+ };
+
+} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/push_ruleset.cpp b/lib/csapi/definitions/push_ruleset.cpp
new file mode 100644
index 00000000..98d79248
--- /dev/null
+++ b/lib/csapi/definitions/push_ruleset.cpp
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "push_ruleset.h"
+
+using namespace QMatrixClient;
+
+QJsonObject QMatrixClient::toJson(const PushRuleset& pod)
+{
+ QJsonObject _json;
+ addToJson<IfNotEmpty>(_json, "content", pod.content);
+ addToJson<IfNotEmpty>(_json, "override", pod.override);
+ addToJson<IfNotEmpty>(_json, "room", pod.room);
+ addToJson<IfNotEmpty>(_json, "sender", pod.sender);
+ addToJson<IfNotEmpty>(_json, "underride", pod.underride);
+ return _json;
+}
+
+PushRuleset FromJson<PushRuleset>::operator()(const QJsonValue& jv)
+{
+ const auto& _json = jv.toObject();
+ PushRuleset result;
+ result.content =
+ fromJson<QVector<PushRule>>(_json.value("content"));
+ result.override =
+ fromJson<QVector<PushRule>>(_json.value("override"));
+ result.room =
+ fromJson<QVector<PushRule>>(_json.value("room"));
+ result.sender =
+ fromJson<QVector<PushRule>>(_json.value("sender"));
+ result.underride =
+ fromJson<QVector<PushRule>>(_json.value("underride"));
+
+ return result;
+}
+
diff --git a/lib/csapi/definitions/push_ruleset.h b/lib/csapi/definitions/push_ruleset.h
new file mode 100644
index 00000000..96199a11
--- /dev/null
+++ b/lib/csapi/definitions/push_ruleset.h
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+
+#include <QtCore/QVector>
+#include "converters.h"
+#include "lib/csapi/definitions/push_rule.h"
+
+#include "converters.h"
+
+namespace QMatrixClient
+{
+ // Data structures
+
+ struct PushRuleset
+ {
+ QVector<PushRule> content;
+ QVector<PushRule> override;
+ QVector<PushRule> room;
+ QVector<PushRule> sender;
+ QVector<PushRule> underride;
+ };
+
+ QJsonObject toJson(const PushRuleset& pod);
+
+ template <> struct FromJson<PushRuleset>
+ {
+ PushRuleset operator()(const QJsonValue& jv);
+ };
+
+} // namespace QMatrixClient
diff --git a/lib/csapi/pushrules.cpp b/lib/csapi/pushrules.cpp
new file mode 100644
index 00000000..eca46247
--- /dev/null
+++ b/lib/csapi/pushrules.cpp
@@ -0,0 +1,210 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "pushrules.h"
+
+#include "converters.h"
+
+#include <QtCore/QStringBuilder>
+
+using namespace QMatrixClient;
+
+static const auto basePath = QStringLiteral("/_matrix/client/r0");
+
+class GetPushRulesJob::Private
+{
+ public:
+ PushRuleset global;
+};
+
+QUrl GetPushRulesJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/pushrules");
+}
+
+GetPushRulesJob::GetPushRulesJob()
+ : BaseJob(HttpVerb::Get, "GetPushRulesJob",
+ basePath % "/pushrules")
+ , d(new Private)
+{
+}
+
+GetPushRulesJob::~GetPushRulesJob() = default;
+
+const PushRuleset& GetPushRulesJob::global() const
+{
+ return d->global;
+}
+
+BaseJob::Status GetPushRulesJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ if (!json.contains("global"))
+ return { JsonParseError,
+ "The key 'global' not found in the response" };
+ d->global = fromJson<PushRuleset>(json.value("global"));
+ return Success;
+}
+
+class GetPushRuleJob::Private
+{
+ public:
+ PushRule data;
+};
+
+QUrl GetPushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId);
+}
+
+GetPushRuleJob::GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId)
+ : BaseJob(HttpVerb::Get, "GetPushRuleJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId)
+ , d(new Private)
+{
+}
+
+GetPushRuleJob::~GetPushRuleJob() = default;
+
+const PushRule& GetPushRuleJob::data() const
+{
+ return d->data;
+}
+
+BaseJob::Status GetPushRuleJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ if (!json.contains("data"))
+ return { JsonParseError,
+ "The key 'data' not found in the response" };
+ d->data = fromJson<PushRule>(json.value("data"));
+ return Success;
+}
+
+QUrl DeletePushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId);
+}
+
+DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId)
+ : BaseJob(HttpVerb::Delete, "DeletePushRuleJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId)
+{
+}
+
+BaseJob::Query queryToSetPushRule(const QString& before, const QString& after)
+{
+ BaseJob::Query _q;
+ if (!before.isEmpty())
+ _q.addQueryItem("before", before);
+ if (!after.isEmpty())
+ _q.addQueryItem("after", after);
+ return _q;
+}
+
+SetPushRuleJob::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)
+ : BaseJob(HttpVerb::Put, "SetPushRuleJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId,
+ queryToSetPushRule(before, after))
+{
+ QJsonObject _data;
+ addToJson<>(_data, "actions", actions);
+ addToJson<IfNotEmpty>(_data, "conditions", conditions);
+ addToJson<IfNotEmpty>(_data, "pattern", pattern);
+ setRequestData(_data);
+}
+
+class IsPushRuleEnabledJob::Private
+{
+ public:
+ bool enabled;
+};
+
+QUrl IsPushRuleEnabledJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled");
+}
+
+IsPushRuleEnabledJob::IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId)
+ : BaseJob(HttpVerb::Get, "IsPushRuleEnabledJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled")
+ , d(new Private)
+{
+}
+
+IsPushRuleEnabledJob::~IsPushRuleEnabledJob() = default;
+
+bool IsPushRuleEnabledJob::enabled() const
+{
+ return d->enabled;
+}
+
+BaseJob::Status IsPushRuleEnabledJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ if (!json.contains("enabled"))
+ return { JsonParseError,
+ "The key 'enabled' not found in the response" };
+ d->enabled = fromJson<bool>(json.value("enabled"));
+ return Success;
+}
+
+SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled)
+ : BaseJob(HttpVerb::Put, "SetPushRuleEnabledJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled")
+{
+ QJsonObject _data;
+ addToJson<>(_data, "enabled", enabled);
+ setRequestData(_data);
+}
+
+class GetPushRuleActionsJob::Private
+{
+ public:
+ QStringList actions;
+};
+
+QUrl GetPushRuleActionsJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions");
+}
+
+GetPushRuleActionsJob::GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId)
+ : BaseJob(HttpVerb::Get, "GetPushRuleActionsJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions")
+ , d(new Private)
+{
+}
+
+GetPushRuleActionsJob::~GetPushRuleActionsJob() = default;
+
+const QStringList& GetPushRuleActionsJob::actions() const
+{
+ return d->actions;
+}
+
+BaseJob::Status GetPushRuleActionsJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ if (!json.contains("actions"))
+ return { JsonParseError,
+ "The key 'actions' not found in the response" };
+ d->actions = fromJson<QStringList>(json.value("actions"));
+ return Success;
+}
+
+SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions)
+ : BaseJob(HttpVerb::Put, "SetPushRuleActionsJob",
+ basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions")
+{
+ QJsonObject _data;
+ addToJson<>(_data, "actions", actions);
+ setRequestData(_data);
+}
+
diff --git a/lib/csapi/pushrules.h b/lib/csapi/pushrules.h
new file mode 100644
index 00000000..a01049af
--- /dev/null
+++ b/lib/csapi/pushrules.h
@@ -0,0 +1,154 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+#include "jobs/basejob.h"
+
+#include "lib/csapi/definitions/push_ruleset.h"
+#include <QtCore/QVector>
+#include "converters.h"
+#include "lib/csapi/definitions/push_rule.h"
+#include "lib/csapi/definitions/push_condition.h"
+
+namespace QMatrixClient
+{
+ // Operations
+
+ class GetPushRulesJob : public BaseJob
+ {
+ public:
+ explicit GetPushRulesJob();
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetPushRulesJob. 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
+
+ const PushRuleset& global() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+
+ class GetPushRuleJob : public BaseJob
+ {
+ public:
+ explicit GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId);
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetPushRuleJob. 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
+
+ const PushRule& data() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+
+ class DeletePushRuleJob : public BaseJob
+ {
+ public:
+ explicit DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId);
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * DeletePushRuleJob. 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);
+
+ };
+
+ class SetPushRuleJob : public BaseJob
+ {
+ public:
+ 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 = {});
+ };
+
+ class IsPushRuleEnabledJob : public BaseJob
+ {
+ public:
+ explicit IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId);
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * IsPushRuleEnabledJob. 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
+
+ bool enabled() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+
+ class SetPushRuleEnabledJob : public BaseJob
+ {
+ public:
+ explicit SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled);
+ };
+
+ class GetPushRuleActionsJob : public BaseJob
+ {
+ public:
+ explicit GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId);
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetPushRuleActionsJob. 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);
+
+ ~GetPushRuleActionsJob() override;
+
+ // Result properties
+
+ const QStringList& actions() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+
+ class SetPushRuleActionsJob : public BaseJob
+ {
+ public:
+ explicit SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions);
+ };
+} // namespace QMatrixClient