aboutsummaryrefslogtreecommitdiff
path: root/lib/events/stateevent.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-01-06 17:45:34 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-01-06 17:45:34 +0900
commitc83a73b17eaef465150458282e63a478ba238f26 (patch)
treed6c2416fa765d2fb00924da9e5086a5a743294b2 /lib/events/stateevent.cpp
parenta23fa6df08008f4a3f7437efa8afe839a102dc8e (diff)
downloadlibquotient-c83a73b17eaef465150458282e63a478ba238f26.tar.gz
libquotient-c83a73b17eaef465150458282e63a478ba238f26.zip
Create StateEventBase events if state_key is there
This makes unknown state events to still be treated as state events.
Diffstat (limited to 'lib/events/stateevent.cpp')
-rw-r--r--lib/events/stateevent.cpp13
1 files changed, 12 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
{