aboutsummaryrefslogtreecommitdiff
path: root/lib/events/event.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 19:46:08 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 20:13:44 +0900
commit2cbb2a8c1be8bf08b1b835ffaa7bb0bee823e3a6 (patch)
tree0b436233d3c6042bad2852cc215b20d7b1a10c24 /lib/events/event.cpp
parent3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee (diff)
downloadlibquotient-2cbb2a8c1be8bf08b1b835ffaa7bb0bee823e3a6.tar.gz
libquotient-2cbb2a8c1be8bf08b1b835ffaa7bb0bee823e3a6.zip
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.
Diffstat (limited to 'lib/events/event.cpp')
-rw-r--r--lib/events/event.cpp79
1 files changed, 6 insertions, 73 deletions
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 <QtCore/QJsonDocument>
using namespace QMatrixClient;
+event_type_t QMatrixClient::nextTypeId()
+{
+ static event_type_t _id = EventTypeTraits<void>::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::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<RedactionEvent>(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<QDateTime>(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<StateEventBase>();
-
-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<void>::id;
- return ++_id;
-}