aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/pushrules.cpp
diff options
context:
space:
mode:
authorAndres Salomon <dilinger@queued.net>2021-01-18 04:00:14 -0500
committerAndres Salomon <dilinger@queued.net>2021-01-18 04:00:14 -0500
commit09eb39236666e81d5da014acea011dcd74d0999b (patch)
tree52876d96be71be1a39d5d935c1295a51995e8949 /lib/csapi/pushrules.cpp
parentf1788ee27f33e9339334e0d79bde9a27d9ce2e44 (diff)
parenta4e78956f105875625b572d8b98459ffa86fafe5 (diff)
downloadlibquotient-09eb39236666e81d5da014acea011dcd74d0999b.tar.gz
libquotient-09eb39236666e81d5da014acea011dcd74d0999b.zip
Update upstream source from tag 'upstream/0.6.4'
Update to upstream version '0.6.4' with Debian dir aa8705fd74743e79c043bc9e3e425d5064404cfe
Diffstat (limited to 'lib/csapi/pushrules.cpp')
-rw-r--r--lib/csapi/pushrules.cpp237
1 files changed, 82 insertions, 155 deletions
diff --git a/lib/csapi/pushrules.cpp b/lib/csapi/pushrules.cpp
index b91d18f7..86165744 100644
--- a/lib/csapi/pushrules.cpp
+++ b/lib/csapi/pushrules.cpp
@@ -4,101 +4,58 @@
#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;
-};
+using namespace Quotient;
QUrl GetPushRulesJob::makeRequestUrl(QUrl baseUrl)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/pushrules");
+ QStringLiteral("/_matrix/client/r0")
+ % "/pushrules");
}
-static const auto GetPushRulesJobName = QStringLiteral("GetPushRulesJob");
-
GetPushRulesJob::GetPushRulesJob()
- : BaseJob(HttpVerb::Get, GetPushRulesJobName,
- basePath % "/pushrules")
- , d(new Private)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetPushRulesJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules")
{
+ addExpectedKey("global");
}
-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"_ls))
- return { JsonParseError,
- "The key 'global' not found in the response" };
- fromJson(json.value("global"_ls), d->global);
- return Success;
-}
-
-class GetPushRuleJob::Private
-{
- public:
- PushRule data;
-};
-
-QUrl GetPushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+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);
+ QStringLiteral("/_matrix/client/r0")
+ % "/pushrules/" % scope % "/" % kind
+ % "/" % ruleId);
}
-static const auto GetPushRuleJobName = QStringLiteral("GetPushRuleJob");
+GetPushRuleJob::GetPushRuleJob(const QString& scope, const QString& kind,
+ const QString& ruleId)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetPushRuleJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId)
+{}
-GetPushRuleJob::GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId)
- : BaseJob(HttpVerb::Get, GetPushRuleJobName,
- 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)
-{
- fromJson(data, d->data);
- return Success;
-}
-
-QUrl DeletePushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+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);
+ QStringLiteral("/_matrix/client/r0")
+ % "/pushrules/" % scope % "/" % kind
+ % "/" % ruleId);
}
-static const auto DeletePushRuleJobName = QStringLiteral("DeletePushRuleJob");
+DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind,
+ const QString& ruleId)
+ : BaseJob(HttpVerb::Delete, QStringLiteral("DeletePushRuleJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId)
+{}
-DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId)
- : BaseJob(HttpVerb::Delete, DeletePushRuleJobName,
- basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId)
-{
-}
-
-BaseJob::Query queryToSetPushRule(const QString& before, const QString& after)
+auto queryToSetPushRule(const QString& before, const QString& after)
{
BaseJob::Query _q;
addParam<IfNotEmpty>(_q, QStringLiteral("before"), before);
@@ -106,115 +63,85 @@ BaseJob::Query queryToSetPushRule(const QString& before, const QString& after)
return _q;
}
-static const auto SetPushRuleJobName = QStringLiteral("SetPushRuleJob");
-
-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, SetPushRuleJobName,
- basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId,
- queryToSetPushRule(before, after))
+SetPushRuleJob::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)
+ : BaseJob(HttpVerb::Put, QStringLiteral("SetPushRuleJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId,
+ queryToSetPushRule(before, after))
{
QJsonObject _data;
addParam<>(_data, QStringLiteral("actions"), actions);
addParam<IfNotEmpty>(_data, QStringLiteral("conditions"), conditions);
addParam<IfNotEmpty>(_data, QStringLiteral("pattern"), pattern);
- setRequestData(_data);
+ setRequestData(std::move(_data));
}
-class IsPushRuleEnabledJob::Private
-{
- public:
- bool enabled;
-};
-
-QUrl IsPushRuleEnabledJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+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");
+ QStringLiteral("/_matrix/client/r0")
+ % "/pushrules/" % scope % "/" % kind
+ % "/" % ruleId % "/enabled");
}
-static const auto IsPushRuleEnabledJobName = QStringLiteral("IsPushRuleEnabledJob");
-
-IsPushRuleEnabledJob::IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId)
- : BaseJob(HttpVerb::Get, IsPushRuleEnabledJobName,
- basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled")
- , d(new Private)
+IsPushRuleEnabledJob::IsPushRuleEnabledJob(const QString& scope,
+ const QString& kind,
+ const QString& ruleId)
+ : BaseJob(HttpVerb::Get, QStringLiteral("IsPushRuleEnabledJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId % "/enabled")
{
+ addExpectedKey("enabled");
}
-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"_ls))
- return { JsonParseError,
- "The key 'enabled' not found in the response" };
- fromJson(json.value("enabled"_ls), d->enabled);
- return Success;
-}
-
-static const auto SetPushRuleEnabledJobName = QStringLiteral("SetPushRuleEnabledJob");
-
-SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled)
- : BaseJob(HttpVerb::Put, SetPushRuleEnabledJobName,
- basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled")
+SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope,
+ const QString& kind,
+ const QString& ruleId, bool enabled)
+ : BaseJob(HttpVerb::Put, QStringLiteral("SetPushRuleEnabledJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId % "/enabled")
{
QJsonObject _data;
addParam<>(_data, QStringLiteral("enabled"), enabled);
- setRequestData(_data);
+ setRequestData(std::move(_data));
}
-class GetPushRuleActionsJob::Private
-{
- public:
- QStringList actions;
-};
-
-QUrl GetPushRuleActionsJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId)
+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");
-}
-
-static const auto GetPushRuleActionsJobName = QStringLiteral("GetPushRuleActionsJob");
-
-GetPushRuleActionsJob::GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId)
- : BaseJob(HttpVerb::Get, GetPushRuleActionsJobName,
- basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions")
- , d(new Private)
-{
+ QStringLiteral("/_matrix/client/r0")
+ % "/pushrules/" % scope % "/" % kind
+ % "/" % ruleId % "/actions");
}
-GetPushRuleActionsJob::~GetPushRuleActionsJob() = default;
-
-const QStringList& GetPushRuleActionsJob::actions() const
-{
- return d->actions;
-}
-
-BaseJob::Status GetPushRuleActionsJob::parseJson(const QJsonDocument& data)
+GetPushRuleActionsJob::GetPushRuleActionsJob(const QString& scope,
+ const QString& kind,
+ const QString& ruleId)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetPushRuleActionsJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId % "/actions")
{
- auto json = data.object();
- if (!json.contains("actions"_ls))
- return { JsonParseError,
- "The key 'actions' not found in the response" };
- fromJson(json.value("actions"_ls), d->actions);
- return Success;
+ addExpectedKey("actions");
}
-static const auto SetPushRuleActionsJobName = QStringLiteral("SetPushRuleActionsJob");
-
-SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions)
- : BaseJob(HttpVerb::Put, SetPushRuleActionsJobName,
- basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions")
+SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope,
+ const QString& kind,
+ const QString& ruleId,
+ const QVector<QVariant>& actions)
+ : BaseJob(HttpVerb::Put, QStringLiteral("SetPushRuleActionsJob"),
+ QStringLiteral("/_matrix/client/r0") % "/pushrules/" % scope % "/"
+ % kind % "/" % ruleId % "/actions")
{
QJsonObject _data;
addParam<>(_data, QStringLiteral("actions"), actions);
- setRequestData(_data);
+ setRequestData(std::move(_data));
}
-