diff options
Diffstat (limited to 'lib/csapi/filter.cpp')
-rw-r--r-- | lib/csapi/filter.cpp | 55 |
1 files changed, 8 insertions, 47 deletions
diff --git a/lib/csapi/filter.cpp b/lib/csapi/filter.cpp index 98b85f83..bb3a893f 100644 --- a/lib/csapi/filter.cpp +++ b/lib/csapi/filter.cpp @@ -4,68 +4,29 @@ #include "filter.h" -#include "converters.h" - #include <QtCore/QStringBuilder> using namespace Quotient; -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -class DefineFilterJob::Private { -public: - QString filterId; -}; - DefineFilterJob::DefineFilterJob(const QString& userId, const Filter& filter) : BaseJob(HttpVerb::Post, QStringLiteral("DefineFilterJob"), - basePath % "/user/" % userId % "/filter") - , d(new Private) + QStringLiteral("/_matrix/client/r0") % "/user/" % userId + % "/filter") { setRequestData(Data(toJson(filter))); + addExpectedKey("filter_id"); } -DefineFilterJob::~DefineFilterJob() = default; - -const QString& DefineFilterJob::filterId() const { return d->filterId; } - -BaseJob::Status DefineFilterJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - if (!json.contains("filter_id"_ls)) - return { IncorrectResponse, - "The key 'filter_id' not found in the response" }; - fromJson(json.value("filter_id"_ls), d->filterId); - - return Success; -} - -class GetFilterJob::Private { -public: - Filter data; -}; - QUrl GetFilterJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& filterId) { - return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/user/" - % userId % "/filter/" - % filterId); + return BaseJob::makeRequestUrl(std::move(baseUrl), + QStringLiteral("/_matrix/client/r0") % "/user/" + % userId % "/filter/" % filterId); } GetFilterJob::GetFilterJob(const QString& userId, const QString& filterId) : BaseJob(HttpVerb::Get, QStringLiteral("GetFilterJob"), - basePath % "/user/" % userId % "/filter/" % filterId) - , d(new Private) + QStringLiteral("/_matrix/client/r0") % "/user/" % userId + % "/filter/" % filterId) {} - -GetFilterJob::~GetFilterJob() = default; - -const Filter& GetFilterJob::data() const { return d->data; } - -BaseJob::Status GetFilterJob::parseJson(const QJsonDocument& data) -{ - fromJson(data, d->data); - - return Success; -} |