aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roomevent.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-31 08:56:38 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-31 08:56:38 +0900
commit0ec67c2f6ba0e122fb7274cec1aaa1ee398b9bfd (patch)
tree793383b93993d71b0a8fb48d22dd619fd75bf791 /lib/events/roomevent.cpp
parent68358af90bdfbcb6f2884c6d1c795f1724cf840b (diff)
downloadlibquotient-0ec67c2f6ba0e122fb7274cec1aaa1ee398b9bfd.tar.gz
libquotient-0ec67c2f6ba0e122fb7274cec1aaa1ee398b9bfd.zip
RoomEvent: don't store transactionId separately
It's present on the vast minority of events so better be embedded into JSON instead.
Diffstat (limited to 'lib/events/roomevent.cpp')
-rw-r--r--lib/events/roomevent.cpp22
1 files changed, 19 insertions, 3 deletions
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);
}