summary refs log tree commit diff
path: root/include/events
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-12-04 18:41:19 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-12-04 18:41:19 +0200
commita605e4486f4b9d90d668d6d1844ba5f0d58bbc26 (patch)
treec82001904cb120d975361edb38a62b5b77fa0644 /include/events
parentRun tests only with gcc (diff)
downloadnheko-a605e4486f4b9d90d668d6d1844ba5f0d58bbc26.tar.xz
Migrate to matrix-structs for event and response parsing
Diffstat (limited to 'include/events')
-rw-r--r--include/events/AliasesEventContent.h42
-rw-r--r--include/events/AvatarEventContent.h46
-rw-r--r--include/events/CanonicalAliasEventContent.h48
-rw-r--r--include/events/CreateEventContent.h47
-rw-r--r--include/events/Event.h183
-rw-r--r--include/events/HistoryVisibilityEventContent.h49
-rw-r--r--include/events/JoinRulesEventContent.h61
-rw-r--r--include/events/MemberEventContent.h68
-rw-r--r--include/events/MessageEvent.h64
-rw-r--r--include/events/MessageEventContent.h74
-rw-r--r--include/events/NameEventContent.h45
-rw-r--r--include/events/PowerLevelsEventContent.h73
-rw-r--r--include/events/RoomEvent.h116
-rw-r--r--include/events/StateEvent.h88
-rw-r--r--include/events/TopicEventContent.h46
-rw-r--r--include/events/messages/Audio.h50
-rw-r--r--include/events/messages/Emote.h34
-rw-r--r--include/events/messages/File.h55
-rw-r--r--include/events/messages/Image.h54
-rw-r--r--include/events/messages/Location.h50
-rw-r--r--include/events/messages/Notice.h34
-rw-r--r--include/events/messages/Text.h34
-rw-r--r--include/events/messages/Video.h55
23 files changed, 0 insertions, 1416 deletions
diff --git a/include/events/AliasesEventContent.h b/include/events/AliasesEventContent.h
deleted file mode 100644

