aboutsummaryrefslogtreecommitdiff
path: root/lib/events/stateevent.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events/stateevent.h')
-rw-r--r--lib/events/stateevent.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h
index b0aa9907..88da68f8 100644
--- a/lib/events/stateevent.h
+++ b/lib/events/stateevent.h
@@ -17,12 +17,11 @@ inline QJsonObject basicStateEventJson(const QString& matrixTypeId,
{ ContentKey, content } };
}
-class StateEventBase : public RoomEvent {
+class QUOTIENT_API StateEventBase : public RoomEvent {
public:
- using factory_t = EventFactory<StateEventBase>;
+ static inline EventFactory<StateEventBase> factory { "StateEvent" };
- StateEventBase(Type type, const QJsonObject& json) : RoomEvent(type, json)
- {}
+ StateEventBase(Type type, const QJsonObject& json);
StateEventBase(Type type, event_mtype_t matrixType,
const QString& stateKey = {},
const QJsonObject& contentJson = {});
@@ -37,6 +36,22 @@ public:
using StateEventPtr = event_ptr_tt<StateEventBase>;
using StateEvents = EventsArray<StateEventBase>;
+//! \brief Override RoomEvent factory with that from StateEventBase if JSON has
+//! stateKey
+//!
+//! This means in particular that an event with a type known to RoomEvent but
+//! having stateKey set (even to an empty value) will be treated as a state
+//! event and most likely end up as unknown (consider, e.g., m.room.message
+//! that has stateKey set).
+template <>
+inline RoomEventPtr doLoadEvent(const QJsonObject& json,
+ const QString& matrixType)
+{
+ if (json.contains(StateKeyKeyL))
+ return StateEventBase::factory.loadEvent(json, matrixType);
+ return RoomEvent::factory.loadEvent(json, matrixType);
+}
+
template <>
inline bool is<StateEventBase>(const Event& e)
{