aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-04 21:12:29 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-08 17:43:58 +0200
commit843f7a0ac2619a2f2863d457cdeaa03707255793 (patch)
tree3c518b467d318dc54b36b0bcf17cdb719d9e3cfe /lib/events
parent4070706fcc91cd46054b00c5f3a267a9d8c44fb7 (diff)
downloadlibquotient-843f7a0ac2619a2f2863d457cdeaa03707255793.tar.gz
libquotient-843f7a0ac2619a2f2863d457cdeaa03707255793.zip
basic*EventJson() -> *Event::basicJson()
This makes it easier and more intuitive to build a minimal JSON payload for a given event type. A common basicJson() call point is also convenient in template contexts (see next commits).
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/event.cpp2
-rw-r--r--lib/events/event.h14
-rw-r--r--lib/events/eventloader.h4
-rw-r--r--lib/events/roomevent.cpp10
-rw-r--r--lib/events/roomevent.h5
-rw-r--r--lib/events/stateevent.cpp2
-rw-r--r--lib/events/stateevent.h28
7 files changed, 39 insertions, 26 deletions
diff --git a/lib/events/event.cpp b/lib/events/event.cpp
index 4c304a3c..1f1eebaa 100644
--- a/lib/events/event.cpp
+++ b/lib/events/event.cpp
@@ -29,7 +29,7 @@ Event::Event(Type type, const QJsonObject& json) : _type(type), _json(json)
}
Event::Event(Type type, event_mtype_t matrixType, const QJsonObject& contentJson)
- : Event(type, basicEventJson(matrixType, contentJson))
+ : Event(type, basicJson(matrixType, contentJson))
{}
Event::~Event() = default;
diff --git a/lib/events/event.h b/lib/events/event.h
index 113fa3fa..5be2b41b 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -48,13 +48,6 @@ const QString RoomIdKey { RoomIdKeyL };
const QString UnsignedKey { UnsignedKeyL };
const QString StateKeyKey { StateKeyKeyL };
-/// Make a minimal correct Matrix event JSON
-inline QJsonObject basicEventJson(const QString& matrixType,
- const QJsonObject& content)
-{
- return { { TypeKey, matrixType }, { ContentKey, content } };
-}
-
// === Event types ===
using event_type_t = QLatin1String;
@@ -193,6 +186,13 @@ public:
Event& operator=(Event&&) = delete;
virtual ~Event();
+ /// Make a minimal correct Matrix event JSON
+ static QJsonObject basicJson(const QString& matrixType,
+ const QJsonObject& content)
+ {
+ return { { TypeKey, matrixType }, { ContentKey, content } };
+ }
+
Type type() const { return _type; }
QString matrixType() const;
[[deprecated("Use fullJson() and stringify it with QJsonDocument::toJson() "
diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h
index fe624d70..c7b82e8e 100644
--- a/lib/events/eventloader.h
+++ b/lib/events/eventloader.h
@@ -29,7 +29,7 @@ template <typename BaseEventT>
inline event_ptr_tt<BaseEventT> loadEvent(const QString& matrixType,
const QJsonObject& content)
{
- return doLoadEvent<BaseEventT>(basicEventJson(matrixType, content),
+ return doLoadEvent<BaseEventT>(Event::basicJson(matrixType, content),
matrixType);
}
@@ -44,7 +44,7 @@ inline StateEventPtr loadStateEvent(const QString& matrixType,
const QString& stateKey = {})
{
return doLoadEvent<StateEventBase>(
- basicStateEventJson(matrixType, content, stateKey), matrixType);
+ StateEventBase::basicJson(matrixType, content, stateKey), matrixType);
}
template <typename EventT>
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
index 2f482871..ebe72149 100644
--- a/lib/events/roomevent.cpp
+++ b/lib/events/roomevent.cpp
@@ -101,19 +101,19 @@ void RoomEvent::dumpTo(QDebug dbg) const
dbg << " (made at " << originTimestamp().toString(Qt::ISODate) << ')';
}
-QJsonObject makeCallContentJson(const QString& callId, int version,
- QJsonObject content)
+QJsonObject CallEventBase::basicJson(const QString& matrixType,
+ const QString& callId, int version,
+ QJsonObject content)
{
content.insert(QStringLiteral("call_id"), callId);
content.insert(QStringLiteral("version"), version);
- return content;
+ return RoomEvent::basicJson(matrixType, content);
}
CallEventBase::CallEventBase(Type type, event_mtype_t matrixType,
const QString& callId, int version,
const QJsonObject& contentJson)
- : RoomEvent(type, matrixType,
- makeCallContentJson(callId, version, contentJson))
+ : RoomEvent(type, basicJson(type, callId, version, contentJson))
{}
CallEventBase::CallEventBase(Event::Type type, const QJsonObject& json)
diff --git a/lib/events/roomevent.h b/lib/events/roomevent.h
index a7d6c428..0692ad8a 100644
--- a/lib/events/roomevent.h
+++ b/lib/events/roomevent.h
@@ -98,6 +98,11 @@ public:
QString callId() const { return contentPart<QString>("call_id"_ls); }
int version() const { return contentPart<int>("version"_ls); }
+
+protected:
+ static QJsonObject basicJson(const QString& matrixType,
+ const QString& callId, int version,
+ QJsonObject contentJson = {});
};
} // namespace Quotient
Q_DECLARE_METATYPE(Quotient::RoomEvent*)
diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp
index e53d47d4..cdf3c449 100644
--- a/lib/events/stateevent.cpp
+++ b/lib/events/stateevent.cpp
@@ -16,7 +16,7 @@ StateEventBase::StateEventBase(Type type, const QJsonObject& json)
StateEventBase::StateEventBase(Event::Type type, event_mtype_t matrixType,
const QString& stateKey,
const QJsonObject& contentJson)
- : RoomEvent(type, basicStateEventJson(matrixType, contentJson, stateKey))
+ : RoomEvent(type, basicJson(type, contentJson, stateKey))
{}
bool StateEventBase::repeatsState() const
diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h
index 19905431..47bf6e59 100644
--- a/lib/events/stateevent.h
+++ b/lib/events/stateevent.h
@@ -7,16 +7,6 @@
namespace Quotient {
-/// Make a minimal correct Matrix state event JSON
-inline QJsonObject basicStateEventJson(const QString& matrixTypeId,
- const QJsonObject& content,
- const QString& stateKey = {})
-{
- return { { TypeKey, matrixTypeId },
- { StateKeyKey, stateKey },
- { ContentKey, content } };
-}
-
class QUOTIENT_API StateEventBase : public RoomEvent {
public:
static inline EventFactory<StateEventBase> factory { "StateEvent" };
@@ -27,6 +17,16 @@ public:
const QJsonObject& contentJson = {});
~StateEventBase() override = default;
+ //! Make a minimal correct Matrix state event JSON
+ static QJsonObject basicJson(const QString& matrixTypeId,
+ const QJsonObject& content,
+ const QString& stateKey = {})
+ {
+ return { { TypeKey, matrixTypeId },
+ { StateKeyKey, stateKey },
+ { ContentKey, content } };
+ }
+
bool isStateEvent() const override { return true; }
QString replacedState() const;
void dumpTo(QDebug dbg) const override;
@@ -36,6 +36,14 @@ public:
using StateEventPtr = event_ptr_tt<StateEventBase>;
using StateEvents = EventsArray<StateEventBase>;
+[[deprecated("Use StateEventBase::basicJson() instead")]]
+inline QJsonObject basicStateEventJson(const QString& matrixTypeId,
+ const QJsonObject& content,
+ const QString& stateKey = {})
+{
+ return StateEventBase::basicJson(matrixTypeId, content, stateKey);
+}
+
//! \brief Override RoomEvent factory with that from StateEventBase if JSON has
//! stateKey
//!