From 2cbb2a8c1be8bf08b1b835ffaa7bb0bee823e3a6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 4 Jul 2018 19:46:08 +0900 Subject: Break down event.* into smaller files We now have event.*, roomevent.*, stateevent.* and eventloader.h. If you only use event leaf-classes (such as RoomMemberEvent) you shouldn't notice anything. --- lib/events/event.cpp | 79 ++++------------------------------------------------ 1 file changed, 6 insertions(+), 73 deletions(-) (limited to 'lib/events/event.cpp') diff --git a/lib/events/event.cpp b/lib/events/event.cpp index 447068af..44bf79a1 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -18,13 +18,18 @@ #include "event.h" -#include "redactionevent.h" #include "logging.h" #include using namespace QMatrixClient; +event_type_t QMatrixClient::nextTypeId() +{ + static event_type_t _id = EventTypeTraits::id; + return ++_id; +} + Event::Event(Type type, const QJsonObject& json) : _type(type), _json(json) { @@ -61,75 +66,3 @@ const QJsonObject Event::unsignedJson() const { return fullJson()[UnsignedKeyL].toObject(); } - -[[gnu::unused]] static auto roomEventTypeInitialised = - Event::factory_t::chainFactory(); - -RoomEvent::RoomEvent(Type type, event_mtype_t matrixType, - const QJsonObject& contentJson) - : Event(type, matrixType, contentJson) -{ } - -RoomEvent::RoomEvent(Type type, const QJsonObject& json) - : Event(type, json) -{ - const auto unsignedData = json[UnsignedKeyL].toObject(); - const auto redaction = unsignedData[RedactedCauseKeyL]; - if (redaction.isObject()) - { - _redactedBecause = makeEvent(redaction.toObject()); - return; - } - - _txnId = unsignedData.value("transactionId"_ls).toString(); - if (!_txnId.isEmpty()) - qCDebug(EVENTS) << "Event transactionId:" << _txnId; -} - -RoomEvent::~RoomEvent() = default; // Let the smart pointer do its job - -QString RoomEvent::id() const -{ - return fullJson()[EventIdKeyL].toString(); -} - -QDateTime RoomEvent::timestamp() const -{ - return QMatrixClient::fromJson(fullJson()["origin_server_ts"_ls]); -} - -QString RoomEvent::roomId() const -{ - return fullJson()["room_id"_ls].toString(); -} - -QString RoomEvent::senderId() const -{ - return fullJson()["sender"_ls].toString(); -} - -QString RoomEvent::redactionReason() const -{ - return isRedacted() ? _redactedBecause->reason() : QString{}; -} - -void RoomEvent::addId(const QString& newId) -{ - Q_ASSERT(id().isEmpty()); Q_ASSERT(!newId.isEmpty()); - editJson().insert(EventIdKey, newId); -} - -[[gnu::unused]] static auto stateEventTypeInitialised = - RoomEvent::factory_t::chainFactory(); - -bool StateEventBase::repeatsState() const -{ - const auto prevContentJson = unsignedJson().value(PrevContentKeyL); - return fullJson().value(ContentKeyL) == prevContentJson; -} - -event_type_t QMatrixClient::nextTypeId() -{ - static event_type_t _id = EventTypeTraits::id; - return ++_id; -} -- cgit v1.2.3