diff options
Diffstat (limited to 'lib/events/event.cpp')
-rw-r--r-- | lib/events/event.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/events/event.cpp b/lib/events/event.cpp index 1d5f1b0d..576e9426 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -76,7 +76,7 @@ template <typename BaseEventT, typename EventT, typename... EventTs> inline event_ptr_tt<BaseEventT> makeIfMatches(const QJsonObject& o, const QString& selector) { - if (selector == EventT::TypeId) + if (selector == EventT::typeId()) return _impl::create<EventT>(o); return makeIfMatches<BaseEventT, EventTs...>(o, selector); @@ -160,14 +160,13 @@ void RoomEvent::addId(const QString& id) template <> RoomEventPtr _impl::doMakeEvent(const QJsonObject& obj) { - return RoomEventPtr { makeIfMatches<RoomEvent, - RoomMessageEvent, RoomNameEvent, RoomAliasesEvent, - RoomCanonicalAliasEvent, RoomMemberEvent, RoomTopicEvent, - RoomAvatarEvent, EncryptionEvent, RedactionEvent> - (obj, obj["type"].toString()) }; -} + // Check more specific event types first + if (auto e = doMakeEvent<StateEventBase>(obj)) + return ptrCast<RoomEvent>(move(e)); -StateEventBase::~StateEventBase() = default; + return makeIfMatches<RoomEvent, + RoomMessageEvent, RedactionEvent>(obj, obj["type"].toString()); +} bool StateEventBase::repeatsState() const { @@ -176,3 +175,13 @@ bool StateEventBase::repeatsState() const .toObject().value("prev_content"); return contentJson == prevContentJson; } + +template<> +StateEventPtr _impl::doMakeEvent<StateEventBase>(const QJsonObject& obj) +{ + return makeIfMatches<StateEventBase, + RoomNameEvent, RoomAliasesEvent, + RoomCanonicalAliasEvent, RoomMemberEvent, RoomTopicEvent, + RoomAvatarEvent, EncryptionEvent>(obj, obj["type"].toString()); + +} |