diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-30 22:33:45 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-30 22:33:45 +0900 |
commit | fe4afda065fc9a1db64fd8032bad4e10bff3d020 (patch) | |
tree | 2a2b784f1a1ada80e83c7969f753ab463e992a57 /lib/jobs/generated | |
parent | ae5835b959455d3f4eb86b3a1f3d98f3713bdfbe (diff) | |
download | libquotient-fe4afda065fc9a1db64fd8032bad4e10bff3d020.tar.gz libquotient-fe4afda065fc9a1db64fd8032bad4e10bff3d020.zip |
jobs/generated: GetNotificationsJob
Diffstat (limited to 'lib/jobs/generated')
-rw-r--r-- | lib/jobs/generated/notifications.cpp | 182 | ||||
-rw-r--r-- | lib/jobs/generated/notifications.h | 77 |
2 files changed, 259 insertions, 0 deletions
diff --git a/lib/jobs/generated/notifications.cpp b/lib/jobs/generated/notifications.cpp new file mode 100644 index 00000000..e3558097 --- /dev/null +++ b/lib/jobs/generated/notifications.cpp @@ -0,0 +1,182 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "notifications.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + QJsonObject toJson(const GetNotificationsJob::Unsigned& pod) + { + QJsonObject o; + o.insert("age", toJson(pod.age)); + o.insert("prev_content", toJson(pod.prevContent)); + o.insert("transaction_id", toJson(pod.transactionId)); + o.insert("redacted_because", toJson(pod.redactedBecause)); + + return o; + } + + template <> struct FromJson<GetNotificationsJob::Unsigned> + { + GetNotificationsJob::Unsigned operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetNotificationsJob::Unsigned result; + result.age = + fromJson<qint64>(o.value("age")); + result.prevContent = + fromJson<QJsonObject>(o.value("prev_content")); + result.transactionId = + fromJson<QString>(o.value("transaction_id")); + result.redactedBecause = + fromJson<QJsonObject>(o.value("redacted_because")); + + return result; + } + }; +} // namespace QMatrixClient + +namespace QMatrixClient +{ + QJsonObject toJson(const GetNotificationsJob::Event& pod) + { + QJsonObject o; + o.insert("event_id", toJson(pod.eventId)); + o.insert("content", toJson(pod.content)); + o.insert("origin_server_ts", toJson(pod.originServerTimestamp)); + o.insert("sender", toJson(pod.sender)); + o.insert("state_key", toJson(pod.stateKey)); + o.insert("type", toJson(pod.type)); + o.insert("unsigned", toJson(pod.unsignedData)); + + return o; + } + + template <> struct FromJson<GetNotificationsJob::Event> + { + GetNotificationsJob::Event operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetNotificationsJob::Event result; + result.eventId = + fromJson<QString>(o.value("event_id")); + result.content = + fromJson<QJsonObject>(o.value("content")); + result.originServerTimestamp = + fromJson<qint64>(o.value("origin_server_ts")); + result.sender = + fromJson<QString>(o.value("sender")); + result.stateKey = + fromJson<QString>(o.value("state_key")); + result.type = + fromJson<QString>(o.value("type")); + result.unsignedData = + fromJson<GetNotificationsJob::Unsigned>(o.value("unsigned")); + + return result; + } + }; +} // namespace QMatrixClient + +namespace QMatrixClient +{ + QJsonObject toJson(const GetNotificationsJob::Notification& pod) + { + QJsonObject o; + o.insert("actions", toJson(pod.actions)); + o.insert("event", toJson(pod.event)); + o.insert("profile_tag", toJson(pod.profileTag)); + o.insert("read", toJson(pod.read)); + o.insert("room_id", toJson(pod.roomId)); + o.insert("ts", toJson(pod.ts)); + + return o; + } + + template <> struct FromJson<GetNotificationsJob::Notification> + { + GetNotificationsJob::Notification operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetNotificationsJob::Notification result; + result.actions = + fromJson<QVector<QJsonObject>>(o.value("actions")); + result.event = + fromJson<GetNotificationsJob::Event>(o.value("event")); + result.profileTag = + fromJson<QString>(o.value("profile_tag")); + result.read = + fromJson<bool>(o.value("read")); + result.roomId = + fromJson<QString>(o.value("room_id")); + result.ts = + fromJson<qint64>(o.value("ts")); + + return result; + } + }; +} // namespace QMatrixClient + +class GetNotificationsJob::Private +{ + public: + QString nextToken; + QVector<Notification> notifications; +}; + +BaseJob::Query queryToGetNotifications(const QString& from, int limit, const QString& only) +{ + BaseJob::Query _q; + if (!from.isEmpty()) + _q.addQueryItem("from", from); + _q.addQueryItem("limit", QString("%1").arg(limit)); + if (!only.isEmpty()) + _q.addQueryItem("only", only); + return _q; +} + +QUrl GetNotificationsJob::makeRequestUrl(QUrl baseUrl, const QString& from, int limit, const QString& only) +{ + return BaseJob::makeRequestUrl(baseUrl, + basePath % "/notifications", + queryToGetNotifications(from, limit, only)); +} + +GetNotificationsJob::GetNotificationsJob(const QString& from, int limit, const QString& only) + : BaseJob(HttpVerb::Get, "GetNotificationsJob", + basePath % "/notifications", + queryToGetNotifications(from, limit, only)) + , d(new Private) +{ +} + +GetNotificationsJob::~GetNotificationsJob() = default; + +const QString& GetNotificationsJob::nextToken() const +{ + return d->nextToken; +} + +const QVector<GetNotificationsJob::Notification>& GetNotificationsJob::notifications() const +{ + return d->notifications; +} + +BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->nextToken = fromJson<QString>(json.value("next_token")); + if (!json.contains("notifications")) + return { JsonParseError, + "The key 'notifications' not found in the response" }; + d->notifications = fromJson<QVector<Notification>>(json.value("notifications")); + return Success; +} + diff --git a/lib/jobs/generated/notifications.h b/lib/jobs/generated/notifications.h new file mode 100644 index 00000000..9249a1b7 --- /dev/null +++ b/lib/jobs/generated/notifications.h @@ -0,0 +1,77 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "../basejob.h" + +#include <QtCore/QJsonObject> +#include <QtCore/QVector> + +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class GetNotificationsJob : public BaseJob + { + public: + // Inner data structures + + struct Unsigned + { + qint64 age; + QJsonObject prevContent; + QString transactionId; + QJsonObject redactedBecause; + + }; + + struct Event + { + QString eventId; + QJsonObject content; + qint64 originServerTimestamp; + QString sender; + QString stateKey; + QString type; + Unsigned unsignedData; + + }; + + struct Notification + { + QVector<QJsonObject> actions; + Event event; + QString profileTag; + bool read; + QString roomId; + qint64 ts; + + }; + + // End of inner data structures + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetNotificationsJob. This function can be used when + * a URL for GetNotificationsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& from = {}, int limit = {}, const QString& only = {}); + + explicit GetNotificationsJob(const QString& from = {}, int limit = {}, const QString& only = {}); + ~GetNotificationsJob() override; + + const QString& nextToken() const; + const QVector<Notification>& notifications() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient |