diff options
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/stateevent.cpp | 13 | ||||
-rw-r--r-- | lib/events/stateevent.h | 3 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp index fd8079be..c4151676 100644 --- a/lib/events/stateevent.cpp +++ b/lib/events/stateevent.cpp @@ -20,8 +20,19 @@ using namespace QMatrixClient; +// Aside from the normal factory to instantiate StateEventBase inheritors +// StateEventBase itself can be instantiated if there's a state_key JSON key +// but the event type is unknown. [[gnu::unused]] static auto stateEventTypeInitialised = - RoomEvent::factory_t::chainFactory<StateEventBase>(); + RoomEvent::factory_t::addMethod( + [] (const QJsonObject& json, const QString& matrixType) + { + if (auto e = StateEventBase::factory_t::make(json, matrixType)) + return e; + return json.contains("state_key") + ? makeEvent<StateEventBase>(unknownEventTypeId(), json) + : nullptr; + }); bool StateEventBase::repeatsState() const { diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h index d488c0a0..dc017b11 100644 --- a/lib/events/stateevent.h +++ b/lib/events/stateevent.h @@ -38,6 +38,9 @@ namespace QMatrixClient { using StateEventPtr = event_ptr_tt<StateEventBase>; using StateEvents = EventsArray<StateEventBase>; + template <> + inline bool is<StateEventBase>(const Event& e) { return e.isStateEvent(); } + /** * A combination of event type and state key uniquely identifies a piece * of state in Matrix. |