diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-11-15 21:51:51 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-11-15 21:51:51 +0100 |
commit | 52cab4b11bdd48cd87e04c01b12c698ec4145e6d (patch) | |
tree | f8b44dd9c585606b4ac229c396ef914d5950fd47 /lib/events | |
parent | 5b1bfc102fccd4e57893b34bf2b0a14ba6a9f577 (diff) | |
download | libquotient-52cab4b11bdd48cd87e04c01b12c698ec4145e6d.tar.gz libquotient-52cab4b11bdd48cd87e04c01b12c698ec4145e6d.zip |
Cleanup across event classes
In particular: removed unnecessary #includes, deprecated and no more
used constructs, replaced stored members with dynamic generation
from JSON (TypingEvent and, especially promising for performance,
ReceiptEvent)
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/callanswerevent.cpp | 5 | ||||
-rw-r--r-- | lib/events/callhangupevent.cpp | 5 | ||||
-rw-r--r-- | lib/events/callinviteevent.cpp | 5 | ||||
-rw-r--r-- | lib/events/encryptedevent.cpp | 3 | ||||
-rw-r--r-- | lib/events/encryptionevent.h | 4 | ||||
-rw-r--r-- | lib/events/event.h | 12 | ||||
-rw-r--r-- | lib/events/reactionevent.h | 3 | ||||
-rw-r--r-- | lib/events/receiptevent.cpp | 12 | ||||
-rw-r--r-- | lib/events/receiptevent.h | 10 | ||||
-rw-r--r-- | lib/events/roomcanonicalaliasevent.h | 4 | ||||
-rw-r--r-- | lib/events/roomevent.cpp | 5 | ||||
-rw-r--r-- | lib/events/roomkeyevent.h | 2 | ||||
-rw-r--r-- | lib/events/roommemberevent.h | 10 | ||||
-rw-r--r-- | lib/events/typingevent.cpp | 8 | ||||
-rw-r--r-- | lib/events/typingevent.h | 7 |
15 files changed, 21 insertions, 74 deletions
diff --git a/lib/events/callanswerevent.cpp b/lib/events/callanswerevent.cpp index d6622b30..bf096534 100644 --- a/lib/events/callanswerevent.cpp +++ b/lib/events/callanswerevent.cpp @@ -18,11 +18,6 @@ #include "callanswerevent.h" -#include "event.h" -#include "logging.h" - -#include <QtCore/QJsonDocument> - /* m.call.answer { diff --git a/lib/events/callhangupevent.cpp b/lib/events/callhangupevent.cpp index d41849c3..f2117f38 100644 --- a/lib/events/callhangupevent.cpp +++ b/lib/events/callhangupevent.cpp @@ -18,11 +18,6 @@ #include "callhangupevent.h" -#include "event.h" -#include "logging.h" - -#include <QtCore/QJsonDocument> - /* m.call.hangup { diff --git a/lib/events/callinviteevent.cpp b/lib/events/callinviteevent.cpp index 54faac8d..63f331de 100644 --- a/lib/events/callinviteevent.cpp +++ b/lib/events/callinviteevent.cpp @@ -18,11 +18,6 @@ #include "callinviteevent.h" -#include "event.h" -#include "logging.h" - -#include <QtCore/QJsonDocument> - /* m.call.invite { diff --git a/lib/events/encryptedevent.cpp b/lib/events/encryptedevent.cpp index dccfa540..117aae37 100644 --- a/lib/events/encryptedevent.cpp +++ b/lib/events/encryptedevent.cpp @@ -1,9 +1,6 @@ #include "encryptedevent.h" -#include "room.h" - using namespace Quotient; -using namespace QtOlm; EncryptedEvent::EncryptedEvent(const QJsonObject& ciphertext, const QString& senderKey) diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h index cbd3ba4a..cbb6d786 100644 --- a/lib/events/encryptionevent.h +++ b/lib/events/encryptionevent.h @@ -48,6 +48,7 @@ public: DEFINE_EVENT_TYPEID("m.room.encryption", EncryptionEvent) using EncryptionType = EncryptionEventContent::EncryptionType; + Q_ENUM(EncryptionType) explicit EncryptionEvent(const QJsonObject& obj = {}) // TODO: apropriate // default value @@ -64,9 +65,6 @@ public: QString algorithm() const { return content().algorithm; } int rotationPeriodMs() const { return content().rotationPeriodMs; } int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; } - -private: - Q_ENUM(EncryptionType) }; REGISTER_EVENT_TYPE(EncryptionEvent) diff --git a/lib/events/event.h b/lib/events/event.h index b12dc9ad..626a0229 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -21,10 +21,6 @@ #include "converters.h" #include "logging.h" -#ifdef ENABLE_EVENTTYPE_ALIAS -# define USE_EVENTTYPE_ALIAS 1 -#endif - namespace Quotient { // === event_ptr_tt<> and type casting facilities === @@ -45,14 +41,6 @@ inline TargetEventT* weakPtrCast(const event_ptr_tt<EventT>& ptr) return static_cast<TargetEventT*>(rawPtr(ptr)); } -/// Re-wrap a smart pointer to base into a smart pointer to derived -template <typename TargetT, typename SourceT> -[[deprecated("Consider using eventCast() or visit() instead")]] -inline event_ptr_tt<TargetT> ptrCast(event_ptr_tt<SourceT>&& ptr) -{ - return std::unique_ptr<TargetT>(static_cast<TargetT*>(ptr.release())); -} - // === Standard Matrix key names and basicEventJson() === static const auto TypeKey = QStringLiteral("type"); diff --git a/lib/events/reactionevent.h b/lib/events/reactionevent.h index 75c6528c..48b0bc6c 100644 --- a/lib/events/reactionevent.h +++ b/lib/events/reactionevent.h @@ -64,9 +64,6 @@ public: { return content<EventRelation>(QStringLiteral("m.relates_to")); } - -private: - EventRelation _relation; }; REGISTER_EVENT_TYPE(ReactionEvent) diff --git a/lib/events/receiptevent.cpp b/lib/events/receiptevent.cpp index bf050cb2..deb3c4e8 100644 --- a/lib/events/receiptevent.cpp +++ b/lib/events/receiptevent.cpp @@ -40,10 +40,11 @@ Example of a Receipt Event: using namespace Quotient; -ReceiptEvent::ReceiptEvent(const QJsonObject& obj) : Event(typeId(), obj) +EventsWithReceipts ReceiptEvent::eventsWithReceipts() const { + EventsWithReceipts result; const auto& contents = contentJson(); - _eventsWithReceipts.reserve(contents.size()); + result.reserve(contents.size()); for (auto eventIt = contents.begin(); eventIt != contents.end(); ++eventIt) { if (eventIt.key().isEmpty()) { qCWarning(EPHEMERAL) @@ -51,15 +52,16 @@ ReceiptEvent::ReceiptEvent(const QJsonObject& obj) : Event(typeId(), obj) qCDebug(EPHEMERAL) << "ReceiptEvent content follows:\n" << contents; continue; } - const QJsonObject reads = + const auto reads = eventIt.value().toObject().value("m.read"_ls).toObject(); QVector<Receipt> receipts; receipts.reserve(reads.size()); for (auto userIt = reads.begin(); userIt != reads.end(); ++userIt) { - const QJsonObject user = userIt.value().toObject(); + const auto user = userIt.value().toObject(); receipts.push_back( { userIt.key(), fromJson<QDateTime>(user["ts"_ls]) }); } - _eventsWithReceipts.push_back({ eventIt.key(), std::move(receipts) }); + result.push_back({ eventIt.key(), std::move(receipts) }); } + return result; } diff --git a/lib/events/receiptevent.h b/lib/events/receiptevent.h index dd54a476..b7adea44 100644 --- a/lib/events/receiptevent.h +++ b/lib/events/receiptevent.h @@ -37,15 +37,9 @@ using EventsWithReceipts = QVector<ReceiptsForEvent>; class ReceiptEvent : public Event { public: DEFINE_EVENT_TYPEID("m.receipt", ReceiptEvent) - explicit ReceiptEvent(const QJsonObject& obj); + explicit ReceiptEvent(const QJsonObject& obj) : Event(typeId(), obj) {} - const EventsWithReceipts& eventsWithReceipts() const - { - return _eventsWithReceipts; - } - -private: - EventsWithReceipts _eventsWithReceipts; + EventsWithReceipts eventsWithReceipts() const; }; REGISTER_EVENT_TYPE(ReceiptEvent) } // namespace Quotient diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h index fadfece0..4a21b7cc 100644 --- a/lib/events/roomcanonicalaliasevent.h +++ b/lib/events/roomcanonicalaliasevent.h @@ -61,13 +61,13 @@ public: explicit RoomCanonicalAliasEvent(const QString& canonicalAlias, const QStringList& altAliases = {}) - : StateEvent(typeId(), matrixTypeId(), QString(), + : StateEvent(typeId(), matrixTypeId(), {}, canonicalAlias, altAliases) { } explicit RoomCanonicalAliasEvent(QString&& canonicalAlias, QStringList&& altAliases = {}) - : StateEvent(typeId(), matrixTypeId(), QString(), + : StateEvent(typeId(), matrixTypeId(), {}, std::move(canonicalAlias), std::move(altAliases)) { } diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp index 3d87ef18..a2dbc07d 100644 --- a/lib/events/roomevent.cpp +++ b/lib/events/roomevent.cpp @@ -34,9 +34,8 @@ RoomEvent::RoomEvent(Type type, event_mtype_t matrixType, RoomEvent::RoomEvent(Type type, const QJsonObject& json) : Event(type, json) { - const auto unsignedData = json[UnsignedKeyL].toObject(); - const auto redaction = unsignedData[RedactedCauseKeyL]; - if (redaction.isObject()) + if (const auto redaction = unsignedJson()[RedactedCauseKeyL]; + redaction.isObject()) _redactedBecause = makeEvent<RedactionEvent>(redaction.toObject()); } diff --git a/lib/events/roomkeyevent.h b/lib/events/roomkeyevent.h index 3a781474..b8cd2eae 100644 --- a/lib/events/roomkeyevent.h +++ b/lib/events/roomkeyevent.h @@ -8,7 +8,7 @@ class RoomKeyEvent : public Event public: DEFINE_EVENT_TYPEID("m.room_key", RoomKeyEvent) - RoomKeyEvent(const QJsonObject& obj); + explicit RoomKeyEvent(const QJsonObject& obj); QString algorithm() const { return content<QString>("algorithm"_ls); } QString roomId() const { return content<QString>(RoomIdKeyL); } diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h index 35fd69a9..cebaaf10 100644 --- a/lib/events/roommemberevent.h +++ b/lib/events/roommemberevent.h @@ -54,13 +54,10 @@ public: DEFINE_EVENT_TYPEID("m.room.member", RoomMemberEvent) using MembershipType = MemberEventContent::MembershipType; + Q_ENUM(MembershipType) explicit RoomMemberEvent(const QJsonObject& obj) : StateEvent(typeId(), obj) {} - [[deprecated("Use RoomMemberEvent(userId, contentArgs) instead")]] - RoomMemberEvent(MemberEventContent&& c) - : StateEvent(typeId(), matrixTypeId(), QString(), c) - {} template <typename... ArgTs> RoomMemberEvent(const QString& userId, ArgTs&&... contentArgs) : StateEvent(typeId(), matrixTypeId(), userId, @@ -82,7 +79,7 @@ public: {} MembershipType membership() const { return content().membership; } - QString userId() const { return fullJson()[StateKeyKeyL].toString(); } + QString userId() const { return stateKey(); } bool isDirect() const { return content().isDirect; } Omittable<QString> newDisplayName() const { return content().displayName; } Omittable<QUrl> newAvatarUrl() const { return content().avatarUrl; } @@ -104,9 +101,6 @@ public: bool isLeave() const; bool isRename() const; bool isAvatarUpdate() const; - -private: - Q_ENUM(MembershipType) }; template <> diff --git a/lib/events/typingevent.cpp b/lib/events/typingevent.cpp index 0c5fc6ba..e102fc79 100644 --- a/lib/events/typingevent.cpp +++ b/lib/events/typingevent.cpp @@ -18,13 +18,9 @@ #include "typingevent.h" -#include <QtCore/QJsonArray> - using namespace Quotient; -TypingEvent::TypingEvent(const QJsonObject& obj) : Event(typeId(), obj) +QStringList TypingEvent::users() const { - const auto& array = contentJson()["user_ids"_ls].toArray(); - for (const auto& user : array) - _users.push_back(user.toString()); + return fromJson<QStringList>(contentJson()["user_ids"_ls]); } diff --git a/lib/events/typingevent.h b/lib/events/typingevent.h index 1cf4e69d..97e1f9cc 100644 --- a/lib/events/typingevent.h +++ b/lib/events/typingevent.h @@ -25,12 +25,9 @@ class TypingEvent : public Event { public: DEFINE_EVENT_TYPEID("m.typing", TypingEvent) - TypingEvent(const QJsonObject& obj); + explicit TypingEvent(const QJsonObject& obj) : Event(typeId(), obj) {} - const QStringList& users() const { return _users; } - -private: - QStringList _users; + QStringList users() const; }; REGISTER_EVENT_TYPE(TypingEvent) } // namespace Quotient |