diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-11 18:16:39 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-11 18:16:39 +0900 |
commit | 1ffb27f506ed1a4b3766768b872a86af7799a39e (patch) | |
tree | b87c0b36d5da179bc41182598c1253986189de58 /lib/events/eventloader.h | |
parent | d714e47dd713d89d1581dbad1a8e751fcf5fa2e4 (diff) | |
download | libquotient-1ffb27f506ed1a4b3766768b872a86af7799a39e.tar.gz libquotient-1ffb27f506ed1a4b3766768b872a86af7799a39e.zip |
EventFactory::make() should return nullptr in case of failure
Otherwise factory chaining doesn't work right (an unknown event returned
by a chained factory is treated as successful parsing).
Diffstat (limited to 'lib/events/eventloader.h')
-rw-r--r-- | lib/events/eventloader.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 5f1e3b57..ea261cac 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -22,6 +22,17 @@ #include "converters.h" namespace QMatrixClient { + namespace _impl { + template <typename BaseEventT> + static inline auto loadEvent(const QJsonObject& json, + const QString& matrixType) + { + if (auto e = EventFactory<BaseEventT>::make(json, matrixType)) + return e; + return makeEvent<BaseEventT>(unknownEventTypeId(), json); + } + } + /** Create an event with proper type from a JSON object * Use this factory template to detect the type from the JSON object * contents (the detected event type should derive from the template @@ -30,8 +41,8 @@ namespace QMatrixClient { template <typename BaseEventT> inline event_ptr_tt<BaseEventT> loadEvent(const QJsonObject& fullJson) { - return EventFactory<BaseEventT> - ::make(fullJson, fullJson[TypeKeyL].toString()); + return _impl::loadEvent<BaseEventT>(fullJson, + fullJson[TypeKeyL].toString()); } /** Create an event from a type string and content JSON @@ -43,8 +54,8 @@ namespace QMatrixClient { inline event_ptr_tt<BaseEventT> loadEvent(const QString& matrixType, const QJsonObject& content) { - return EventFactory<BaseEventT> - ::make(basicEventJson(matrixType, content), matrixType); + return _impl::loadEvent<BaseEventT>(basicEventJson(matrixType, content), + matrixType); } template <typename EventT> struct FromJson<event_ptr_tt<EventT>> |