index 7784fad7..00000000 --- a/include/events/AliasesEventContent.h +++ /dev/null
@@ -1,42 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> -#include <QList> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -class AliasesEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QList<QString> aliases() const { return aliases_; }; - -private: - QList<QString> aliases_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/AvatarEventContent.h b/include/events/AvatarEventContent.h deleted file mode 100644
index 55284aa4..00000000 --- a/include/events/AvatarEventContent.h +++ /dev/null
@@ -1,46 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> -#include <QUrl> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -/* - * A picture that is associated with the room. - */ - -class AvatarEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QUrl url() const { return url_; }; - -private: - QUrl url_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/CanonicalAliasEventContent.h b/include/events/CanonicalAliasEventContent.h deleted file mode 100644
index 6322c001..00000000 --- a/include/events/CanonicalAliasEventContent.h +++ /dev/null
@@ -1,48 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "CanonicalAliasEventContent.h" -#include "Deserializable.h" - -namespace matrix { -namespace events { -/* - * This event is used to inform the room about which alias should be considered - * the canonical one. This could be for display purposes or as suggestion to - * users which alias to use to advertise the room. - */ - -class CanonicalAliasEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QString alias() const { return alias_; }; - -private: - QString alias_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/CreateEventContent.h b/include/events/CreateEventContent.h deleted file mode 100644
index 0a47860e..00000000 --- a/include/events/CreateEventContent.h +++ /dev/null
@@ -1,47 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -/* - * This is the first event in a room and cannot be changed. It acts as the root - * of all other events. - */ - -class CreateEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QString creator() const { return creator_; }; - -private: - // The user_id of the room creator. This is set by the homeserver. - QString creator_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/Event.h b/include/events/Event.h deleted file mode 100644
index f6620a2c..00000000 --- a/include/events/Event.h +++ /dev/null
@@ -1,183 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QDebug> -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -enum class EventType -{ - /// m.room.aliases - RoomAliases, - /// m.room.avatar - RoomAvatar, - /// m.room.canonical_alias - RoomCanonicalAlias, - /// m.room.create - RoomCreate, - /// m.room.history_visibility - RoomHistoryVisibility, - /// m.room.join_rules - RoomJoinRules, - /// m.room.member - RoomMember, - /// m.room.message - RoomMessage, - /// m.room.name - RoomName, - /// m.room.power_levels - RoomPowerLevels, - /// m.room.topic - RoomTopic, - // Unsupported event - Unsupported, -}; - -EventType -extractEventType(const QJsonObject &data); - -bool -isMessageEvent(EventType type); -bool -isStateEvent(EventType type); - -class UnsignedData - : public Deserializable - , public Serializable -{ -public: - double age() const { return age_; } - QString transactionId() const { return transaction_id_; } - - bool isEmpty() const { return age_ <= 0 && transaction_id_.isEmpty(); } - - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - -private: - double age_ = 0; - QString transaction_id_; -}; - -template<class Content> -class Event - : public Deserializable - , public Serializable -{ -public: - Content content() const; - EventType eventType() const; - UnsignedData unsignedData() const { return unsignedData_; } - - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - -private: - Content content_; - EventType type_; - UnsignedData unsignedData_; -}; - -template<class Content> -inline Content -Event<Content>::content() const -{ - return content_; -} - -template<class Content> -inline EventType -Event<Content>::eventType() const -{ - return type_; -} - -template<class Content> -void -Event<Content>::deserialize(const QJsonValue &data) -{ - if (!data.isObject()) - throw DeserializationException("Event is not a JSON object"); - - auto object = data.toObject(); - - content_.deserialize(object.value("content")); - type_ = extractEventType(object); - - if (object.contains("unsigned")) - unsignedData_.deserialize(object.value("unsigned")); -} - -template<class Content> -QJsonObject -Event<Content>::serialize() const -{ - QJsonObject object; - - switch (type_) { - case EventType::RoomAliases: - object["type"] = "m.room.aliases"; - break; - case EventType::RoomAvatar: - object["type"] = "m.room.avatar"; - break; - case EventType::RoomCanonicalAlias: - object["type"] = "m.room.canonical_alias"; - break; - case EventType::RoomCreate: - object["type"] = "m.room.create"; - break; - case EventType::RoomHistoryVisibility: - object["type"] = "m.room.history_visibility"; - break; - case EventType::RoomJoinRules: - object["type"] = "m.room.join_rules"; - break; - case EventType::RoomMember: - object["type"] = "m.room.member"; - break; - case EventType::RoomMessage: - object["type"] = "m.room.message"; - break; - case EventType::RoomName: - object["type"] = "m.room.name"; - break; - case EventType::RoomPowerLevels: - object["type"] = "m.room.power_levels"; - break; - case EventType::RoomTopic: - object["type"] = "m.room.topic"; - break; - case EventType::Unsupported: - qWarning() << "Unsupported type to serialize"; - break; - } - - object["content"] = content_.serialize(); - - if (!unsignedData_.isEmpty()) - object["unsigned"] = unsignedData_.serialize(); - - return object; -} -} // namespace events -} // namespace matrix diff --git a/include/events/HistoryVisibilityEventContent.h b/include/events/HistoryVisibilityEventContent.h deleted file mode 100644
index 1c39ae03..00000000 --- a/include/events/HistoryVisibilityEventContent.h +++ /dev/null
@@ -1,49 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -enum class HistoryVisibility -{ - Invited, - Joined, - Shared, - WorldReadable, -}; - -class HistoryVisibilityEventContent - : public Deserializable - , public Serializable -{ -public: - HistoryVisibility historyVisibility() const { return history_visibility_; }; - - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - -private: - HistoryVisibility history_visibility_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/JoinRulesEventContent.h b/include/events/JoinRulesEventContent.h deleted file mode 100644
index 4ed9e65f..00000000 --- a/include/events/JoinRulesEventContent.h +++ /dev/null
@@ -1,61 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -enum class JoinRule -{ - // A user who wishes to join the room must first receive - // an invite to the room from someone already inside of the room. - Invite, - - // Reserved but not yet implemented by the Matrix specification. - Knock, - - // Reserved but not yet implemented by the Matrix specification. - Private, - - /// Anyone can join the room without any prior action. - Public, -}; - -/* - * Describes how users are allowed to join the room. - */ - -class JoinRulesEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - JoinRule joinRule() const { return join_rule_; }; - -private: - JoinRule join_rule_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/MemberEventContent.h b/include/events/MemberEventContent.h deleted file mode 100644
index 8b7b1576..00000000 --- a/include/events/MemberEventContent.h +++ /dev/null
@@ -1,68 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> -#include <QUrl> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -enum class Membership -{ - // The user is banned. - Ban, - - // The user has been invited. - Invite, - - // The user has joined. - Join, - - // The user has requested to join. - Knock, - - // The user has left. - Leave, -}; - -/* - * The current membership state of a user in the room. - */ - -class MemberEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QUrl avatarUrl() const { return avatar_url_; }; - QString displayName() const { return display_name_; }; - Membership membershipState() const { return membership_state_; }; - -private: - QUrl avatar_url_; - QString display_name_; - Membership membership_state_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/MessageEvent.h b/include/events/MessageEvent.h deleted file mode 100644
index 08cd926f..00000000 --- a/include/events/MessageEvent.h +++ /dev/null
@@ -1,64 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include "MessageEventContent.h" -#include "RoomEvent.h" - -namespace matrix { -namespace events { -template<class MsgContent> -class MessageEvent : public RoomEvent<MessageEventContent> -{ -public: - MsgContent msgContent() const; - - void deserialize(const QJsonValue &data) override; - -private: - MsgContent msg_content_; -}; - -template<class MsgContent> -inline MsgContent -MessageEvent<MsgContent>::msgContent() const -{ - return msg_content_; -} - -template<class MsgContent> -void -MessageEvent<MsgContent>::deserialize(const QJsonValue &data) -{ - RoomEvent<MessageEventContent>::deserialize(data); - - msg_content_.deserialize(data.toObject().value("content").toObject()); -} - -namespace messages { -struct ThumbnailInfo -{ - int h; - int w; - int size = 0; - - QString mimetype; -}; -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/MessageEventContent.h b/include/events/MessageEventContent.h deleted file mode 100644
index aa08c066..00000000 --- a/include/events/MessageEventContent.h +++ /dev/null
@@ -1,74 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -enum class MessageEventType -{ - // m.audio - Audio, - - // m.emote - Emote, - - // m.file - File, - - // m.image - Image, - - // m.location - Location, - - // m.notice - Notice, - - // m.text - Text, - - // m.video - Video, - - // Unrecognized message type - Unknown, -}; - -MessageEventType -extractMessageEventType(const QJsonObject &data); - -class MessageEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QString body() const { return body_; }; - -private: - QString body_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/NameEventContent.h b/include/events/NameEventContent.h deleted file mode 100644
index 378f689d..00000000 --- a/include/events/NameEventContent.h +++ /dev/null
@@ -1,45 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -/* - * A human-friendly room name designed to be displayed to the end-user. - */ - -class NameEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QString name() const { return name_; }; - -private: - QString name_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/PowerLevelsEventContent.h b/include/events/PowerLevelsEventContent.h deleted file mode 100644
index 63998871..00000000 --- a/include/events/PowerLevelsEventContent.h +++ /dev/null
@@ -1,73 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> -#include <QMap> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -enum class PowerLevels -{ - User = 0, - Moderator = 50, - Admin = 100, -}; - -/* - * Defines the power levels (privileges) of users in the room. - */ - -class PowerLevelsEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - int banLevel() const { return ban_; }; - int inviteLevel() const { return invite_; }; - int kickLevel() const { return kick_; }; - int redactLevel() const { return redact_; }; - - int eventsDefaultLevel() const { return events_default_; }; - int stateDefaultLevel() const { return state_default_; }; - int usersDefaultLevel() const { return users_default_; }; - - int eventLevel(QString event_type) const; - int userLevel(QString user_id) const; - -private: - int ban_ = static_cast<int>(PowerLevels::Moderator); - int invite_ = static_cast<int>(PowerLevels::Moderator); - int kick_ = static_cast<int>(PowerLevels::Moderator); - int redact_ = static_cast<int>(PowerLevels::Moderator); - - int events_default_ = static_cast<int>(PowerLevels::User); - int state_default_ = static_cast<int>(PowerLevels::Moderator); - int users_default_ = static_cast<int>(PowerLevels::User); - - QMap<QString, int> events_; - QMap<QString, int> users_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/RoomEvent.h b/include/events/RoomEvent.h deleted file mode 100644
index d80951c7..00000000 --- a/include/events/RoomEvent.h +++ /dev/null
@@ -1,116 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> -#include <QString> - -#include "Event.h" - -namespace matrix { -namespace events { -template<class Content> -class RoomEvent : public Event<Content> -{ -public: - QString eventId() const; - QString roomId() const; - QString sender() const; - uint64_t timestamp() const; - - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - -private: - QString event_id_; - QString room_id_; - QString sender_; - - uint64_t origin_server_ts_; -}; - -template<class Content> -inline QString -RoomEvent<Content>::eventId() const -{ - return event_id_; -} - -template<class Content> -inline QString -RoomEvent<Content>::roomId() const -{ - return room_id_; -} - -template<class Content> -inline QString -RoomEvent<Content>::sender() const -{ - return sender_; -} - -template<class Content> -inline uint64_t -RoomEvent<Content>::timestamp() const -{ - return origin_server_ts_; -} - -template<class Content> -void -RoomEvent<Content>::deserialize(const QJsonValue &data) -{ - Event<Content>::deserialize(data); - - auto object = data.toObject(); - - if (!object.contains("event_id")) - throw DeserializationException("event_id key is missing"); - - if (!object.contains("origin_server_ts")) - throw DeserializationException("origin_server_ts key is missing"); - - // FIXME: Synapse doesn't include room id?! - /* if (!object.contains("room_id")) */ - /* throw DeserializationException("room_id key is missing"); */ - - if (!object.contains("sender")) - throw DeserializationException("sender key is missing"); - - event_id_ = object.value("event_id").toString(); - room_id_ = object.value("room_id").toString(); - sender_ = object.value("sender").toString(); - origin_server_ts_ = object.value("origin_server_ts").toDouble(); -} - -template<class Content> -QJsonObject -RoomEvent<Content>::serialize() const -{ - QJsonObject object = Event<Content>::serialize(); - - object["event_id"] = event_id_; - object["room_id"] = room_id_; - object["sender"] = sender_; - object["origin_server_ts"] = QJsonValue(static_cast<qint64>(origin_server_ts_)); - - return object; -} -} // namespace events -} // namespace matrix diff --git a/include/events/StateEvent.h b/include/events/StateEvent.h deleted file mode 100644
index 19342a48..00000000 --- a/include/events/StateEvent.h +++ /dev/null
@@ -1,88 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "RoomEvent.h" - -namespace matrix { -namespace events { -template<class Content> -class StateEvent : public RoomEvent<Content> -{ -public: - QString stateKey() const; - Content previousContent() const; - - void deserialize(const QJsonValue &data); - QJsonObject serialize() const; - -private: - QString state_key_; - Content prev_content_; -}; - -template<class Content> -inline QString -StateEvent<Content>::stateKey() const -{ - return state_key_; -} - -template<class Content> -inline Content -StateEvent<Content>::previousContent() const -{ - return prev_content_; -} - -template<class Content> -void -StateEvent<Content>::deserialize(const QJsonValue &data) -{ - RoomEvent<Content>::deserialize(data); - - auto object = data.toObject(); - - if (!object.contains("state_key")) - throw DeserializationException("state_key key is missing"); - - state_key_ = object.value("state_key").toString(); - - if (object.contains("prev_content")) - prev_content_.deserialize(object.value("prev_content")); -} - -template<class Content> -QJsonObject -StateEvent<Content>::serialize() const -{ - QJsonObject object = RoomEvent<Content>::serialize(); - - object["state_key"] = state_key_; - - auto prev = prev_content_.serialize(); - - if (!prev.isEmpty()) - object["prev_content"] = prev; - - return object; -} -} // namespace events -} // namespace matrix diff --git a/include/events/TopicEventContent.h b/include/events/TopicEventContent.h deleted file mode 100644
index 67e21208..00000000 --- a/include/events/TopicEventContent.h +++ /dev/null
@@ -1,46 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonValue> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -/* - * A topic is a short message detailing what is currently being discussed in the - * room. - */ - -class TopicEventContent - : public Deserializable - , public Serializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonObject serialize() const override; - - QString topic() const { return topic_; }; - -private: - QString topic_; -}; - -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Audio.h b/include/events/messages/Audio.h deleted file mode 100644
index b5666d90..00000000 --- a/include/events/messages/Audio.h +++ /dev/null
@@ -1,50 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -namespace messages { -struct AudioInfo -{ - uint64_t duration; - int size = 0; - - QString mimetype; -}; - -class Audio : public Deserializable -{ -public: - QString url() const { return url_; }; - AudioInfo info() const { return info_; }; - - void deserialize(const QJsonObject &object) override; - -private: - QString url_; - AudioInfo info_; -}; - -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Emote.h b/include/events/messages/Emote.h deleted file mode 100644
index a11b7c8d..00000000 --- a/include/events/messages/Emote.h +++ /dev/null
@@ -1,34 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -namespace messages { -class Emote : public Deserializable -{ -public: - void deserialize(const QJsonObject &obj) override; -}; -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/File.h b/include/events/messages/File.h deleted file mode 100644
index 9064a556..00000000 --- a/include/events/messages/File.h +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" -#include "MessageEvent.h" - -namespace matrix { -namespace events { -namespace messages { -struct FileInfo -{ - int size = 0; - - QString mimetype; - QString thumbnail_url; - ThumbnailInfo thumbnail_info; -}; - -class File : public Deserializable -{ -public: - QString url() const { return url_; }; - QString filename() const { return filename_; }; - FileInfo info() const { return info_; }; - - void deserialize(const QJsonObject &object) override; - -private: - QString url_; - QString filename_; - - FileInfo info_; -}; - -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Image.h b/include/events/messages/Image.h deleted file mode 100644
index 03c7a368..00000000 --- a/include/events/messages/Image.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" -#include "MessageEvent.h" - -namespace matrix { -namespace events { -namespace messages { -struct ImageInfo -{ - int h; - int w; - int size = 0; - - QString mimetype; - QString thumbnail_url; - ThumbnailInfo thumbnail_info; -}; - -class Image : public Deserializable -{ -public: - QString url() const { return url_; }; - ImageInfo info() const { return info_; }; - - void deserialize(const QJsonObject &object) override; - -private: - QString url_; - ImageInfo info_; -}; - -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Location.h b/include/events/messages/Location.h deleted file mode 100644
index 27722b37..00000000 --- a/include/events/messages/Location.h +++ /dev/null
@@ -1,50 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" -#include "MessageEvent.h" - -namespace matrix { -namespace events { -namespace messages { -struct LocationInfo -{ - QString thumbnail_url; - ThumbnailInfo thumbnail_info; -}; - -class Location : public Deserializable -{ -public: - QString geoUri() const { return geo_uri_; }; - LocationInfo info() const { return info_; }; - - void deserialize(const QJsonObject &object) override; - -private: - QString geo_uri_; - - LocationInfo info_; -}; - -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Notice.h b/include/events/messages/Notice.h deleted file mode 100644
index 66f4386d..00000000 --- a/include/events/messages/Notice.h +++ /dev/null
@@ -1,34 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -namespace messages { -class Notice : public Deserializable -{ -public: - void deserialize(const QJsonObject &obj) override; -}; -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Text.h b/include/events/messages/Text.h deleted file mode 100644
index c3182dc5..00000000 --- a/include/events/messages/Text.h +++ /dev/null
@@ -1,34 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" - -namespace matrix { -namespace events { -namespace messages { -class Text : public Deserializable -{ -public: - void deserialize(const QJsonObject &obj) override; -}; -} // namespace messages -} // namespace events -} // namespace matrix diff --git a/include/events/messages/Video.h b/include/events/messages/Video.h deleted file mode 100644
index 6aeaf4d5..00000000 --- a/include/events/messages/Video.h +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * 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/>. - */ - -#pragma once - -#include <QJsonObject> - -#include "Deserializable.h" -#include "MessageEvent.h" - -namespace matrix { -namespace events { -namespace messages { -struct VideoInfo -{ - int h; - int w; - int size = 0; - int duration; - - QString mimetype; - QString thumbnail_url; - ThumbnailInfo thumbnail_info; -}; - -class Video : public Deserializable -{ -public: - QString url() const { return url_; }; - VideoInfo info() const { return info_; }; - - void deserialize(const QJsonObject &object) override; - -private: - QString url_; - VideoInfo info_; -}; - -} // namespace messages -} // namespace events -} // namespace matrix