From a605e4486f4b9d90d668d6d1844ba5f0d58bbc26 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 4 Dec 2017 18:41:19 +0200 Subject: Migrate to matrix-structs for event and response parsing --- include/ChatPage.h | 71 +++++++--- include/MatrixClient.h | 15 +- include/RoomState.h | 96 ++++++++----- include/Sync.h | 131 ------------------ include/TextInputWidget.h | 3 - include/events/AliasesEventContent.h | 42 ------ include/events/AvatarEventContent.h | 46 ------- include/events/CanonicalAliasEventContent.h | 48 ------- include/events/CreateEventContent.h | 47 ------- include/events/Event.h | 183 ------------------------- include/events/HistoryVisibilityEventContent.h | 49 ------- include/events/JoinRulesEventContent.h | 61 --------- include/events/MemberEventContent.h | 68 --------- include/events/MessageEvent.h | 64 --------- include/events/MessageEventContent.h | 74 ---------- include/events/NameEventContent.h | 45 ------ include/events/PowerLevelsEventContent.h | 73 ---------- include/events/RoomEvent.h | 116 ---------------- include/events/StateEvent.h | 88 ------------ include/events/TopicEventContent.h | 46 ------- include/events/messages/Audio.h | 50 ------- include/events/messages/Emote.h | 34 ----- include/events/messages/File.h | 55 -------- include/events/messages/Image.h | 54 -------- include/events/messages/Location.h | 50 ------- include/events/messages/Notice.h | 34 ----- include/events/messages/Text.h | 34 ----- include/events/messages/Video.h | 55 -------- include/timeline/TimelineItem.h | 43 +++--- include/timeline/TimelineView.h | 86 +++++------- include/timeline/TimelineViewManager.h | 10 +- include/timeline/widgets/AudioItem.h | 9 +- include/timeline/widgets/FileItem.h | 11 +- include/timeline/widgets/ImageItem.h | 11 +- include/timeline/widgets/VideoItem.h | 9 +- 35 files changed, 189 insertions(+), 1722 deletions(-) delete mode 100644 include/Sync.h delete mode 100644 include/events/AliasesEventContent.h delete mode 100644 include/events/AvatarEventContent.h delete mode 100644 include/events/CanonicalAliasEventContent.h delete mode 100644 include/events/CreateEventContent.h delete mode 100644 include/events/Event.h delete mode 100644 include/events/HistoryVisibilityEventContent.h delete mode 100644 include/events/JoinRulesEventContent.h delete mode 100644 include/events/MemberEventContent.h delete mode 100644 include/events/MessageEvent.h delete mode 100644 include/events/MessageEventContent.h delete mode 100644 include/events/NameEventContent.h delete mode 100644 include/events/PowerLevelsEventContent.h delete mode 100644 include/events/RoomEvent.h delete mode 100644 include/events/StateEvent.h delete mode 100644 include/events/TopicEventContent.h delete mode 100644 include/events/messages/Audio.h delete mode 100644 include/events/messages/Emote.h delete mode 100644 include/events/messages/File.h delete mode 100644 include/events/messages/Image.h delete mode 100644 include/events/messages/Location.h delete mode 100644 include/events/messages/Notice.h delete mode 100644 include/events/messages/Text.h delete mode 100644 include/events/messages/Video.h (limited to 'include') diff --git a/include/ChatPage.h b/include/ChatPage.h index 01f6c5d7..94c54f0b 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -24,9 +24,7 @@ #include #include -#include "MemberEventContent.h" -#include "MessageEvent.h" -#include "StateEvent.h" +#include class Cache; class MatrixClient; @@ -37,14 +35,11 @@ class RoomSettings; class RoomState; class SideBarActions; class Splitter; -class SyncResponse; class TextInputWidget; class TimelineViewManager; class TopRoomBar; class TypingDisplay; class UserInfoWidget; -class JoinedRoom; -class LeftRoom; constexpr int CONSENSUS_TIMEOUT = 1000; constexpr int SHOW_CONTENT_TIMEOUT = 3000; @@ -76,8 +71,8 @@ private slots: void updateTopBarAvatar(const QString &roomid, const QPixmap &img); void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name); void setOwnAvatar(const QPixmap &img); - void initialSyncCompleted(const SyncResponse &response); - void syncCompleted(const SyncResponse &response); + void initialSyncCompleted(const mtx::responses::Sync &response); + void syncCompleted(const mtx::responses::Sync &response); void syncFailed(const QString &msg); void changeTopRoomInfo(const QString &room_id); void logout(); @@ -87,26 +82,34 @@ private slots: private: using UserID = QString; using RoomStates = QMap; - using JoinedRooms = QMap; - using LeftRooms = QMap; - using Membership = matrix::events::StateEvent; - using Memberships = QMap; + using Membership = mtx::events::StateEvent; + using Memberships = std::map; + + using JoinedRooms = std::map; + using LeftRooms = std::map; void removeLeftRooms(const LeftRooms &rooms); void updateJoinedRooms(const JoinedRooms &rooms); - Memberships getMemberships(const QJsonArray &events) const; RoomStates generateMembershipDifference(const JoinedRooms &rooms, const RoomStates &states) const; - void updateTypingUsers(const QString &roomid, const QList &user_ids); - void updateUserMetadata(const QJsonArray &events); - void updateUserDisplayName(const Membership &event); - void updateUserAvatarUrl(const Membership &event); + void updateTypingUsers(const QString &roomid, const std::vector &user_ids); + + using MemberEvent = mtx::events::StateEvent; + void updateUserDisplayName(const MemberEvent &event); + void updateUserAvatarUrl(const MemberEvent &event); + void loadStateFromCache(); void deleteConfigs(); void resetUI(); + template + Memberships getMemberships(const std::vector &events) const; + + template + void updateUserMetadata(const std::vector &collection); + QHBoxLayout *topLayout_; Splitter *splitter; @@ -153,3 +156,37 @@ private: // return to the login page. int initialSyncFailures = 0; }; + +template +void +ChatPage::updateUserMetadata(const std::vector &collection) +{ + using Member = mtx::events::StateEvent; + + for (auto &event : collection) { + if (mpark::holds_alternative(event)) { + auto member = mpark::get(event); + + updateUserAvatarUrl(member); + updateUserDisplayName(member); + } + } +} + +template +std::map> +ChatPage::getMemberships(const std::vector &collection) const +{ + std::map> memberships; + + using Member = mtx::events::StateEvent; + + for (auto &event : collection) { + if (mpark::holds_alternative(event)) { + auto member = mpark::get(event); + memberships.emplace(member.state_key, member); + } + } + + return memberships; +} diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 722a8611..397ba11d 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -20,12 +20,7 @@ #include #include #include - -#include "MessageEvent.h" - -class SyncResponse; -class Profile; -class RoomMessages; +#include /* * MatrixClient provides the high level API to communicate with @@ -40,7 +35,7 @@ public: // Client API. void initialSync() noexcept; void sync() noexcept; - void sendRoomMessage(matrix::events::MessageEventType ty, + void sendRoomMessage(mtx::events::MessageType ty, int txnId, const QString &roomid, const QString &msg, @@ -107,15 +102,15 @@ signals: // Returned profile data for the user's account. void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name); - void initialSyncCompleted(const SyncResponse &response); + void initialSyncCompleted(const mtx::responses::Sync &response); void initialSyncFailed(const QString &msg); - void syncCompleted(const SyncResponse &response); + void syncCompleted(const mtx::responses::Sync &response); void syncFailed(const QString &msg); void joinFailed(const QString &msg); void messageSent(const QString &event_id, const QString &roomid, const int txn_id); void messageSendFailed(const QString &roomid, const int txn_id); void emoteSent(const QString &event_id, const QString &roomid, const int txn_id); - void messagesRetrieved(const QString &room_id, const RoomMessages &msgs); + void messagesRetrieved(const QString &room_id, const mtx::responses::Messages &msgs); void joinedRoom(const QString &room_id); void leftRoom(const QString &room_id); diff --git a/include/RoomState.h b/include/RoomState.h index db1cdc68..0e91410c 100644 --- a/include/RoomState.h +++ b/include/RoomState.h @@ -21,28 +21,14 @@ #include #include -#include "AliasesEventContent.h" -#include "AvatarEventContent.h" -#include "CanonicalAliasEventContent.h" -#include "CreateEventContent.h" -#include "HistoryVisibilityEventContent.h" -#include "JoinRulesEventContent.h" -#include "MemberEventContent.h" -#include "NameEventContent.h" -#include "PowerLevelsEventContent.h" -#include "TopicEventContent.h" - -#include "Event.h" -#include "RoomEvent.h" -#include "StateEvent.h" - -namespace events = matrix::events; +#include class RoomState { public: RoomState(); - RoomState(const QJsonArray &events); + RoomState(const mtx::responses::Timeline &timeline); + RoomState(const mtx::responses::State &state); // Calculate room data that are not immediatly accessible. Like room name and // avatar. @@ -50,32 +36,37 @@ public: // e.g If the room is 1-on-1 name and avatar should be extracted from a user. void resolveName(); void resolveAvatar(); - void parse(const QJsonObject &object); + void parse(const nlohmann::json &object); QUrl getAvatar() const { return avatar_; }; QString getName() const { return name_; }; - QString getTopic() const { return topic.content().topic().simplified(); }; + QString getTopic() const + { + return QString::fromStdString(topic.content.topic).simplified(); + }; void removeLeaveMemberships(); void update(const RoomState &state); - void updateFromEvents(const QJsonArray &events); - QJsonObject serialize() const; + template + void updateFromEvents(const std::vector &collection); + + std::string serialize() const; // The latest state events. - events::StateEvent aliases; - events::StateEvent avatar; - events::StateEvent canonical_alias; - events::StateEvent create; - events::StateEvent history_visibility; - events::StateEvent join_rules; - events::StateEvent name; - events::StateEvent power_levels; - events::StateEvent topic; + mtx::events::StateEvent aliases; + mtx::events::StateEvent avatar; + mtx::events::StateEvent canonical_alias; + mtx::events::StateEvent create; + mtx::events::StateEvent history_visibility; + mtx::events::StateEvent join_rules; + mtx::events::StateEvent name; + mtx::events::StateEvent power_levels; + mtx::events::StateEvent topic; // Contains the m.room.member events for all the joined users. - using UserID = QString; - QMap> memberships; + using UserID = std::string; + std::map> memberships; private: QUrl avatar_; @@ -85,3 +76,44 @@ private: // avatar event this should be empty. QString userAvatar_; }; + +template +void +RoomState::updateFromEvents(const std::vector &collection) +{ + using Aliases = mtx::events::StateEvent; + using Avatar = mtx::events::StateEvent; + using CanonicalAlias = mtx::events::StateEvent; + using Create = mtx::events::StateEvent; + using HistoryVisibility = mtx::events::StateEvent; + using JoinRules = mtx::events::StateEvent; + using Member = mtx::events::StateEvent; + using Name = mtx::events::StateEvent; + using PowerLevels = mtx::events::StateEvent; + using Topic = mtx::events::StateEvent; + + for (const auto &event : collection) { + if (mpark::holds_alternative(event)) { + this->aliases = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->avatar = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->canonical_alias = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->create = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->history_visibility = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->join_rules = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->name = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + auto membership = mpark::get(event); + this->memberships.emplace(membership.state_key, membership); + } else if (mpark::holds_alternative(event)) { + this->power_levels = mpark::get(event); + } else if (mpark::holds_alternative(event)) { + this->topic = mpark::get(event); + } + } +} diff --git a/include/Sync.h b/include/Sync.h deleted file mode 100644 index d59a57dc..00000000 --- a/include/Sync.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 . - */ - -#pragma once - -#include -#include - -#include "Deserializable.h" - -class Event : public Deserializable -{ -public: - QJsonObject content() const { return content_; }; - QJsonObject unsigned_content() const { return unsigned_; }; - - QString sender() const { return sender_; }; - QString state_key() const { return state_key_; }; - QString type() const { return type_; }; - QString eventId() const { return event_id_; }; - - uint64_t timestamp() const { return origin_server_ts_; }; - - void deserialize(const QJsonValue &data) override; - -private: - QJsonObject content_; - QJsonObject unsigned_; - - QString sender_; - QString state_key_; - QString type_; - QString event_id_; - - uint64_t origin_server_ts_; -}; - -class State : public Deserializable -{ -public: - void deserialize(const QJsonValue &data) override; - QJsonArray events() const { return events_; }; - -private: - QJsonArray events_; -}; - -class Timeline : public Deserializable -{ -public: - QJsonArray events() const { return events_; }; - QString previousBatch() const { return prev_batch_; }; - bool limited() const { return limited_; }; - - void deserialize(const QJsonValue &data) override; - -private: - QJsonArray events_; - QString prev_batch_; - bool limited_; -}; - -// TODO: Add support for account_data, undread_notifications -class JoinedRoom : public Deserializable -{ -public: - State state() const { return state_; }; - Timeline timeline() const { return timeline_; }; - QList typingUserIDs() const { return typingUserIDs_; }; - - void deserialize(const QJsonValue &data) override; - -private: - State state_; - Timeline timeline_; - QList typingUserIDs_; - /* AccountData account_data_; */ - /* UnreadNotifications unread_notifications_; */ -}; - -class LeftRoom : public Deserializable -{ -public: - State state() const { return state_; }; - Timeline timeline() const { return timeline_; }; - - void deserialize(const QJsonValue &data) override; - -private: - State state_; - Timeline timeline_; -}; - -// TODO: Add support for invited and left rooms. -class Rooms : public Deserializable -{ -public: - QMap join() const { return join_; }; - QMap leave() const { return leave_; }; - void deserialize(const QJsonValue &data) override; - -private: - QMap join_; - QMap leave_; -}; - -class SyncResponse : public Deserializable -{ -public: - void deserialize(const QJsonDocument &data) override; - QString nextBatch() const { return next_batch_; }; - Rooms rooms() const { return rooms_; }; - -private: - QString next_batch_; - Rooms rooms_; -}; diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h index b208d3f4..df309e27 100644 --- a/include/TextInputWidget.h +++ b/include/TextInputWidget.h @@ -25,13 +25,10 @@ #include #include "FlatButton.h" -#include "Image.h" #include "LoadingIndicator.h" #include "emoji/PickButton.h" -namespace msgs = matrix::events::messages; - class FilteredTextEdit : public QTextEdit { Q_OBJECT 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 - * - * 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 . - */ - -#pragma once - -#include -#include - -#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 aliases() const { return aliases_; }; - -private: - QList 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 - * - * 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 . - */ - -#pragma once - -#include -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include -#include - -#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 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 -inline Content -Event::content() const -{ - return content_; -} - -template -inline EventType -Event::eventType() const -{ - return type_; -} - -template -void -Event::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 -QJsonObject -Event::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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include "MessageEventContent.h" -#include "RoomEvent.h" - -namespace matrix { -namespace events { -template -class MessageEvent : public RoomEvent -{ -public: - MsgContent msgContent() const; - - void deserialize(const QJsonValue &data) override; - -private: - MsgContent msg_content_; -}; - -template -inline MsgContent -MessageEvent::msgContent() const -{ - return msg_content_; -} - -template -void -MessageEvent::deserialize(const QJsonValue &data) -{ - RoomEvent::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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include -#include - -#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(PowerLevels::Moderator); - int invite_ = static_cast(PowerLevels::Moderator); - int kick_ = static_cast(PowerLevels::Moderator); - int redact_ = static_cast(PowerLevels::Moderator); - - int events_default_ = static_cast(PowerLevels::User); - int state_default_ = static_cast(PowerLevels::Moderator); - int users_default_ = static_cast(PowerLevels::User); - - QMap events_; - QMap 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 - * - * 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 . - */ - -#pragma once - -#include -#include - -#include "Event.h" - -namespace matrix { -namespace events { -template -class RoomEvent : public Event -{ -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 -inline QString -RoomEvent::eventId() const -{ - return event_id_; -} - -template -inline QString -RoomEvent::roomId() const -{ - return room_id_; -} - -template -inline QString -RoomEvent::sender() const -{ - return sender_; -} - -template -inline uint64_t -RoomEvent::timestamp() const -{ - return origin_server_ts_; -} - -template -void -RoomEvent::deserialize(const QJsonValue &data) -{ - Event::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 -QJsonObject -RoomEvent::serialize() const -{ - QJsonObject object = Event::serialize(); - - object["event_id"] = event_id_; - object["room_id"] = room_id_; - object["sender"] = sender_; - object["origin_server_ts"] = QJsonValue(static_cast(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 - * - * 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 . - */ - -#pragma once - -#include - -#include "RoomEvent.h" - -namespace matrix { -namespace events { -template -class StateEvent : public RoomEvent -{ -public: - QString stateKey() const; - Content previousContent() const; - - void deserialize(const QJsonValue &data); - QJsonObject serialize() const; - -private: - QString state_key_; - Content prev_content_; -}; - -template -inline QString -StateEvent::stateKey() const -{ - return state_key_; -} - -template -inline Content -StateEvent::previousContent() const -{ - return prev_content_; -} - -template -void -StateEvent::deserialize(const QJsonValue &data) -{ - RoomEvent::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 -QJsonObject -StateEvent::serialize() const -{ - QJsonObject object = RoomEvent::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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 - * - * 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 . - */ - -#pragma once - -#include - -#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 diff --git a/include/timeline/TimelineItem.h b/include/timeline/TimelineItem.h index e04cbeae..17b110fc 100644 --- a/include/timeline/TimelineItem.h +++ b/include/timeline/TimelineItem.h @@ -25,16 +25,7 @@ #include #include -#include "Audio.h" -#include "Emote.h" -#include "File.h" -#include "Image.h" -#include "Notice.h" -#include "Text.h" -#include "Video.h" - #include "AvatarProvider.h" -#include "MessageEvent.h" #include "RoomInfoListItem.h" #include "TimelineViewManager.h" @@ -44,26 +35,23 @@ class VideoItem; class FileItem; class Avatar; -namespace events = matrix::events; -namespace msgs = matrix::events::messages; - class TimelineItem : public QWidget { Q_OBJECT public: - TimelineItem(const events::MessageEvent &e, + TimelineItem(const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent = 0); - TimelineItem(const events::MessageEvent &e, + TimelineItem(const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent = 0); - TimelineItem(const events::MessageEvent &e, + TimelineItem(const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent = 0); // For local messages. // m.text & m.emote - TimelineItem(events::MessageEventType ty, + TimelineItem(mtx::events::MessageType ty, const QString &userid, QString body, bool withSender, @@ -75,19 +63,19 @@ public: TimelineItem(VideoItem *item, const QString &userid, bool withSender, QWidget *parent = 0); TimelineItem(ImageItem *img, - const events::MessageEvent &e, + const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent); TimelineItem(FileItem *file, - const events::MessageEvent &e, + const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent); TimelineItem(AudioItem *audio, - const events::MessageEvent &e, + const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent); TimelineItem(VideoItem *video, - const events::MessageEvent &e, + const mtx::events::RoomEvent &e, bool with_sender, QWidget *parent); @@ -185,16 +173,17 @@ TimelineItem::setupWidgetLayout(Widget *widget, { init(); - event_id_ = event.eventId(); + event_id_ = QString::fromStdString(event.event_id); + const auto sender = QString::fromStdString(event.sender); - auto timestamp = QDateTime::fromMSecsSinceEpoch(event.timestamp()); - auto displayName = TimelineViewManager::displayName(event.sender()); + auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts); + auto displayName = TimelineViewManager::displayName(sender); QSettings settings; - descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName, - event.sender(), + descriptionMsg_ = {sender == settings.value("auth/user_id") ? "You" : displayName, + sender, msgDescription, - descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))}; + descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.origin_server_ts))}; generateTimestamp(timestamp); @@ -209,7 +198,7 @@ TimelineItem::setupWidgetLayout(Widget *widget, mainLayout_->addLayout(headerLayout_); - AvatarProvider::resolve(event.sender(), this); + AvatarProvider::resolve(sender, this); } else { setupSimpleLayout(); } diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index 5262d20d..52bf0165 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -27,39 +27,27 @@ #include #include -#include "Audio.h" -#include "Emote.h" -#include "File.h" -#include "Image.h" -#include "Notice.h" -#include "Text.h" -#include "Video.h" +#include #include "MatrixClient.h" -#include "MessageEvent.h" #include "TimelineItem.h" class FloatingButton; -class RoomMessages; class ScrollBar; -class Timeline; struct DescInfo; -namespace msgs = matrix::events::messages; -namespace events = matrix::events; - // Contains info about a message shown in the history view // but not yet confirmed by the homeserver through sync. struct PendingMessage { - matrix::events::MessageEventType ty; + mtx::events::MessageType ty; int txn_id; QString body; QString filename; QString event_id; TimelineItem *widget; - PendingMessage(matrix::events::MessageEventType ty, + PendingMessage(mtx::events::MessageType ty, int txn_id, QString body, QString filename, @@ -86,7 +74,7 @@ class TimelineView : public QWidget Q_OBJECT public: - TimelineView(const Timeline &timeline, + TimelineView(const mtx::responses::Timeline &timeline, QSharedPointer client, const QString &room_id, QWidget *parent = 0); @@ -95,10 +83,10 @@ public: QWidget *parent = 0); // Add new events at the end of the timeline. - int addEvents(const Timeline &timeline); - void addUserMessage(matrix::events::MessageEventType ty, const QString &msg); + int addEvents(const mtx::responses::Timeline &timeline); + void addUserMessage(mtx::events::MessageType ty, const QString &msg); - template + template void addUserMessage(const QString &url, const QString &filename); void updatePendingMessage(int txn_id, QString event_id); void scrollDown(); @@ -109,7 +97,7 @@ public slots: void fetchHistory(); // Add old events at the top of the timeline. - void addBackwardsEvents(const QString &room_id, const RoomMessages &msgs); + void addBackwardsEvents(const QString &room_id, const mtx::responses::Messages &msgs); // Whether or not the initial batch has been loaded. bool hasLoaded() { return scroll_layout_->count() > 1 || isTimelineFinished; } @@ -135,13 +123,14 @@ private: void notifyForLastEvent(); void readLastEvent() const; QString getLastEventId() const; + QString getEventSender(const mtx::events::collections::TimelineEvents &event) const; template - TimelineItem *processMessageEvent(const QJsonObject &event, TimelineDirection direction); + TimelineItem *processMessageEvent(const Event &event, TimelineDirection direction); // TODO: Remove this eventually. template - TimelineItem *processMessageEvent(const QJsonObject &event, TimelineDirection direction); + TimelineItem *processMessageEvent(const Event &event, TimelineDirection direction); // For events with custom display widgets. template @@ -164,7 +153,8 @@ private: void handleNewUserMessage(PendingMessage msg); // Return nullptr if the event couldn't be parsed. - TimelineItem *parseMessageEvent(const QJsonObject &event, TimelineDirection direction); + TimelineItem *parseMessageEvent(const mtx::events::collections::TimelineEvents &event, + TimelineDirection direction); QVBoxLayout *top_layout_; QVBoxLayout *scroll_layout_; @@ -207,7 +197,7 @@ private: QSharedPointer client_; }; -template +template void TimelineView::addUserMessage(const QString &url, const QString &filename) { @@ -252,62 +242,50 @@ TimelineView::createTimelineItem(const Event &event, bool withSender) template TimelineItem * -TimelineView::processMessageEvent(const QJsonObject &data, TimelineDirection direction) +TimelineView::processMessageEvent(const Event &event, TimelineDirection direction) { - Event event; - - try { - event.deserialize(data); - } catch (const DeserializationException &e) { - qWarning() << e.what() << data; - return nullptr; - } + const auto event_id = QString::fromStdString(event.event_id); + const auto sender = QString::fromStdString(event.sender); - if (isDuplicate(event.eventId())) + if (isDuplicate(event_id)) return nullptr; - eventIds_[event.eventId()] = true; + eventIds_[event_id] = true; - QString txnid = event.unsignedData().transactionId(); - if (!txnid.isEmpty() && isPendingMessage(txnid, event.sender(), local_user_)) { + const QString txnid = QString::fromStdString(event.unsigned_data.transaction_id); + if (!txnid.isEmpty() && isPendingMessage(txnid, sender, local_user_)) { removePendingMessage(txnid); return nullptr; } - auto with_sender = isSenderRendered(event.sender(), direction); + auto with_sender = isSenderRendered(sender, direction); - updateLastSender(event.sender(), direction); + updateLastSender(sender, direction); return createTimelineItem(event, with_sender); } template TimelineItem * -TimelineView::processMessageEvent(const QJsonObject &data, TimelineDirection direction) +TimelineView::processMessageEvent(const Event &event, TimelineDirection direction) { - Event event; - - try { - event.deserialize(data); - } catch (const DeserializationException &e) { - qWarning() << e.what() << data; - return nullptr; - } + const auto event_id = QString::fromStdString(event.event_id); + const auto sender = QString::fromStdString(event.sender); - if (isDuplicate(event.eventId())) + if (isDuplicate(event_id)) return nullptr; - eventIds_[event.eventId()] = true; + eventIds_[event_id] = true; - QString txnid = event.unsignedData().transactionId(); - if (!txnid.isEmpty() && isPendingMessage(txnid, event.sender(), local_user_)) { + const QString txnid = QString::fromStdString(event.unsigned_data.transaction_id); + if (!txnid.isEmpty() && isPendingMessage(txnid, sender, local_user_)) { removePendingMessage(txnid); return nullptr; } - auto with_sender = isSenderRendered(event.sender(), direction); + auto with_sender = isSenderRendered(sender, direction); - updateLastSender(event.sender(), direction); + updateLastSender(sender, direction); return createTimelineItem(event, with_sender); } diff --git a/include/timeline/TimelineViewManager.h b/include/timeline/TimelineViewManager.h index edb44ecd..2c32da16 100644 --- a/include/timeline/TimelineViewManager.h +++ b/include/timeline/TimelineViewManager.h @@ -21,12 +21,10 @@ #include #include -#include "MessageEvent.h" +#include -class JoinedRoom; class MatrixClient; class RoomInfoListItem; -class Rooms; class TimelineView; struct DescInfo; @@ -39,14 +37,14 @@ public: ~TimelineViewManager(); // Initialize with timeline events. - void initialize(const Rooms &rooms); + void initialize(const mtx::responses::Rooms &rooms); // Empty initialization. void initialize(const QList &rooms); - void addRoom(const JoinedRoom &room, const QString &room_id); + void addRoom(const mtx::responses::JoinedRoom &room, const QString &room_id); void addRoom(const QString &room_id); - void sync(const Rooms &rooms); + void sync(const mtx::responses::Rooms &rooms); void clearAll(); // Check if all the timelines have been loaded. diff --git a/include/timeline/widgets/AudioItem.h b/include/timeline/widgets/AudioItem.h index 1104996f..f8e7cc07 100644 --- a/include/timeline/widgets/AudioItem.h +++ b/include/timeline/widgets/AudioItem.h @@ -24,12 +24,9 @@ #include #include -#include "Audio.h" #include "MatrixClient.h" -#include "MessageEvent.h" -namespace events = matrix::events; -namespace msgs = matrix::events::messages; +#include class AudioItem : public QWidget { @@ -46,7 +43,7 @@ class AudioItem : public QWidget public: AudioItem(QSharedPointer client, - const events::MessageEvent &event, + const mtx::events::RoomEvent &event, QWidget *parent = nullptr); AudioItem(QSharedPointer client, @@ -94,7 +91,7 @@ private: QString readableFileSize_; QString filenameToSave_; - events::MessageEvent event_; + mtx::events::RoomEvent event_; QSharedPointer client_; QMediaPlayer *player_; diff --git a/include/timeline/widgets/FileItem.h b/include/timeline/widgets/FileItem.h index 47e81867..fd0b0249 100644 --- a/include/timeline/widgets/FileItem.h +++ b/include/timeline/widgets/FileItem.h @@ -23,12 +23,9 @@ #include #include -#include "File.h" -#include "MatrixClient.h" -#include "MessageEvent.h" +#include -namespace events = matrix::events; -namespace msgs = matrix::events::messages; +#include "MatrixClient.h" class FileItem : public QWidget { @@ -40,7 +37,7 @@ class FileItem : public QWidget public: FileItem(QSharedPointer client, - const events::MessageEvent &event, + const mtx::events::RoomEvent &event, QWidget *parent = nullptr); FileItem(QSharedPointer client, @@ -75,7 +72,7 @@ private: QString readableFileSize_; QString filenameToSave_; - events::MessageEvent event_; + mtx::events::RoomEvent event_; QSharedPointer client_; QIcon icon_; diff --git a/include/timeline/widgets/ImageItem.h b/include/timeline/widgets/ImageItem.h index c4f6998a..931c17dd 100644 --- a/include/timeline/widgets/ImageItem.h +++ b/include/timeline/widgets/ImageItem.h @@ -22,19 +22,16 @@ #include #include -#include "Image.h" -#include "MatrixClient.h" -#include "MessageEvent.h" +#include -namespace events = matrix::events; -namespace msgs = matrix::events::messages; +#include "MatrixClient.h" class ImageItem : public QWidget { Q_OBJECT public: ImageItem(QSharedPointer client, - const events::MessageEvent &event, + const mtx::events::RoomEvent &event, QWidget *parent = nullptr); ImageItem(QSharedPointer client, @@ -72,7 +69,7 @@ private: int bottom_height_ = 30; - events::MessageEvent event_; + mtx::events::RoomEvent event_; QSharedPointer client_; }; diff --git a/include/timeline/widgets/VideoItem.h b/include/timeline/widgets/VideoItem.h index aa2a5da3..88ff21ec 100644 --- a/include/timeline/widgets/VideoItem.h +++ b/include/timeline/widgets/VideoItem.h @@ -23,11 +23,8 @@ #include #include "MatrixClient.h" -#include "MessageEvent.h" -#include "Video.h" -namespace events = matrix::events; -namespace msgs = matrix::events::messages; +#include class VideoItem : public QWidget { @@ -35,7 +32,7 @@ class VideoItem : public QWidget public: VideoItem(QSharedPointer client, - const events::MessageEvent &event, + const mtx::events::RoomEvent &event, QWidget *parent = nullptr); VideoItem(QSharedPointer client, @@ -53,6 +50,6 @@ private: QLabel *label_; - events::MessageEvent event_; + mtx::events::RoomEvent event_; QSharedPointer client_; }; -- cgit 1.5.1