diff options
-rw-r--r-- | lib/events/event.h | 1 | ||||
-rw-r--r-- | lib/events/roomevent.cpp | 22 | ||||
-rw-r--r-- | lib/events/roomevent.h | 7 |
3 files changed, 23 insertions, 7 deletions
diff --git a/lib/events/event.h b/lib/events/event.h index 28d73e2a..8fa8c901 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -57,6 +57,7 @@ namespace QMatrixClient static const auto TypeKey = QStringLiteral("type"); static const auto ContentKey = QStringLiteral("content"); static const auto EventIdKey = QStringLiteral("event_id"); + static const auto UnsignedKey = QStringLiteral("unsigned"); static const auto TypeKeyL = "type"_ls; static const auto ContentKeyL = "content"_ls; static const auto EventIdKeyL = "event_id"_ls; diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp index 75850772..738a5f58 100644 --- a/lib/events/roomevent.cpp +++ b/lib/events/roomevent.cpp @@ -43,9 +43,9 @@ RoomEvent::RoomEvent(Type type, const QJsonObject& json) return; } - _txnId = unsignedData.value("transactionId"_ls).toString(); - if (!_txnId.isEmpty()) - qCDebug(EVENTS) << "Event transactionId:" << _txnId; + const auto& txnId = transactionId(); + if (!txnId.isEmpty()) + qCDebug(EVENTS) << "Event transactionId:" << txnId; } RoomEvent::~RoomEvent() = default; // Let the smart pointer do its job @@ -75,13 +75,29 @@ QString RoomEvent::redactionReason() const return isRedacted() ? _redactedBecause->reason() : QString{}; } +QString RoomEvent::transactionId() const +{ + return unsignedJson()["transactionId"_ls].toString(); +} + QString RoomEvent::stateKey() const { return fullJson()["state_key"_ls].toString(); } +void RoomEvent::setTransactionId(const QString& txnId) +{ + auto unsignedData = fullJson()[UnsignedKeyL].toObject(); + unsignedData.insert(QStringLiteral("transactionId"), txnId); + editJson().insert(UnsignedKey, unsignedData); + qCDebug(EVENTS) << "New event transactionId:" << txnId; + Q_ASSERT(transactionId() == txnId); +} + void RoomEvent::addId(const QString& newId) { Q_ASSERT(id().isEmpty()); Q_ASSERT(!newId.isEmpty()); editJson().insert(EventIdKey, newId); + qCDebug(EVENTS) << "Event txnId -> id:" << transactionId() << "->" << id(); + Q_ASSERT(id() == newId); } diff --git a/lib/events/roomevent.h b/lib/events/roomevent.h index fcbb33e5..a345d176 100644 --- a/lib/events/roomevent.h +++ b/lib/events/roomevent.h @@ -35,7 +35,7 @@ namespace QMatrixClient { Q_PROPERTY(QString senderId READ senderId CONSTANT) Q_PROPERTY(QString redactionReason READ redactionReason) Q_PROPERTY(bool isRedacted READ isRedacted) - Q_PROPERTY(QString transactionId READ transactionId) + Q_PROPERTY(QString transactionId READ transactionId WRITE setTransactionId) public: using factory_t = EventFactory<RoomEvent>; @@ -56,7 +56,7 @@ namespace QMatrixClient { return _redactedBecause; } QString redactionReason() const; - const QString& transactionId() const { return _txnId; } + QString transactionId() const; QString stateKey() const; /** @@ -67,7 +67,7 @@ namespace QMatrixClient { * \param txnId - transaction id, normally obtained from * Connection::generateTxnId() */ - void setTransactionId(const QString& txnId) { _txnId = txnId; } + void setTransactionId(const QString& txnId); /** * Sets event id for locally created events @@ -82,7 +82,6 @@ namespace QMatrixClient { private: event_ptr_tt<RedactionEvent> _redactedBecause; - QString _txnId; }; using RoomEventPtr = event_ptr_tt<RoomEvent>; using RoomEvents = EventsArray<RoomEvent>; |