diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-04 23:04:04 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-04 23:04:04 +0900 |
commit | 49022915fde72b83d9f18944c268110b01fa3469 (patch) | |
tree | 1b465b553a2e341486cd6051530a63faba17288e /lib/csapi/notifications.cpp | |
parent | f70ec41accd6da9f223bc41b446ad1d2d77de3f4 (diff) | |
download | libquotient-49022915fde72b83d9f18944c268110b01fa3469.tar.gz libquotient-49022915fde72b83d9f18944c268110b01fa3469.zip |
New home for the generated code - lib/csapi
Diffstat (limited to 'lib/csapi/notifications.cpp')
-rw-r--r-- | lib/csapi/notifications.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/csapi/notifications.cpp b/lib/csapi/notifications.cpp new file mode 100644 index 00000000..04ad0175 --- /dev/null +++ b/lib/csapi/notifications.cpp @@ -0,0 +1,96 @@ +/****************************************************************************** + * 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 +{ + // Converters + + 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<EventPtr>(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; + std::vector<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(std::move(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; +} + +std::vector<GetNotificationsJob::Notification>&& GetNotificationsJob::notifications() +{ + return std::move(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<std::vector<Notification>>(json.value("notifications")); + return Success; +} + |