aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-11-12 18:51:35 +0100
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-11-12 18:51:35 +0100
commit4cc8838c3bbe712493a4f6ddbecd0f7093e907bb (patch)
treea0efd33b273d044acf380b1f1370cf27d50c6c96
parent39b80fa8eb9b70d287aa453663b845319d8b6196 (diff)
downloadlibquotient-4cc8838c3bbe712493a4f6ddbecd0f7093e907bb.tar.gz
libquotient-4cc8838c3bbe712493a4f6ddbecd0f7093e907bb.zip
More JSON key constants
-rw-r--r--lib/connection.cpp2
-rw-r--r--lib/events/event.h4
-rw-r--r--lib/events/roomevent.cpp8
-rw-r--r--lib/events/roomkeyevent.h2
-rw-r--r--lib/room.cpp4
5 files changed, 12 insertions, 8 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 0f53643b..e84b8080 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -202,7 +202,7 @@ public:
auto&& decryptedEvent =
fromJson<EventPtr>(QJsonDocument::fromJson(decrypted.toUtf8()));
- if (auto sender = decryptedEvent->fullJson()["sender"_ls].toString();
+ if (auto sender = decryptedEvent->fullJson()[SenderKeyL].toString();
sender != encryptedEvent.senderId()) {
qCWarning(E2EE) << "Found user" << sender
<< "instead of sender" << encryptedEvent.senderId()
diff --git a/lib/events/event.h b/lib/events/event.h
index 5b9f20b7..b12dc9ad 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -59,12 +59,16 @@ static const auto TypeKey = QStringLiteral("type");
static const auto BodyKey = QStringLiteral("body");
static const auto ContentKey = QStringLiteral("content");
static const auto EventIdKey = QStringLiteral("event_id");
+static const auto SenderKey = QStringLiteral("sender");
+static const auto RoomIdKey = QStringLiteral("room_id");
static const auto UnsignedKey = QStringLiteral("unsigned");
static const auto StateKeyKey = QStringLiteral("state_key");
static const auto TypeKeyL = "type"_ls;
static const auto BodyKeyL = "body"_ls;
static const auto ContentKeyL = "content"_ls;
static const auto EventIdKeyL = "event_id"_ls;
+static const auto SenderKeyL = "sender"_ls;
+static const auto RoomIdKeyL = "room_id"_ls;
static const auto UnsignedKeyL = "unsigned"_ls;
static const auto RedactedCauseKeyL = "redacted_because"_ls;
static const auto PrevContentKeyL = "prev_content"_ls;
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
index 0a4332ad..3d87ef18 100644
--- a/lib/events/roomevent.cpp
+++ b/lib/events/roomevent.cpp
@@ -51,12 +51,12 @@ QDateTime RoomEvent::originTimestamp() const
QString RoomEvent::roomId() const
{
- return fullJson()["room_id"_ls].toString();
+ return fullJson()[RoomIdKeyL].toString();
}
QString RoomEvent::senderId() const
{
- return fullJson()["sender"_ls].toString();
+ return fullJson()[SenderKeyL].toString();
}
bool RoomEvent::isReplaced() const
@@ -90,12 +90,12 @@ QString RoomEvent::stateKey() const
void RoomEvent::setRoomId(const QString& roomId)
{
- editJson().insert(QStringLiteral("room_id"), roomId);
+ editJson().insert(RoomIdKey, roomId);
}
void RoomEvent::setSender(const QString& senderId)
{
- editJson().insert(QStringLiteral("sender"), senderId);
+ editJson().insert(SenderKey, senderId);
}
void RoomEvent::setTransactionId(const QString& txnId)
diff --git a/lib/events/roomkeyevent.h b/lib/events/roomkeyevent.h
index 679cbf7c..3a781474 100644
--- a/lib/events/roomkeyevent.h
+++ b/lib/events/roomkeyevent.h
@@ -11,7 +11,7 @@ public:
RoomKeyEvent(const QJsonObject& obj);
QString algorithm() const { return content<QString>("algorithm"_ls); }
- QString roomId() const { return content<QString>("room_id"_ls); }
+ QString roomId() const { return content<QString>(RoomIdKeyL); }
QString sessionId() const { return content<QString>("session_id"_ls); }
QString sessionKey() const { return content<QString>("session_key"_ls); }
};
diff --git a/lib/room.cpp b/lib/room.cpp
index e98116a9..57de4f0c 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -2064,8 +2064,8 @@ RoomEventPtr makeRedacted(const RoomEvent& target,
{
auto originalJson = target.originalJsonObject();
// clang-format off
- static const QStringList keepKeys { EventIdKey, TypeKey,
- QStringLiteral("room_id"), QStringLiteral("sender"), StateKeyKey,
+ static const QStringList keepKeys {
+ EventIdKey, TypeKey, RoomIdKey, SenderKey, StateKeyKey,
QStringLiteral("hashes"), QStringLiteral("signatures"),
QStringLiteral("depth"), QStringLiteral("prev_events"),
QStringLiteral("prev_state"), QStringLiteral("auth_events"),