aboutsummaryrefslogtreecommitdiff
path: root/events/event.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-09-07 08:14:29 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-09-07 08:14:29 +0900
commit573e0e478c4a904ba69e6b523dead41eb28121c1 (patch)
tree6fc1008c9d2dc50a7acd21c601ac06aff1365f2e /events/event.cpp
parentae0b65440834a76f3ce6c266ee4b7d683b215842 (diff)
downloadlibquotient-573e0e478c4a904ba69e6b523dead41eb28121c1.tar.gz
libquotient-573e0e478c4a904ba69e6b523dead41eb28121c1.zip
Temporarily revert "Event::fromJson(): made the code more compact" as it breaks highlighting
This reverts commit 0fe83d59d76cd8f9c8f92d40cc58d9f5b082a84a.
Diffstat (limited to 'events/event.cpp')
-rw-r--r--events/event.cpp55
1 files changed, 31 insertions, 24 deletions
diff --git a/events/event.cpp b/events/event.cpp
index 11ed1cc9..0c7700ee 100644
--- a/events/event.cpp
+++ b/events/event.cpp
@@ -82,33 +82,40 @@ QString Event::originalJson() const
return d->originalJson;
}
-template <typename T>
-Event* make(const QJsonObject& obj)
-{
- return T::fromJson(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.room.typing", make<TypingEvent> },
- { "m.room.receipt", make<ReceiptEvent> },
- // Insert new types before this line
- };
- for (auto e: evTypes)
+ //qDebug() << obj.value("type").toString();
+ if( obj.value("type").toString() == "m.room.message" )
+ {
+ return RoomMessageEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.room.name" )
+ {
+ return RoomNameEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.room.aliases" )
+ {
+ return RoomAliasesEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.room.canonical_alias" )
+ {
+ return RoomCanonicalAliasEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.room.member" )
+ {
+ return RoomMemberEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.room.topic" )
+ {
+ return RoomTopicEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.typing" )
+ {
+ return TypingEvent::fromJson(obj);
+ }
+ if( obj.value("type").toString() == "m.receipt" )
{
- if (obj["type"].toString() == e.type)
- return e.make(obj);
+ return ReceiptEvent::fromJson(obj);
}
return UnknownEvent::fromJson(obj);
}