aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roomevent.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 21:34:00 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 21:34:00 +0900
commit6a9de91752dfe75e185bf90ab856367b2c804582 (patch)
tree2a12ecc84bf0055e317ef2e4aeec3439d92b2035 /lib/events/roomevent.cpp
parentd5397fe5ae2ca34d5cfb11394dac17728a2b50ce (diff)
parent5d1dd53890611376873f6f959e206d5a56cfff70 (diff)
downloadlibquotient-6a9de91752dfe75e185bf90ab856367b2c804582.tar.gz
libquotient-6a9de91752dfe75e185bf90ab856367b2c804582.zip
Merge branch 'kitsune-events-rewritten'
Diffstat (limited to 'lib/events/roomevent.cpp')
-rw-r--r--lib/events/roomevent.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
new file mode 100644
index 00000000..3d09af8a
--- /dev/null
+++ b/lib/events/roomevent.cpp
@@ -0,0 +1,82 @@
+/******************************************************************************
+* Copyright (C) 2018 Kitsune Ral <kitsune-ral@users.sf.net>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "roomevent.h"
+
+#include "redactionevent.h"
+#include "converters.h"
+#include "logging.h"
+
+using namespace QMatrixClient;
+
+[[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);
+}