From a2024608abf4912b9720829ba0b0c20bbb4a5916 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 8 Jun 2018 12:47:59 +0900 Subject: csapi: added sync filter definitions and jobs --- lib/csapi/definitions/event_filter.cpp | 37 ++++++++++++++ lib/csapi/definitions/event_filter.h | 32 ++++++++++++ lib/csapi/definitions/room_event_filter.cpp | 31 ++++++++++++ lib/csapi/definitions/room_event_filter.h | 31 ++++++++++++ lib/csapi/definitions/sync_filter.cpp | 72 ++++++++++++++++++++++++++ lib/csapi/definitions/sync_filter.h | 52 +++++++++++++++++++ lib/csapi/filter.cpp | 78 +++++++++++++++++++++++++++++ lib/csapi/filter.h | 59 ++++++++++++++++++++++ 8 files changed, 392 insertions(+) create mode 100644 lib/csapi/definitions/event_filter.cpp create mode 100644 lib/csapi/definitions/event_filter.h create mode 100644 lib/csapi/definitions/room_event_filter.cpp create mode 100644 lib/csapi/definitions/room_event_filter.h create mode 100644 lib/csapi/definitions/sync_filter.cpp create mode 100644 lib/csapi/definitions/sync_filter.h create mode 100644 lib/csapi/filter.cpp create mode 100644 lib/csapi/filter.h diff --git a/lib/csapi/definitions/event_filter.cpp b/lib/csapi/definitions/event_filter.cpp new file mode 100644 index 00000000..b16b082d --- /dev/null +++ b/lib/csapi/definitions/event_filter.cpp @@ -0,0 +1,37 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "event_filter.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const Filter& pod) +{ + QJsonObject _json; + addToJson(_json, "limit", pod.limit); + addToJson(_json, "not_senders", pod.notSenders); + addToJson(_json, "not_types", pod.notTypes); + addToJson(_json, "senders", pod.senders); + addToJson(_json, "types", pod.types); + return _json; +} + +Filter FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + Filter result; + result.limit = + fromJson(_json.value("limit")); + result.notSenders = + fromJson(_json.value("not_senders")); + result.notTypes = + fromJson(_json.value("not_types")); + result.senders = + fromJson(_json.value("senders")); + result.types = + fromJson(_json.value("types")); + + return result; +} + diff --git a/lib/csapi/definitions/event_filter.h b/lib/csapi/definitions/event_filter.h new file mode 100644 index 00000000..407ef7c5 --- /dev/null +++ b/lib/csapi/definitions/event_filter.h @@ -0,0 +1,32 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + + +#include "converters.h" + +#include "converters.h" + +namespace QMatrixClient +{ + // Data structures + + struct Filter + { + Omittable limit; + QStringList notSenders; + QStringList notTypes; + QStringList senders; + QStringList types; + }; + + QJsonObject toJson(const Filter& pod); + + template <> struct FromJson + { + Filter operator()(const QJsonValue& jv); + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/definitions/room_event_filter.cpp b/lib/csapi/definitions/room_event_filter.cpp new file mode 100644 index 00000000..68e56f4c --- /dev/null +++ b/lib/csapi/definitions/room_event_filter.cpp @@ -0,0 +1,31 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "room_event_filter.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const RoomEventFilter& pod) +{ + QJsonObject _json; + addToJson(_json, "not_rooms", pod.notRooms); + addToJson(_json, "rooms", pod.rooms); + addToJson(_json, "contains_url", pod.containsUrl); + return _json; +} + +RoomEventFilter FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + RoomEventFilter result; + result.notRooms = + fromJson(_json.value("not_rooms")); + result.rooms = + fromJson(_json.value("rooms")); + result.containsUrl = + fromJson(_json.value("contains_url")); + + return result; +} + diff --git a/lib/csapi/definitions/room_event_filter.h b/lib/csapi/definitions/room_event_filter.h new file mode 100644 index 00000000..b503ec3a --- /dev/null +++ b/lib/csapi/definitions/room_event_filter.h @@ -0,0 +1,31 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + + +#include "csapi/definitions/event_filter.h" +#include "converters.h" + +#include "converters.h" + +namespace QMatrixClient +{ + // Data structures + + struct RoomEventFilter : Filter + { + QStringList notRooms; + QStringList rooms; + bool containsUrl; + }; + + QJsonObject toJson(const RoomEventFilter& pod); + + template <> struct FromJson + { + RoomEventFilter operator()(const QJsonValue& jv); + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/definitions/sync_filter.cpp b/lib/csapi/definitions/sync_filter.cpp new file mode 100644 index 00000000..7ca389b4 --- /dev/null +++ b/lib/csapi/definitions/sync_filter.cpp @@ -0,0 +1,72 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "sync_filter.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const RoomFilter& pod) +{ + QJsonObject _json; + addToJson(_json, "not_rooms", pod.notRooms); + addToJson(_json, "rooms", pod.rooms); + addToJson(_json, "ephemeral", pod.ephemeral); + addToJson(_json, "include_leave", pod.includeLeave); + addToJson(_json, "state", pod.state); + addToJson(_json, "timeline", pod.timeline); + addToJson(_json, "account_data", pod.accountData); + return _json; +} + +RoomFilter FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + RoomFilter result; + result.notRooms = + fromJson(_json.value("not_rooms")); + result.rooms = + fromJson(_json.value("rooms")); + result.ephemeral = + fromJson(_json.value("ephemeral")); + result.includeLeave = + fromJson(_json.value("include_leave")); + result.state = + fromJson(_json.value("state")); + result.timeline = + fromJson(_json.value("timeline")); + result.accountData = + fromJson(_json.value("account_data")); + + return result; +} + +QJsonObject QMatrixClient::toJson(const SyncFilter& pod) +{ + QJsonObject _json; + addToJson(_json, "event_fields", pod.eventFields); + addToJson(_json, "event_format", pod.eventFormat); + addToJson(_json, "presence", pod.presence); + addToJson(_json, "account_data", pod.accountData); + addToJson(_json, "room", pod.room); + return _json; +} + +SyncFilter FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + SyncFilter result; + result.eventFields = + fromJson(_json.value("event_fields")); + result.eventFormat = + fromJson(_json.value("event_format")); + result.presence = + fromJson(_json.value("presence")); + result.accountData = + fromJson(_json.value("account_data")); + result.room = + fromJson(_json.value("room")); + + return result; +} + diff --git a/lib/csapi/definitions/sync_filter.h b/lib/csapi/definitions/sync_filter.h new file mode 100644 index 00000000..f7428c0d --- /dev/null +++ b/lib/csapi/definitions/sync_filter.h @@ -0,0 +1,52 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + + +#include "csapi/definitions/room_event_filter.h" +#include "converters.h" +#include "csapi/definitions/event_filter.h" + +#include "converters.h" + +namespace QMatrixClient +{ + // Data structures + + struct RoomFilter + { + QStringList notRooms; + QStringList rooms; + Omittable ephemeral; + bool includeLeave; + Omittable state; + Omittable timeline; + Omittable accountData; + }; + + QJsonObject toJson(const RoomFilter& pod); + + template <> struct FromJson + { + RoomFilter operator()(const QJsonValue& jv); + }; + + struct SyncFilter + { + QStringList eventFields; + QString eventFormat; + Omittable presence; + Omittable accountData; + Omittable room; + }; + + QJsonObject toJson(const SyncFilter& pod); + + template <> struct FromJson + { + SyncFilter operator()(const QJsonValue& jv); + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/filter.cpp b/lib/csapi/filter.cpp new file mode 100644 index 00000000..a1546923 --- /dev/null +++ b/lib/csapi/filter.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "filter.h" + +#include "converters.h" + +#include + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class DefineFilterJob::Private +{ + public: + QString filterId; +}; + +DefineFilterJob::DefineFilterJob(const QString& userId, const SyncFilter& filter) + : BaseJob(HttpVerb::Post, "DefineFilterJob", + basePath % "/user/" % userId % "/filter") + , d(new Private) +{ + setRequestData(Data(toJson(filter))); +} + +DefineFilterJob::~DefineFilterJob() = default; + +const QString& DefineFilterJob::filterId() const +{ + return d->filterId; +} + +BaseJob::Status DefineFilterJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->filterId = fromJson(json.value("filter_id")); + return Success; +} + +class GetFilterJob::Private +{ + public: + SyncFilter data; +}; + +QUrl GetFilterJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& filterId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/user/" % userId % "/filter/" % filterId); +} + +GetFilterJob::GetFilterJob(const QString& userId, const QString& filterId) + : BaseJob(HttpVerb::Get, "GetFilterJob", + basePath % "/user/" % userId % "/filter/" % filterId) + , d(new Private) +{ +} + +GetFilterJob::~GetFilterJob() = default; + +const SyncFilter& GetFilterJob::data() const +{ + return d->data; +} + +BaseJob::Status GetFilterJob::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(json.value("data")); + return Success; +} + diff --git a/lib/csapi/filter.h b/lib/csapi/filter.h new file mode 100644 index 00000000..92e9c737 --- /dev/null +++ b/lib/csapi/filter.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include "converters.h" +#include "csapi/definitions/sync_filter.h" + +namespace QMatrixClient +{ + // Operations + + class DefineFilterJob : public BaseJob + { + public: + explicit DefineFilterJob(const QString& userId, const SyncFilter& filter); + ~DefineFilterJob() override; + + // Result properties + + const QString& filterId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; + + class GetFilterJob : public BaseJob + { + public: + explicit GetFilterJob(const QString& userId, const QString& filterId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetFilterJob. This function can be used when + * a URL for GetFilterJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& filterId); + + ~GetFilterJob() override; + + // Result properties + + const SyncFilter& data() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; +} // namespace QMatrixClient -- cgit v1.2.3