diff options
Diffstat (limited to 'events/event.cpp')
-rw-r--r-- | events/event.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/events/event.cpp b/events/event.cpp index c7a94e9e..95084ddb 100644 --- a/events/event.cpp +++ b/events/event.cpp @@ -90,27 +90,19 @@ Event* make(const QJsonObject& obj) Event* Event::fromJson(const QJsonObject& obj) { - struct Factory { - QString type; - Event* (*make)(const QJsonObject& obj); - }; - const Factory evTypes[] { - { "m.room.message", make<RoomMessageEvent> }, - { "m.room.name", make<RoomNameEvent> }, - { "m.room.aliases", make<RoomAliasesEvent> }, - { "m.room.canonical_alias", make<RoomCanonicalAliasEvent> }, - { "m.room.member", make<RoomMemberEvent> }, - { "m.room.topic", make<RoomTopicEvent> }, - { "m.typing", make<TypingEvent> }, - { "m.receipt", make<ReceiptEvent> }, - // Insert new types before this line - }; - for (auto e: evTypes) - { - if (obj["type"].toString() == e.type) - return e.make(obj); - } - return UnknownEvent::fromJson(obj); + auto delegate = lookup(obj.value("type").toString(), + "m.room.message", make<RoomMessageEvent>, + "m.room.name", make<RoomNameEvent>, + "m.room.aliases", make<RoomAliasesEvent>, + "m.room.canonical_alias", make<RoomCanonicalAliasEvent>, + "m.room.member", make<RoomMemberEvent>, + "m.room.topic", make<RoomTopicEvent>, + "m.typing", make<TypingEvent>, + "m.receipt", make<ReceiptEvent>, + /* Insert new event types BEFORE this line */ + make<UnknownEvent> + ); + return delegate(obj); } bool Event::parseJson(const QJsonObject& obj) |