From ecf7b64d3ca30ff607ca399f24800a50594b7ebf Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 30 Apr 2018 22:14:41 +0900 Subject: ConnectionsGuard: suppress the copying assignment operator It accidentally leaked through using QPointer::operator= --- lib/util.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/util.h b/lib/util.h index 7ab1e20d..2a323cf3 100644 --- a/lib/util.h +++ b/lib/util.h @@ -78,6 +78,7 @@ namespace QMatrixClient } ConnectionsGuard(ConnectionsGuard&&) noexcept = default; ConnectionsGuard& operator=(ConnectionsGuard&&) noexcept = default; + ConnectionsGuard& operator=(const ConnectionsGuard&) = delete; using QPointer::operator=; private: -- cgit v1.2.3 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') 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') 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 6a73f99fc71df74b1c60e6e202cd4d6787d0cb07 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 30 Apr 2018 22:45:56 +0900 Subject: ConnectionsGuard: one more fix about defaults --- lib/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/util.h b/lib/util.h index 2a323cf3..55f3af6a 100644 --- a/lib/util.h +++ b/lib/util.h @@ -76,8 +76,8 @@ namespace QMatrixClient if (*this) (*this)->disconnect(subscriber); } - ConnectionsGuard(ConnectionsGuard&&) noexcept = default; - ConnectionsGuard& operator=(ConnectionsGuard&&) noexcept = default; + ConnectionsGuard(ConnectionsGuard&&) = default; + ConnectionsGuard& operator=(ConnectionsGuard&&) = default; ConnectionsGuard& operator=(const ConnectionsGuard&) = delete; using QPointer::operator=; -- cgit v1.2.3 From 203a6b61480f726fae341d119f09f9dc83b8829a Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 13:52:23 +0900 Subject: Integrate converters with EventPtr partially So that events can be created from JSON in the same way as all other types. --- lib/events/event.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/events/event.h b/lib/events/event.h index d614115a..68e598ad 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -18,15 +18,9 @@ #pragma once -#include -#include -#include -#include - +#include "converters.h" #include "util.h" -#include - namespace QMatrixClient { template @@ -110,6 +104,14 @@ namespace QMatrixClient EventPtr doMakeEvent(const QJsonObject& obj); } + template <> struct FromJson + { + EventPtr operator()(const QJsonValue& jv) const + { + return makeEvent(jv.toObject()); + } + }; + /** * \brief A vector of pointers to events with deserialisation capabilities * -- cgit v1.2.3 From fb979167127ffaaacec7361ecb45791bf542305f Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 13:53:19 +0900 Subject: Event: cleanup --- lib/events/event.cpp | 4 ---- lib/events/event.h | 5 +---- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/events/event.cpp b/lib/events/event.cpp index 8ddf3945..31520fc9 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -98,10 +98,6 @@ RoomEvent::RoomEvent(Event::Type type) : Event(type) { } RoomEvent::RoomEvent(Type type, const QJsonObject& rep) : Event(type, rep) , _id(rep["event_id"].toString()) -// , _roomId(rep["room_id"].toString()) -// , _senderId(rep["sender"].toString()) -// , _serverTimestamp( -// QMatrixClient::fromJson(rep["origin_server_ts"])) { // if (_id.isEmpty()) // { diff --git a/lib/events/event.h b/lib/events/event.h index 68e598ad..4e2b1071 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -167,7 +167,7 @@ namespace QMatrixClient // constructors and destructors explicit RoomEvent(Type type); RoomEvent(Type type, const QJsonObject& rep); - ~RoomEvent(); + ~RoomEvent() override; QString id() const { return _id; } QDateTime timestamp() const; @@ -204,9 +204,6 @@ namespace QMatrixClient private: QString _id; -// QString _roomId; -// QString _senderId; -// QDateTime _serverTimestamp; event_ptr_tt _redactedBecause; QString _txnId; }; -- cgit v1.2.3 From 0cc26526b243fd10d84ccda87852defd29631b39 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 14:39:03 +0900 Subject: RedactionEvent: make the constructor explicit --- lib/events/redactionevent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/events/redactionevent.h b/lib/events/redactionevent.h index fa6902ab..829b9085 100644 --- a/lib/events/redactionevent.h +++ b/lib/events/redactionevent.h @@ -27,7 +27,7 @@ namespace QMatrixClient public: static constexpr const char* const TypeId = "m.room.redaction"; - RedactionEvent(const QJsonObject& obj) + explicit RedactionEvent(const QJsonObject& obj) : RoomEvent(Type::Redaction, obj) , _redactedEvent(obj.value("redacts").toString()) , _reason(contentJson().value("reason").toString()) -- cgit v1.2.3 From 13f891185de9a678d37fe377c1426805c2e974ac Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 16:36:53 +0900 Subject: User::processEvent: add const --- lib/user.cpp | 2 +- lib/user.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/user.cpp b/lib/user.cpp index c4fbfe35..91b340d5 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -358,7 +358,7 @@ QUrl User::avatarUrl(const Room* room) const return avatarObject(room).url(); } -void User::processEvent(RoomMemberEvent* event, const Room* room) +void User::processEvent(const RoomMemberEvent* event, const Room* room) { if (event->membership() != MembershipType::Invite && event->membership() != MembershipType::Join) diff --git a/lib/user.h b/lib/user.h index f94fbee4..8ac96539 100644 --- a/lib/user.h +++ b/lib/user.h @@ -103,7 +103,8 @@ namespace QMatrixClient QString avatarMediaId(const Room* room = nullptr) const; QUrl avatarUrl(const Room* room = nullptr) const; - void processEvent(RoomMemberEvent* event, const Room* r = nullptr); + void processEvent(const RoomMemberEvent* event, + const Room* r = nullptr); public slots: void rename(const QString& newName); -- cgit v1.2.3 From 68957eace7f840fffe7442f1d50d3793422bc152 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 16:38:05 +0900 Subject: converters.h: Support std::vector<> --- lib/converters.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') diff --git a/lib/converters.h b/lib/converters.h index 22b22f25..cfe9c01c 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -33,6 +33,15 @@ namespace QMatrixClient inline QJsonValue toJson(const QString& s) { return s; } #endif + template + inline QJsonArray toJson(const std::vector& vals) + { + QJsonArray ar; + for (const auto& v: vals) + ar.push_back(toJson(v)); + return ar; + } + template inline QJsonArray toJson(const QVector& vals) { @@ -142,6 +151,18 @@ namespace QMatrixClient } }; + template struct FromJson> + { + std::vector operator()(const QJsonValue& jv) const + { + const auto jsonArray = jv.toArray(); + std::vector vect; vect.resize(size_t(jsonArray.size())); + std::transform(jsonArray.begin(), jsonArray.end(), + vect.begin(), FromJson()); + return vect; + } + }; + template struct FromJson> { QVector operator()(const QJsonValue& jv) const -- cgit v1.2.3 From 5c61bb08e3fe87591884e0440a85d64482500199 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 16:46:53 +0900 Subject: Room: endorse std::move That is, add "using std::move" and strip std:: from actual usages. --- lib/room.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/room.cpp b/lib/room.cpp index 1fa9212e..670c7d7c 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -55,6 +55,7 @@ using namespace QMatrixClient; using namespace std::placeholders; +using std::move; #if !(defined __GLIBCXX__ && __GLIBCXX__ <= 20150123) using std::llround; #endif @@ -74,7 +75,7 @@ class Room::Private typedef QMultiHash members_map_t; Private(Connection* c, QString id_, JoinState initialJoinState) - : q(nullptr), connection(c), id(std::move(id_)) + : q(nullptr), connection(c), id(move(id_)) , joinState(initialJoinState) { } @@ -228,7 +229,7 @@ class Room::Private RoomEventPtr TimelineItem::replaceEvent(RoomEventPtr&& other) { - return std::exchange(evt, std::move(other)); + return std::exchange(evt, move(other)); } Room::Room(Connection* connection, QString id, JoinState initialJoinState) @@ -1389,7 +1390,7 @@ void Room::Private::addNewMessageEvents(RoomEvents&& events) if (!normalEvents.empty()) emit q->aboutToAddNewMessages(normalEvents); - const auto insertedSize = insertEvents(std::move(normalEvents), Newer); + const auto insertedSize = insertEvents(move(normalEvents), Newer); const auto from = timeline.cend() - insertedSize; if (insertedSize > 0) { @@ -1436,7 +1437,7 @@ void Room::Private::addHistoricalMessageEvents(RoomEvents&& events) return; emit q->aboutToAddHistoricalMessages(normalEvents); - const auto insertedSize = insertEvents(std::move(normalEvents), Older); + const auto insertedSize = insertEvents(move(normalEvents), Older); const auto from = timeline.crend() - insertedSize; qCDebug(MAIN) << "Room" << displayname << "received" << insertedSize -- cgit v1.2.3 From b657cd22aa64f24f2e0f9f31ef8a5d4e38a26a3a Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 17:06:20 +0900 Subject: Event and Room: further abstract event pointers So that eventual switch from std::unique_ptr to some other pointer (as a case - QSharedPointer) would be as painless as possible. --- lib/connection.cpp | 5 ++--- lib/events/event.cpp | 16 ++++++++-------- lib/events/event.h | 30 +++++++++++++++++++++++++++--- lib/room.cpp | 47 ++++++++++++++++++++++------------------------- lib/room.h | 16 +++++++++------- 5 files changed, 68 insertions(+), 46 deletions(-) (limited to 'lib') diff --git a/lib/connection.cpp b/lib/connection.cpp index 5f930d57..adeb7929 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -306,9 +306,8 @@ void Connection::onSyncSuccess(SyncData &&data) { { if (accountEvent->type() == EventType::DirectChat) { - const auto usersToDCs = - unique_ptr_cast(accountEvent) - ->usersToDirectChats(); + const auto usersToDCs = ptrCast(move(accountEvent)) + ->usersToDirectChats(); DirectChatsMap removals = erase_if(d->directChats, [&usersToDCs] (auto it) { return !usersToDCs.contains(it.key()->id(), it.value()); diff --git a/lib/events/event.cpp b/lib/events/event.cpp index 31520fc9..193250de 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -67,16 +67,17 @@ const QJsonObject Event::contentJson() const } template -inline BaseEventT* makeIfMatches(const QJsonObject&, const QString&) +inline event_ptr_tt makeIfMatches(const QJsonObject&, const QString&) { return nullptr; } template -inline BaseEventT* makeIfMatches(const QJsonObject& o, const QString& selector) +inline event_ptr_tt makeIfMatches(const QJsonObject& o, + const QString& selector) { if (selector == EventT::TypeId) - return new EventT(o); + return _impl::create(o); return makeIfMatches(o, selector); } @@ -86,11 +87,11 @@ EventPtr _impl::doMakeEvent(const QJsonObject& obj) { // Check more specific event types first if (auto e = doMakeEvent(obj)) - return EventPtr(move(e)); + return e; - return EventPtr { makeIfMatches( - obj, obj["type"].toString()) }; + obj, obj["type"].toString()); } RoomEvent::RoomEvent(Event::Type type) : Event(type) { } @@ -118,8 +119,7 @@ RoomEvent::RoomEvent(Type type, const QJsonObject& rep) auto redaction = unsignedData.value("redacted_because"); if (redaction.isObject()) { - _redactedBecause = - std::make_unique(redaction.toObject()); + _redactedBecause = _impl::create(redaction.toObject()); return; } diff --git a/lib/events/event.h b/lib/events/event.h index 4e2b1071..396406f1 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -26,8 +26,32 @@ namespace QMatrixClient template using event_ptr_tt = std::unique_ptr; + template + inline EventT* rawPtr(const event_ptr_tt& ptr) + { + return ptr.get(); + } + + template + inline TargetEventT* weakPtr(const event_ptr_tt& ptr) + { + return static_cast(rawPtr(ptr)); + } + + template + inline event_ptr_tt ptrCast(event_ptr_tt&& ptr) + { + return unique_ptr_cast(ptr); + } + namespace _impl { + template + inline event_ptr_tt create(ArgTs&&... args) + { + return std::make_unique(std::forward(args)...); + } + template event_ptr_tt doMakeEvent(const QJsonObject& obj); } @@ -94,7 +118,7 @@ namespace QMatrixClient { auto e = _impl::doMakeEvent(obj); if (!e) - e = std::make_unique(EventType::Unknown, obj); + e = _impl::create(EventType::Unknown, obj); return e; } @@ -174,9 +198,9 @@ namespace QMatrixClient QString roomId() const; QString senderId() const; bool isRedacted() const { return bool(_redactedBecause); } - const RedactionEvent* redactedBecause() const + const event_ptr_tt& redactedBecause() const { - return _redactedBecause.get(); + return _redactedBecause; } QString redactionReason() const; const QString& transactionId() const { return _txnId; } diff --git a/lib/room.cpp b/lib/room.cpp index 670c7d7c..a4cfadb4 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -205,7 +205,7 @@ class Room::Private * Tries to find an event in the timeline and redact it; deletes the * redaction event whether the redacted event was found or not. */ - void processRedaction(RoomEventPtr redactionEvent); + void processRedaction(RoomEventPtr&& redactionEvent); void broadcastTagUpdates() { @@ -712,7 +712,7 @@ Room::Private::getEventWithFile(const QString& eventId) const if (evtIt != timeline.rend() && evtIt->event()->type() == EventType::RoomMessage) { - auto* event = static_cast(evtIt->event()); + auto* event = evtIt->viewAs(); if (event->hasFileContent()) return event; } @@ -1287,11 +1287,10 @@ inline bool isRedaction(const RoomEventPtr& e) return e->type() == EventType::Redaction; } -void Room::Private::processRedaction(RoomEventPtr redactionEvent) +void Room::Private::processRedaction(RoomEventPtr&& redactionEvent) { Q_ASSERT(redactionEvent && isRedaction(redactionEvent)); - const auto& redaction = - static_cast(redactionEvent.get()); + const auto& redaction = ptrCast(move(redactionEvent)); const auto pIdx = eventsIndex.find(redaction->redactedEvent()); if (pIdx == eventsIndex.end()) @@ -1360,9 +1359,9 @@ void Room::Private::processRedaction(RoomEventPtr redactionEvent) // notify everyone and delete the old event RoomEventPtr oldEvent { ti.replaceEvent(makeEvent(originalJson)) }; - q->onRedaction(oldEvent.get(), ti.event()); + q->onRedaction(*oldEvent, *ti.event()); qCDebug(MAIN) << "Redacted" << oldEvent->id() << "with" << redaction->id(); - emit q->replacedEvent(ti.event(), oldEvent.get()); + emit q->replacedEvent(ti.event(), rawPtr(oldEvent)); } Connection* Room::connection() const @@ -1456,25 +1455,24 @@ void Room::processStateEvents(const RoomEvents& events) bool emitNamesChanged = false; for (const auto& e: events) { - auto* event = e.get(); - switch (event->type()) + switch (e->type()) { case EventType::RoomName: { - auto nameEvent = static_cast(event); + auto* nameEvent = weakPtr(e); d->name = nameEvent->name(); qCDebug(MAIN) << "Room name updated:" << d->name; emitNamesChanged = true; break; } case EventType::RoomAliases: { - auto aliasesEvent = static_cast(event); + auto* aliasesEvent = weakPtr(e); d->aliases = aliasesEvent->aliases(); qCDebug(MAIN) << "Room aliases updated:" << d->aliases; emitNamesChanged = true; break; } case EventType::RoomCanonicalAlias: { - auto aliasEvent = static_cast(event); + auto* aliasEvent = weakPtr(e); d->canonicalAlias = aliasEvent->alias(); setObjectName(d->canonicalAlias); qCDebug(MAIN) << "Room canonical alias updated:" << d->canonicalAlias; @@ -1482,7 +1480,7 @@ void Room::processStateEvents(const RoomEvents& events) break; } case EventType::RoomTopic: { - auto topicEvent = static_cast(event); + auto* topicEvent = weakPtr(e); d->topic = topicEvent->topic(); qCDebug(MAIN) << "Room topic updated:" << d->topic; emit topicChanged(); @@ -1490,7 +1488,7 @@ void Room::processStateEvents(const RoomEvents& events) } case EventType::RoomAvatar: { const auto& avatarEventContent = - static_cast(event)->content(); + weakPtr(e)->content(); if (d->avatar.updateUrl(avatarEventContent.url)) { qCDebug(MAIN) << "Room avatar URL updated:" @@ -1500,7 +1498,7 @@ void Room::processStateEvents(const RoomEvents& events) break; } case EventType::RoomMember: { - auto memberEvent = static_cast(event); + auto* memberEvent = weakPtr(e); auto u = user(memberEvent->userId()); u->processEvent(memberEvent, this); if (u == localUser() && memberJoinState(u) == JoinState::Invite @@ -1541,7 +1539,7 @@ void Room::processStateEvents(const RoomEvents& events) case EventType::RoomEncryption: { d->encryptionAlgorithm = - static_cast(event)->algorithm(); + weakPtr(e)->algorithm(); qCDebug(MAIN) << "Encryption switched on in" << displayName(); emit encryption(); break; @@ -1555,13 +1553,13 @@ void Room::processStateEvents(const RoomEvents& events) d->updateDisplayname(); } -void Room::processEphemeralEvent(EventPtr event) +void Room::processEphemeralEvent(EventPtr&& event) { QElapsedTimer et; et.start(); switch (event->type()) { case EventType::Typing: { - auto typingEvent = static_cast(event.get()); + auto typingEvent = ptrCast(move(event)); d->usersTyping.clear(); for( const QString& userId: typingEvent->users() ) { @@ -1576,7 +1574,7 @@ void Room::processEphemeralEvent(EventPtr event) break; } case EventType::Receipt: { - auto receiptEvent = static_cast(event.get()); + auto receiptEvent = ptrCast(move(event)); for( const auto &p: receiptEvent->eventsWithReceipts() ) { { @@ -1630,13 +1628,13 @@ void Room::processEphemeralEvent(EventPtr event) } } -void Room::processAccountDataEvent(EventPtr event) +void Room::processAccountDataEvent(EventPtr&& event) { switch (event->type()) { case EventType::Tag: { - auto newTags = static_cast(event.get())->tags(); + auto newTags = ptrCast(move(event))->tags(); if (newTags == d->tags) break; d->tags = newTags; @@ -1647,16 +1645,15 @@ void Room::processAccountDataEvent(EventPtr event) } case EventType::ReadMarker: { - const auto* rmEvent = static_cast(event.get()); - const auto& readEventId = rmEvent->event_id(); + auto readEventId = + ptrCast(move(event))->event_id(); qCDebug(MAIN) << "Server-side read marker at" << readEventId; d->serverReadMarker = readEventId; const auto newMarker = findInTimeline(readEventId); if (newMarker != timelineEdge()) d->markMessagesAsRead(newMarker); - else { + else d->setLastReadEvent(localUser(), readEventId); - } break; } default: diff --git a/lib/room.h b/lib/room.h index 86a7b245..288db5fb 100644 --- a/lib/room.h +++ b/lib/room.h @@ -46,10 +46,12 @@ namespace QMatrixClient using index_t = int; TimelineItem(RoomEventPtr&& e, index_t number) - : evt(move(e)), idx(number) { } + : evt(std::move(e)), idx(number) { } - RoomEvent* event() const { return evt.get(); } - RoomEvent* operator->() const { return evt.operator->(); } + const RoomEvent* event() const { return rawPtr(evt); } + template + const EventT* viewAs() const { return weakPtr(evt); } + const RoomEventPtr& operator->() const { return evt; } index_t index() const { return idx; } // Used for event redaction @@ -407,12 +409,12 @@ namespace QMatrixClient protected: virtual void processStateEvents(const RoomEvents& events); - virtual void processEphemeralEvent(EventPtr event); - virtual void processAccountDataEvent(EventPtr event); + virtual void processEphemeralEvent(EventPtr&& event); + virtual void processAccountDataEvent(EventPtr&& event); virtual void onAddNewTimelineEvents(timeline_iter_t from) { } virtual void onAddHistoricalTimelineEvents(rev_iter_t from) { } - virtual void onRedaction(const RoomEvent* prevEvent, - const RoomEvent* after) { } + virtual void onRedaction(const RoomEvent& prevEvent, + const RoomEvent& after) { } private: class Private; -- 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') 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') 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