From ae5835b959455d3f4eb86b3a1f3d98f3713bdfbe Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 30 Apr 2018 22:17:04 +0900 Subject: jobs/generated: cleanup C++ --- lib/jobs/generated/administrative_contact.cpp | 18 +++++----- lib/jobs/generated/create_room.cpp | 20 +++++------ lib/jobs/generated/list_public_rooms.cpp | 50 +++++++++++++-------------- 3 files changed, 44 insertions(+), 44 deletions(-) (limited to 'lib/jobs') diff --git a/lib/jobs/generated/administrative_contact.cpp b/lib/jobs/generated/administrative_contact.cpp index 1af57941..ede15344 100644 --- a/lib/jobs/generated/administrative_contact.cpp +++ b/lib/jobs/generated/administrative_contact.cpp @@ -22,14 +22,14 @@ namespace QMatrixClient { template <> struct FromJson { - GetAccount3PIDsJob::ThirdPartyIdentifier operator()(QJsonValue jv) + GetAccount3PIDsJob::ThirdPartyIdentifier operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); GetAccount3PIDsJob::ThirdPartyIdentifier result; result.medium = - fromJson(o.value("medium")); + fromJson(o.value("medium")); result.address = - fromJson(o.value("address")); + fromJson(o.value("address")); return result; } @@ -82,16 +82,16 @@ namespace QMatrixClient { template <> struct FromJson { - Post3PIDsJob::ThreePidCredentials operator()(QJsonValue jv) + Post3PIDsJob::ThreePidCredentials operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); Post3PIDsJob::ThreePidCredentials result; result.clientSecret = - fromJson(o.value("client_secret")); + fromJson(o.value("client_secret")); result.idServer = - fromJson(o.value("id_server")); + fromJson(o.value("id_server")); result.sid = - fromJson(o.value("sid")); + fromJson(o.value("sid")); return result; } diff --git a/lib/jobs/generated/create_room.cpp b/lib/jobs/generated/create_room.cpp index de7807b5..6e582791 100644 --- a/lib/jobs/generated/create_room.cpp +++ b/lib/jobs/generated/create_room.cpp @@ -23,16 +23,16 @@ namespace QMatrixClient { template <> struct FromJson { - CreateRoomJob::Invite3pid operator()(QJsonValue jv) + CreateRoomJob::Invite3pid operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); CreateRoomJob::Invite3pid result; result.idServer = - fromJson(o.value("id_server")); + fromJson(o.value("id_server")); result.medium = - fromJson(o.value("medium")); + fromJson(o.value("medium")); result.address = - fromJson(o.value("address")); + fromJson(o.value("address")); return result; } @@ -52,16 +52,16 @@ namespace QMatrixClient { template <> struct FromJson { - CreateRoomJob::StateEvent operator()(QJsonValue jv) + CreateRoomJob::StateEvent operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); CreateRoomJob::StateEvent result; result.type = - fromJson(o.value("type")); + fromJson(o.value("type")); result.stateKey = - fromJson(o.value("state_key")); + fromJson(o.value("state_key")); result.content = - fromJson(o.value("content")); + fromJson(o.value("content")); return result; } diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 39653300..1e3c4ed8 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp @@ -29,28 +29,28 @@ namespace QMatrixClient { template <> struct FromJson { - GetPublicRoomsJob::PublicRoomsChunk operator()(QJsonValue jv) + GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); GetPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson>(o.value("aliases")); + fromJson>(o.value("aliases")); result.canonicalAlias = - fromJson(o.value("canonical_alias")); + fromJson(o.value("canonical_alias")); result.name = - fromJson(o.value("name")); + fromJson(o.value("name")); result.numJoinedMembers = - fromJson(o.value("num_joined_members")); + fromJson(o.value("num_joined_members")); result.roomId = - fromJson(o.value("room_id")); + fromJson(o.value("room_id")); result.topic = - fromJson(o.value("topic")); + fromJson(o.value("topic")); result.worldReadable = - fromJson(o.value("world_readable")); + fromJson(o.value("world_readable")); result.guestCanJoin = - fromJson(o.value("guest_can_join")); + fromJson(o.value("guest_can_join")); result.avatarUrl = - fromJson(o.value("avatar_url")); + fromJson(o.value("avatar_url")); return result; } @@ -139,12 +139,12 @@ namespace QMatrixClient { template <> struct FromJson { - QueryPublicRoomsJob::Filter operator()(QJsonValue jv) + QueryPublicRoomsJob::Filter operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); QueryPublicRoomsJob::Filter result; result.genericSearchTerm = - fromJson(o.value("generic_search_term")); + fromJson(o.value("generic_search_term")); return result; } @@ -170,28 +170,28 @@ namespace QMatrixClient { template <> struct FromJson { - QueryPublicRoomsJob::PublicRoomsChunk operator()(QJsonValue jv) + QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); QueryPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson>(o.value("aliases")); + fromJson>(o.value("aliases")); result.canonicalAlias = - fromJson(o.value("canonical_alias")); + fromJson(o.value("canonical_alias")); result.name = - fromJson(o.value("name")); + fromJson(o.value("name")); result.numJoinedMembers = - fromJson(o.value("num_joined_members")); + fromJson(o.value("num_joined_members")); result.roomId = - fromJson(o.value("room_id")); + fromJson(o.value("room_id")); result.topic = - fromJson(o.value("topic")); + fromJson(o.value("topic")); result.worldReadable = - fromJson(o.value("world_readable")); + fromJson(o.value("world_readable")); result.guestCanJoin = - fromJson(o.value("guest_can_join")); + fromJson(o.value("guest_can_join")); result.avatarUrl = - fromJson(o.value("avatar_url")); + fromJson(o.value("avatar_url")); return result; } -- cgit v1.2.3 From fe4afda065fc9a1db64fd8032bad4e10bff3d020 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 30 Apr 2018 22:33:45 +0900 Subject: jobs/generated: GetNotificationsJob --- lib/jobs/generated/notifications.cpp | 182 +++++++++++++++++++++++++++++++++++ lib/jobs/generated/notifications.h | 77 +++++++++++++++ 2 files changed, 259 insertions(+) create mode 100644 lib/jobs/generated/notifications.cpp create mode 100644 lib/jobs/generated/notifications.h (limited to 'lib/jobs') 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 + +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 operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetNotificationsJob::Unsigned result; + result.age = + fromJson(o.value("age")); + result.prevContent = + fromJson(o.value("prev_content")); + result.transactionId = + fromJson(o.value("transaction_id")); + result.redactedBecause = + fromJson(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 operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetNotificationsJob::Event result; + result.eventId = + fromJson(o.value("event_id")); + result.content = + fromJson(o.value("content")); + result.originServerTimestamp = + fromJson(o.value("origin_server_ts")); + result.sender = + fromJson(o.value("sender")); + result.stateKey = + fromJson(o.value("state_key")); + result.type = + fromJson(o.value("type")); + result.unsignedData = + fromJson(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 operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetNotificationsJob::Notification result; + result.actions = + fromJson>(o.value("actions")); + result.event = + fromJson(o.value("event")); + result.profileTag = + fromJson(o.value("profile_tag")); + result.read = + fromJson(o.value("read")); + result.roomId = + fromJson(o.value("room_id")); + result.ts = + fromJson(o.value("ts")); + + return result; + } + }; +} // namespace QMatrixClient + +class GetNotificationsJob::Private +{ + public: + QString nextToken; + QVector 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::notifications() const +{ + return d->notifications; +} + +BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->nextToken = fromJson(json.value("next_token")); + if (!json.contains("notifications")) + return { JsonParseError, + "The key 'notifications' not found in the response" }; + d->notifications = fromJson>(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 +#include + +#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 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& notifications() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; +} // namespace QMatrixClient -- cgit v1.2.3 From 21c62057bebd676a1950aa405a5f1a2c316c22ac Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 20:04:51 +0900 Subject: jobs/generated: use std::move in baseURL; type updates from the API files The type updates are a matter of pending PR to matrix-doc yet. --- lib/jobs/generated/administrative_contact.cpp | 4 +- lib/jobs/generated/content-repo.cpp | 20 +++--- lib/jobs/generated/content-repo.h | 6 +- lib/jobs/generated/directory.cpp | 4 +- lib/jobs/generated/leaving.cpp | 4 +- lib/jobs/generated/logout.cpp | 2 +- lib/jobs/generated/notifications.cpp | 96 ++------------------------- lib/jobs/generated/notifications.h | 25 ++----- lib/jobs/generated/profile.cpp | 6 +- lib/jobs/generated/versions.cpp | 2 +- lib/jobs/generated/whoami.cpp | 2 +- 11 files changed, 33 insertions(+), 138 deletions(-) (limited to 'lib/jobs') diff --git a/lib/jobs/generated/administrative_contact.cpp b/lib/jobs/generated/administrative_contact.cpp index ede15344..bd74490c 100644 --- a/lib/jobs/generated/administrative_contact.cpp +++ b/lib/jobs/generated/administrative_contact.cpp @@ -44,7 +44,7 @@ class GetAccount3PIDsJob::Private QUrl GetAccount3PIDsJob::makeRequestUrl(QUrl baseUrl) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/account/3pid"); } @@ -110,7 +110,7 @@ Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind) QUrl RequestTokenTo3PIDJob::makeRequestUrl(QUrl baseUrl) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/account/3pid/email/requestToken"); } diff --git a/lib/jobs/generated/content-repo.cpp b/lib/jobs/generated/content-repo.cpp index 51011251..95fc5aed 100644 --- a/lib/jobs/generated/content-repo.cpp +++ b/lib/jobs/generated/content-repo.cpp @@ -65,7 +65,7 @@ class GetContentJob::Private QUrl GetContentJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/download/" % serverName % "/" % mediaId); } @@ -112,7 +112,7 @@ class GetContentOverrideNameJob::Private QUrl GetContentOverrideNameJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, const QString& fileName) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName); } @@ -168,7 +168,7 @@ BaseJob::Query queryToGetContentThumbnail(int width, int height, const QString& QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width, int height, const QString& method) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/thumbnail/" % serverName % "/" % mediaId, queryToGetContentThumbnail(width, height, method)); } @@ -205,11 +205,11 @@ BaseJob::Status GetContentThumbnailJob::parseReply(QNetworkReply* reply) class GetUrlPreviewJob::Private { public: - double matrixImageSize; + qint64 matrixImageSize; QString ogImage; }; -BaseJob::Query queryToGetUrlPreview(const QString& url, double ts) +BaseJob::Query queryToGetUrlPreview(const QString& url, qint64 ts) { BaseJob::Query _q; _q.addQueryItem("url", url); @@ -217,14 +217,14 @@ BaseJob::Query queryToGetUrlPreview(const QString& url, double ts) return _q; } -QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, double ts) +QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, qint64 ts) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/preview_url", queryToGetUrlPreview(url, ts)); } -GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, double ts) +GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, qint64 ts) : BaseJob(HttpVerb::Get, "GetUrlPreviewJob", basePath % "/preview_url", queryToGetUrlPreview(url, ts)) @@ -234,7 +234,7 @@ GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, double ts) GetUrlPreviewJob::~GetUrlPreviewJob() = default; -double GetUrlPreviewJob::matrixImageSize() const +qint64 GetUrlPreviewJob::matrixImageSize() const { return d->matrixImageSize; } @@ -247,7 +247,7 @@ const QString& GetUrlPreviewJob::ogImage() const BaseJob::Status GetUrlPreviewJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->matrixImageSize = fromJson(json.value("matrix:image:size")); + d->matrixImageSize = fromJson(json.value("matrix:image:size")); d->ogImage = fromJson(json.value("og:image")); return Success; } diff --git a/lib/jobs/generated/content-repo.h b/lib/jobs/generated/content-repo.h index b4ea562f..e1e58f88 100644 --- a/lib/jobs/generated/content-repo.h +++ b/lib/jobs/generated/content-repo.h @@ -111,12 +111,12 @@ namespace QMatrixClient * a URL for GetUrlPreviewJob is necessary but the job * itself isn't. */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& url, double ts = {}); + static QUrl makeRequestUrl(QUrl baseUrl, const QString& url, qint64 ts = {}); - explicit GetUrlPreviewJob(const QString& url, double ts = {}); + explicit GetUrlPreviewJob(const QString& url, qint64 ts = {}); ~GetUrlPreviewJob() override; - double matrixImageSize() const; + qint64 matrixImageSize() const; const QString& ogImage() const; protected: diff --git a/lib/jobs/generated/directory.cpp b/lib/jobs/generated/directory.cpp index 9428dcee..6324a1f5 100644 --- a/lib/jobs/generated/directory.cpp +++ b/lib/jobs/generated/directory.cpp @@ -31,7 +31,7 @@ class GetRoomIdByAliasJob::Private QUrl GetRoomIdByAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/room/" % roomAlias); } @@ -64,7 +64,7 @@ BaseJob::Status GetRoomIdByAliasJob::parseJson(const QJsonDocument& data) QUrl DeleteRoomAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/room/" % roomAlias); } diff --git a/lib/jobs/generated/leaving.cpp b/lib/jobs/generated/leaving.cpp index fbc40d11..afc4adbd 100644 --- a/lib/jobs/generated/leaving.cpp +++ b/lib/jobs/generated/leaving.cpp @@ -14,7 +14,7 @@ static const auto basePath = QStringLiteral("/_matrix/client/r0"); QUrl LeaveRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/rooms/" % roomId % "/leave"); } @@ -26,7 +26,7 @@ LeaveRoomJob::LeaveRoomJob(const QString& roomId) QUrl ForgetRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/rooms/" % roomId % "/forget"); } diff --git a/lib/jobs/generated/logout.cpp b/lib/jobs/generated/logout.cpp index 83139842..b943dcd3 100644 --- a/lib/jobs/generated/logout.cpp +++ b/lib/jobs/generated/logout.cpp @@ -14,7 +14,7 @@ static const auto basePath = QStringLiteral("/_matrix/client/r0"); QUrl LogoutJob::makeRequestUrl(QUrl baseUrl) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/logout"); } diff --git a/lib/jobs/generated/notifications.cpp b/lib/jobs/generated/notifications.cpp index e3558097..ffd17b8a 100644 --- a/lib/jobs/generated/notifications.cpp +++ b/lib/jobs/generated/notifications.cpp @@ -12,94 +12,6 @@ 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 operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - GetNotificationsJob::Unsigned result; - result.age = - fromJson(o.value("age")); - result.prevContent = - fromJson(o.value("prev_content")); - result.transactionId = - fromJson(o.value("transaction_id")); - result.redactedBecause = - fromJson(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 operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - GetNotificationsJob::Event result; - result.eventId = - fromJson(o.value("event_id")); - result.content = - fromJson(o.value("content")); - result.originServerTimestamp = - fromJson(o.value("origin_server_ts")); - result.sender = - fromJson(o.value("sender")); - result.stateKey = - fromJson(o.value("state_key")); - result.type = - fromJson(o.value("type")); - result.unsignedData = - fromJson(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 operator()(const QJsonValue& jv) @@ -128,7 +40,7 @@ class GetNotificationsJob::Private { public: QString nextToken; - QVector notifications; + std::vector notifications; }; BaseJob::Query queryToGetNotifications(const QString& from, int limit, const QString& only) @@ -144,7 +56,7 @@ BaseJob::Query queryToGetNotifications(const QString& from, int limit, const QSt QUrl GetNotificationsJob::makeRequestUrl(QUrl baseUrl, const QString& from, int limit, const QString& only) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/notifications", queryToGetNotifications(from, limit, only)); } @@ -164,7 +76,7 @@ const QString& GetNotificationsJob::nextToken() const return d->nextToken; } -const QVector& GetNotificationsJob::notifications() const +const std::vector& GetNotificationsJob::notifications() const { return d->notifications; } @@ -176,7 +88,7 @@ BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data) if (!json.contains("notifications")) return { JsonParseError, "The key 'notifications' not found in the response" }; - d->notifications = fromJson>(json.value("notifications")); + d->notifications = fromJson>(json.value("notifications")); return Success; } diff --git a/lib/jobs/generated/notifications.h b/lib/jobs/generated/notifications.h index 9249a1b7..72318f69 100644 --- a/lib/jobs/generated/notifications.h +++ b/lib/jobs/generated/notifications.h @@ -6,6 +6,8 @@ #include "../basejob.h" +#include +#include "events/event.h" #include #include @@ -20,26 +22,7 @@ namespace QMatrixClient 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; - - }; + using Event = EventPtr; struct Notification { @@ -65,7 +48,7 @@ namespace QMatrixClient ~GetNotificationsJob() override; const QString& nextToken() const; - const QVector& notifications() const; + const std::vector& notifications() const; protected: Status parseJson(const QJsonDocument& data) override; diff --git a/lib/jobs/generated/profile.cpp b/lib/jobs/generated/profile.cpp index 1f7092d7..d8ddbc14 100644 --- a/lib/jobs/generated/profile.cpp +++ b/lib/jobs/generated/profile.cpp @@ -30,7 +30,7 @@ class GetDisplayNameJob::Private QUrl GetDisplayNameJob::makeRequestUrl(QUrl baseUrl, const QString& userId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/profile/" % userId % "/displayname"); } @@ -73,7 +73,7 @@ class GetAvatarUrlJob::Private QUrl GetAvatarUrlJob::makeRequestUrl(QUrl baseUrl, const QString& userId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/profile/" % userId % "/avatar_url"); } @@ -107,7 +107,7 @@ class GetUserProfileJob::Private QUrl GetUserProfileJob::makeRequestUrl(QUrl baseUrl, const QString& userId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/profile/" % userId); } diff --git a/lib/jobs/generated/versions.cpp b/lib/jobs/generated/versions.cpp index b12594ca..3b03172c 100644 --- a/lib/jobs/generated/versions.cpp +++ b/lib/jobs/generated/versions.cpp @@ -20,7 +20,7 @@ class GetVersionsJob::Private QUrl GetVersionsJob::makeRequestUrl(QUrl baseUrl) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/versions"); } diff --git a/lib/jobs/generated/whoami.cpp b/lib/jobs/generated/whoami.cpp index cc38fa4d..4c231b5f 100644 --- a/lib/jobs/generated/whoami.cpp +++ b/lib/jobs/generated/whoami.cpp @@ -20,7 +20,7 @@ class GetTokenOwnerJob::Private QUrl GetTokenOwnerJob::makeRequestUrl(QUrl baseUrl) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/account/whoami"); } -- cgit v1.2.3 From 2a341e30ef2db74b331a8870ceb2f182af68f194 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 20:45:18 +0900 Subject: GetNotificationsJob: don't alias EventPtr with Event It's useless and misleading. --- lib/jobs/generated/notifications.cpp | 2 +- lib/jobs/generated/notifications.h | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/jobs') diff --git a/lib/jobs/generated/notifications.cpp b/lib/jobs/generated/notifications.cpp index ffd17b8a..df6b10ba 100644 --- a/lib/jobs/generated/notifications.cpp +++ b/lib/jobs/generated/notifications.cpp @@ -21,7 +21,7 @@ namespace QMatrixClient result.actions = fromJson>(o.value("actions")); result.event = - fromJson(o.value("event")); + fromJson(o.value("event")); result.profileTag = fromJson(o.value("profile_tag")); result.read = diff --git a/lib/jobs/generated/notifications.h b/lib/jobs/generated/notifications.h index 72318f69..798b9576 100644 --- a/lib/jobs/generated/notifications.h +++ b/lib/jobs/generated/notifications.h @@ -22,12 +22,10 @@ namespace QMatrixClient public: // Inner data structures - using Event = EventPtr; - struct Notification { QVector actions; - Event event; + EventPtr event; QString profileTag; bool read; QString roomId; -- cgit v1.2.3