aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-07-06 19:58:29 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-07-06 19:58:29 +0900
commit01cce0e39d255cbcf39f6a1aa58c6d7ab1d995d1 (patch)
tree217c33312e9b9832c0c392f7416fcfc38de19689
parent5b8079ca3d35360b7d98814654f37885f21bcb7e (diff)
downloadlibquotient-01cce0e39d255cbcf39f6a1aa58c6d7ab1d995d1.tar.gz
libquotient-01cce0e39d255cbcf39f6a1aa58c6d7ab1d995d1.zip
Convenience: StateKeyKey, StateKeyKeyL, basicStateEventJson()
-rw-r--r--lib/events/event.h4
-rw-r--r--lib/events/roomevent.cpp2
-rw-r--r--lib/events/roommemberevent.h2
-rw-r--r--lib/events/stateevent.cpp2
-rw-r--r--lib/events/stateevent.h11
-rw-r--r--lib/room.cpp2
6 files changed, 18 insertions, 5 deletions
diff --git a/lib/events/event.h b/lib/events/event.h
index 5248472c..b3a58806 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -60,14 +60,16 @@ namespace QMatrixClient
static const auto ContentKey = QStringLiteral("content");
static const auto EventIdKey = QStringLiteral("event_id");
static const auto UnsignedKey = QStringLiteral("unsigned");
+ static const auto StateKeyKey = QStringLiteral("state_key");
static const auto TypeKeyL = "type"_ls;
static const auto ContentKeyL = "content"_ls;
static const auto EventIdKeyL = "event_id"_ls;
static const auto UnsignedKeyL = "unsigned"_ls;
static const auto RedactedCauseKeyL = "redacted_because"_ls;
static const auto PrevContentKeyL = "prev_content"_ls;
+ static const auto StateKeyKeyL = "state_key"_ls;
- // Minimal correct Matrix event JSON
+ /// Make a minimal correct Matrix event JSON
template <typename StrT>
inline QJsonObject basicEventJson(StrT matrixType,
const QJsonObject& content)
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
index 3d03509f..62c2a76d 100644
--- a/lib/events/roomevent.cpp
+++ b/lib/events/roomevent.cpp
@@ -78,7 +78,7 @@ QString RoomEvent::transactionId() const
QString RoomEvent::stateKey() const
{
- return fullJson()["state_key"_ls].toString();
+ return fullJson()[StateKeyKeyL].toString();
}
void RoomEvent::setTransactionId(const QString& txnId)
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h
index b8224033..4490fe65 100644
--- a/lib/events/roommemberevent.h
+++ b/lib/events/roommemberevent.h
@@ -76,7 +76,7 @@ namespace QMatrixClient
MembershipType membership() const { return content().membership; }
QString userId() const
- { return fullJson()["state_key"_ls].toString(); }
+ { return fullJson()[StateKeyKeyL].toString(); }
bool isDirect() const { return content().isDirect; }
QString displayName() const { return content().displayName; }
QUrl avatarUrl() const { return content().avatarUrl; }
diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp
index a84f302b..476e0fd6 100644
--- a/lib/events/stateevent.cpp
+++ b/lib/events/stateevent.cpp
@@ -27,7 +27,7 @@ using namespace QMatrixClient;
RoomEvent::factory_t::addMethod(
[] (const QJsonObject& json, const QString& matrixType) -> StateEventPtr
{
- if (!json.contains("state_key"_ls))
+ if (!json.contains(StateKeyKeyL))
return nullptr;
if (auto e = StateEventBase::factory_t::make(json, matrixType))
diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h
index 3f54f7bf..5dadac7f 100644
--- a/lib/events/stateevent.h
+++ b/lib/events/stateevent.h
@@ -21,6 +21,17 @@
#include "roomevent.h"
namespace QMatrixClient {
+
+ /// Make a minimal correct Matrix state event JSON
+ template <typename StrT>
+ inline QJsonObject basicStateEventJson(StrT matrixType,
+ const QJsonObject& content, const QString& stateKey = {})
+ {
+ return { { TypeKey, std::forward<StrT>(matrixType) },
+ { StateKeyKey, stateKey },
+ { ContentKey, content } };
+ }
+
class StateEventBase: public RoomEvent
{
public:
diff --git a/lib/room.cpp b/lib/room.cpp
index c5367047..8c9f8760 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1920,7 +1920,7 @@ RoomEventPtr makeRedacted(const RoomEvent& target,
auto originalJson = target.originalJsonObject();
static const QStringList keepKeys {
EventIdKey, TypeKey, QStringLiteral("room_id"),
- QStringLiteral("sender"), QStringLiteral("state_key"),
+ QStringLiteral("sender"), StateKeyKey,
QStringLiteral("prev_content"), ContentKey,
QStringLiteral("hashes"), QStringLiteral("signatures"),
QStringLiteral("depth"), QStringLiteral("prev_events"),