aboutsummaryrefslogtreecommitdiff
path: root/events/event.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-12-10 09:49:08 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-12-10 16:20:22 +0900
commit6ecdefd8463c0b393dc51535ddb4b4283b5891d8 (patch)
tree70cfe732adf08676246c4432b0f9076ad9392785 /events/event.cpp
parentc38366210643ef0956884531910d7ece3d6a4cac (diff)
downloadlibquotient-6ecdefd8463c0b393dc51535ddb4b4283b5891d8.tar.gz
libquotient-6ecdefd8463c0b393dc51535ddb4b4283b5891d8.zip
RedactionEvent and RoomEvent::redactedBecause()
A RoomEvent now has an optional pointer to a RedactionEvent that is non-null if the room event is redacted. transactionId and serverTimestamp are only filled if the event is not redacted. There's no way to construct a redacted event as of yet.
Diffstat (limited to 'events/event.cpp')
-rw-r--r--events/event.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/events/event.cpp b/events/event.cpp
index 44b742c1..d779f293 100644
--- a/events/event.cpp
+++ b/events/event.cpp
@@ -24,6 +24,7 @@
#include "roomavatarevent.h"
#include "typingevent.h"
#include "receiptevent.h"
+#include "redactionevent.h"
#include "logging.h"
#include <QtCore/QJsonDocument>
@@ -33,7 +34,8 @@ using namespace QMatrixClient;
Event::Event(Type type, const QJsonObject& rep)
: _type(type), _originalJson(rep)
{
- if (!rep.contains("content"))
+ if (!rep.contains("content") &&
+ !rep.value("unsigned").toObject().contains("redacted_because"))
{
qCWarning(EVENTS) << "Event without 'content' node";
qCWarning(EVENTS) << formatJson << rep;
@@ -80,13 +82,12 @@ Event* Event::fromJson(const QJsonObject& obj)
TypingEvent, ReceiptEvent>(obj, obj["type"].toString());
}
+RoomEvent::RoomEvent(Event::Type type) : Event(type) { }
+
RoomEvent::RoomEvent(Type type, const QJsonObject& rep)
: Event(type, rep), _id(rep["event_id"].toString())
- , _serverTimestamp(
- QMatrixClient::fromJson<QDateTime>(rep["origin_server_ts"]))
, _roomId(rep["room_id"].toString())
, _senderId(rep["sender"].toString())
- , _txnId(rep["unsigned"].toObject().value("transactionId").toString())
{
// if (_id.isEmpty())
// {
@@ -103,10 +104,29 @@ RoomEvent::RoomEvent(Type type, const QJsonObject& rep)
// qCWarning(EVENTS) << "Can't find sender in a room event";
// qCWarning(EVENTS) << formatJson << rep;
// }
+ auto unsignedData = rep["unsigned"].toObject();
+ auto redaction = unsignedData.value("redacted_because");
+ if (redaction.isObject())
+ {
+ _redactedBecause.reset(new RedactionEvent(redaction.toObject()));
+ return;
+ }
+
+ _serverTimestamp =
+ QMatrixClient::fromJson<QDateTime>(rep["origin_server_ts"]);
+ _txnId = unsignedData.value("transactionId").toString();
if (!_txnId.isEmpty())
qCDebug(EVENTS) << "Event transactionId:" << _txnId;
}
+RoomEvent::~RoomEvent()
+{ /* Let QScopedPointer<RedactionEvent> do its job */ }
+
+QString RoomEvent::redactionReason() const
+{
+ return isRedacted() ? _redactedBecause->reason() : QString{};
+}
+
void RoomEvent::addId(const QString& id)
{
Q_ASSERT(_id.isEmpty()); Q_ASSERT(!id.isEmpty());
@@ -118,5 +138,6 @@ RoomEvent* RoomEvent::fromJson(const QJsonObject& obj)
return makeIfMatches<RoomEvent,
RoomMessageEvent, RoomNameEvent, RoomAliasesEvent,
RoomCanonicalAliasEvent, RoomMemberEvent, RoomTopicEvent,
- RoomAvatarEvent, EncryptionEvent>(obj, obj["type"].toString());
+ RoomAvatarEvent, EncryptionEvent, RedactionEvent>
+ (obj, obj["type"].toString());
}