diff --git a/src/events/AliasesEventContent.cc b/src/events/AliasesEventContent.cc
new file mode 100644
index 00000000..ccc4f2c1
--- /dev/null
+++ b/src/events/AliasesEventContent.cc
@@ -0,0 +1,36 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QJsonArray>
+
+#include "AliasesEventContent.h"
+
+void AliasesEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("AliasesEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("aliases") == QJsonValue::Undefined)
+ throw DeserializationException("aliases key is missing");
+
+ auto aliases = object.value("aliases").toArray();
+
+ for (const auto &alias : aliases)
+ aliases_.push_back(alias.toString());
+}
diff --git a/src/events/AvatarEventContent.cc b/src/events/AvatarEventContent.cc
new file mode 100644
index 00000000..51a60a1e
--- /dev/null
+++ b/src/events/AvatarEventContent.cc
@@ -0,0 +1,36 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QDebug>
+
+#include "AvatarEventContent.h"
+
+void AvatarEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("AvatarEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("url") == QJsonValue::Undefined)
+ throw DeserializationException("url key is missing");
+
+ url_ = QUrl(object.value("url").toString());
+
+ if (!url_.isValid())
+ qWarning() << "Invalid avatar url" << url_;
+}
diff --git a/src/events/CanonicalAliasEventContent.cc b/src/events/CanonicalAliasEventContent.cc
new file mode 100644
index 00000000..23a32016
--- /dev/null
+++ b/src/events/CanonicalAliasEventContent.cc
@@ -0,0 +1,31 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CanonicalAliasEventContent.h"
+
+void CanonicalAliasEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("CanonicalAliasEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("alias") == QJsonValue::Undefined)
+ throw DeserializationException("alias key is missing");
+
+ alias_ = object.value("alias").toString();
+}
diff --git a/src/events/CreateEventContent.cc b/src/events/CreateEventContent.cc
new file mode 100644
index 00000000..e44be13e
--- /dev/null
+++ b/src/events/CreateEventContent.cc
@@ -0,0 +1,31 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CreateEventContent.h"
+
+void CreateEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("CreateEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("creator") == QJsonValue::Undefined)
+ throw DeserializationException("creator key is missing");
+
+ creator_ = object.value("creator").toString();
+}
diff --git a/src/events/HistoryVisibilityEventContent.cc b/src/events/HistoryVisibilityEventContent.cc
new file mode 100644
index 00000000..b9eb7ffc
--- /dev/null
+++ b/src/events/HistoryVisibilityEventContent.cc
@@ -0,0 +1,42 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "HistoryVisibilityEventContent.h"
+
+void HistoryVisibilityEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("HistoryVisibilityEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("history_visibility") == QJsonValue::Undefined)
+ throw DeserializationException("history_visibility key is missing");
+
+ auto value = object.value("history_visibility").toString();
+
+ if (value == "invited")
+ history_visibility_ = HistoryVisibility::Invited;
+ else if (value == "joined")
+ history_visibility_ = HistoryVisibility::Joined;
+ else if (value == "shared")
+ history_visibility_ = HistoryVisibility::Shared;
+ else if (value == "world_readable")
+ history_visibility_ = HistoryVisibility::WorldReadable;
+ else
+ throw DeserializationException(QString("Unknown history_visibility value: %1").arg(value).toUtf8().constData());
+}
diff --git a/src/events/JoinRulesEventContent.cc b/src/events/JoinRulesEventContent.cc
new file mode 100644
index 00000000..ad30a1aa
--- /dev/null
+++ b/src/events/JoinRulesEventContent.cc
@@ -0,0 +1,42 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "JoinRulesEventContent.h"
+
+void JoinRulesEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("JoinRulesEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("join_rule") == QJsonValue::Undefined)
+ throw DeserializationException("join_rule key is missing");
+
+ auto value = object.value("join_rule").toString();
+
+ if (value == "invite")
+ join_rule_ = JoinRule::Invite;
+ else if (value == "knock")
+ join_rule_ = JoinRule::Knock;
+ else if (value == "private")
+ join_rule_ = JoinRule::Private;
+ else if (value == "public")
+ join_rule_ = JoinRule::Public;
+ else
+ throw DeserializationException(QString("Unknown join_rule value: %1").arg(value).toUtf8().constData());
+}
diff --git a/src/events/MemberEventContent.cc b/src/events/MemberEventContent.cc
new file mode 100644
index 00000000..e7814e30
--- /dev/null
+++ b/src/events/MemberEventContent.cc
@@ -0,0 +1,55 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QDebug>
+
+#include "MemberEventContent.h"
+
+void MemberEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("MemberEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (!object.contains("membership"))
+ throw DeserializationException("membership key is missing");
+
+ auto value = object.value("membership").toString();
+
+ if (value == "ban")
+ membership_state_ = Membership::BanState;
+ else if (value == "invite")
+ membership_state_ = Membership::InviteState;
+ else if (value == "join")
+ membership_state_ = Membership::JoinState;
+ else if (value == "knock")
+ membership_state_ = Membership::KnockState;
+ else if (value == "leave")
+ membership_state_ = Membership::LeaveState;
+ else
+ throw DeserializationException(QString("Unknown membership value: %1").arg(value).toUtf8().constData());
+
+ if (object.contains("avatar_url"))
+ avatar_url_ = QUrl(object.value("avatar_url").toString());
+
+ if (!avatar_url_.toString().isEmpty() && !avatar_url_.isValid())
+ qWarning() << "Invalid avatar url" << avatar_url_;
+
+ if (object.contains("displayname"))
+ display_name_ = object.value("displayname").toString();
+}
diff --git a/src/events/NameEventContent.cc b/src/events/NameEventContent.cc
new file mode 100644
index 00000000..09b655a7
--- /dev/null
+++ b/src/events/NameEventContent.cc
@@ -0,0 +1,31 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "NameEventContent.h"
+
+void NameEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("NameEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("name") == QJsonValue::Undefined)
+ throw DeserializationException("name key is missing");
+
+ name_ = object.value("name").toString();
+}
diff --git a/src/events/PowerLevelsEventContent.cc b/src/events/PowerLevelsEventContent.cc
new file mode 100644
index 00000000..a6e5846a
--- /dev/null
+++ b/src/events/PowerLevelsEventContent.cc
@@ -0,0 +1,80 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QJsonObject>
+
+#include "Deserializable.h"
+#include "PowerLevelsEventContent.h"
+
+void PowerLevelsEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("PowerLevelsEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("ban") != QJsonValue::Undefined)
+ ban_ = object.value("ban").toInt();
+
+ if (object.value("invite") != QJsonValue::Undefined)
+ invite_ = object.value("invite").toInt();
+
+ if (object.value("kick") != QJsonValue::Undefined)
+ kick_ = object.value("kick").toInt();
+
+ if (object.value("redact") != QJsonValue::Undefined)
+ redact_ = object.value("redact").toInt();
+
+ if (object.value("events_default") != QJsonValue::Undefined)
+ events_default_ = object.value("events_default").toInt();
+
+ if (object.value("state_default") != QJsonValue::Undefined)
+ state_default_ = object.value("state_default").toInt();
+
+ if (object.value("users_default") != QJsonValue::Undefined)
+ users_default_ = object.value("users_default").toInt();
+
+ if (object.value("users").isObject()) {
+ auto users = object.value("users").toObject();
+
+ for (auto it = users.constBegin(); it != users.constEnd(); it++)
+ users_.insert(it.key(), it.value().toInt());
+ }
+
+ if (object.value("events").isObject()) {
+ auto events = object.value("events").toObject();
+
+ for (auto it = events.constBegin(); it != events.constEnd(); it++)
+ events_.insert(it.key(), it.value().toInt());
+ }
+}
+
+int PowerLevelsEventContent::eventLevel(QString event_type) const
+{
+ if (events_.contains(event_type))
+ return events_[event_type];
+
+ return events_default_;
+}
+
+int PowerLevelsEventContent::userLevel(QString userid) const
+{
+ if (users_.contains(userid))
+ return users_[userid];
+
+ return users_default_;
+}
diff --git a/src/events/TopicEventContent.cc b/src/events/TopicEventContent.cc
new file mode 100644
index 00000000..1abda151
--- /dev/null
+++ b/src/events/TopicEventContent.cc
@@ -0,0 +1,31 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "TopicEventContent.h"
+
+void TopicEventContent::deserialize(const QJsonValue &data)
+{
+ if (!data.isObject())
+ throw DeserializationException("TopicEventContent is not a JSON object");
+
+ auto object = data.toObject();
+
+ if (object.value("topic") == QJsonValue::Undefined)
+ throw DeserializationException("topic key is missing");
+
+ topic_ = object.value("topic").toString();
+}
|