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 --- .ci/linux/gtest.sh | 19 - .ci/linux/run-tests.sh | 7 - .travis.yml | 3 - CMakeLists.txt | 58 +- Makefile | 9 +- 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 +- libs/matrix-structs | 2 +- src/Cache.cc | 65 +-- src/ChatPage.cc | 280 ++++------ src/MatrixClient.cc | 56 +- src/RoomList.cc | 1 - src/RoomState.cc | 316 ++++------- src/Sync.cc | 307 ----------- src/events/AliasesEventContent.cc | 55 -- src/events/AvatarEventContent.cc | 50 -- src/events/CanonicalAliasEventContent.cc | 45 -- src/events/CreateEventContent.cc | 45 -- src/events/Event.cc | 106 ---- src/events/HistoryVisibilityEventContent.cc | 64 --- src/events/JoinRulesEventContent.cc | 63 --- src/events/MemberEventContent.cc | 84 --- src/events/MessageEventContent.cc | 74 --- src/events/NameEventContent.cc | 45 -- src/events/PowerLevelsEventContent.cc | 114 ---- src/events/TopicEventContent.cc | 45 -- src/events/messages/Audio.cc | 40 -- src/events/messages/Emote.cc | 27 - src/events/messages/File.cc | 50 -- src/events/messages/Image.cc | 52 -- src/events/messages/Location.cc | 47 -- src/events/messages/Notice.cc | 27 - src/events/messages/Text.cc | 27 - src/events/messages/Video.cc | 53 -- src/timeline/TimelineItem.cc | 79 ++- src/timeline/TimelineView.cc | 200 ++++--- src/timeline/TimelineViewManager.cc | 29 +- src/timeline/widgets/AudioItem.cc | 15 +- src/timeline/widgets/FileItem.cc | 15 +- src/timeline/widgets/ImageItem.cc | 13 +- src/timeline/widgets/VideoItem.cc | 11 +- tests/event_collection.cc | 111 ---- tests/events.cc | 707 ------------------------- tests/message_events.cc | 287 ---------- 77 files changed, 650 insertions(+), 4964 deletions(-) delete mode 100755 .ci/linux/gtest.sh delete mode 100755 .ci/linux/run-tests.sh 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 delete mode 100644 src/Sync.cc delete mode 100644 src/events/AliasesEventContent.cc delete mode 100644 src/events/AvatarEventContent.cc delete mode 100644 src/events/CanonicalAliasEventContent.cc delete mode 100644 src/events/CreateEventContent.cc delete mode 100644 src/events/Event.cc delete mode 100644 src/events/HistoryVisibilityEventContent.cc delete mode 100644 src/events/JoinRulesEventContent.cc delete mode 100644 src/events/MemberEventContent.cc delete mode 100644 src/events/MessageEventContent.cc delete mode 100644 src/events/NameEventContent.cc delete mode 100644 src/events/PowerLevelsEventContent.cc delete mode 100644 src/events/TopicEventContent.cc delete mode 100644 src/events/messages/Audio.cc delete mode 100644 src/events/messages/Emote.cc delete mode 100644 src/events/messages/File.cc delete mode 100644 src/events/messages/Image.cc delete mode 100644 src/events/messages/Location.cc delete mode 100644 src/events/messages/Notice.cc delete mode 100644 src/events/messages/Text.cc delete mode 100644 src/events/messages/Video.cc delete mode 100644 tests/event_collection.cc delete mode 100644 tests/events.cc delete mode 100644 tests/message_events.cc diff --git a/.ci/linux/gtest.sh b/.ci/linux/gtest.sh deleted file mode 100755 index 8dd7084c..00000000 --- a/.ci/linux/gtest.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -evx - -sudo apt-get -qq update -sudo apt-get install -y libgtest-dev -wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz -tar xf release-1.8.0.tar.gz -cd googletest-release-1.8.0 - -cmake -DBUILD_SHARED_LIBS=ON . -make -sudo cp -a googletest/include/gtest /usr/include -sudo cp -a googlemock/gtest/*.so /usr/lib/ - -sudo ldconfig -v | grep gtest - -cd $TRAVIS_BUILD_DIR - diff --git a/.ci/linux/run-tests.sh b/.ci/linux/run-tests.sh deleted file mode 100755 index dc9e303c..00000000 --- a/.ci/linux/run-tests.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -evx - -cmake -DBUILD_TESTS=ON -H. -Bbuild && cmake --build build - -cd build && GTEST_COLOR=1 ctest --verbose diff --git a/.travis.yml b/.travis.yml index c0f0ed16..ba45a88b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ matrix: compiler: gcc env: - COMPILER=g++-6 - - RUN_TESTS=1 addons: apt: sources: ['ubuntu-toolchain-r-test'] @@ -30,7 +29,6 @@ matrix: before_install: - export CXX=${COMPILER} - - if [ $TRAVIS_OS_NAME == linux ]; then ./.ci/linux/gtest.sh; fi install: - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install qt5 lmdb clang-format; fi @@ -45,7 +43,6 @@ script: - make -C build -j2 - if [ $TRAVIS_OS_NAME == osx ]; then make lint; fi - if [ $TRAVIS_OS_NAME == osx ]; then ./.ci/macos/deploy.sh; fi - - if [ $RUN_TESTS == 1 ]; then ./.ci/linux/run-tests.sh; fi - if [ $TRAVIS_OS_NAME == linux ]; then ./.ci/linux/deploy.sh; fi deploy: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d518fe6..69efeedd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.1) -option(BUILD_TESTS "Build all tests" OFF) option(APPVEYOR_BUILD "Build on appveyor" OFF) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) @@ -122,6 +121,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") -Werror \ -pipe \ -pedantic \ + -ferror-limit=3 \ -Wunreachable-code") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -200,7 +200,6 @@ set(SRC_FILES src/RoomState.cc src/SideBarActions.cc src/Splitter.cc - src/Sync.cc src/TextInputWidget.cc src/TopRoomBar.cc src/TrayIcon.cc @@ -211,35 +210,8 @@ set(SRC_FILES src/main.cc ) -set(MATRIX_EVENTS - src/events/Event.cc - - src/events/AliasesEventContent.cc - src/events/AvatarEventContent.cc - src/events/CanonicalAliasEventContent.cc - src/events/CreateEventContent.cc - src/events/HistoryVisibilityEventContent.cc - src/events/JoinRulesEventContent.cc - src/events/MemberEventContent.cc - src/events/MessageEventContent.cc - src/events/NameEventContent.cc - src/events/PowerLevelsEventContent.cc - src/events/TopicEventContent.cc - - src/events/messages/Audio.cc - src/events/messages/Emote.cc - src/events/messages/File.cc - src/events/messages/Image.cc - src/events/messages/Location.cc - src/events/messages/Notice.cc - src/events/messages/Text.cc - src/events/messages/Video.cc -) - include_directories(include) include_directories(include/ui) -include_directories(include/events) -include_directories(include/events/messages) include_directories(libs/lmdbxx) include_directories(${LMDB_INCLUDE_DIR}) @@ -324,35 +296,9 @@ file(APPEND ${_qrc} " ") qt5_add_resources(LANG_QRC ${_qrc}) qt5_add_resources(QRC resources/res.qrc) -# -# Matrix events library. -# -add_library(matrix_events ${MATRIX_EVENTS} src/Deserializable.cc) -target_link_libraries(matrix_events Qt5::Core) - add_subdirectory(libs/matrix-structs) -if (BUILD_TESTS) - enable_testing() - - find_package(GTest REQUIRED) - include_directories(${GTEST_INCLUDE_DIRS}) - - add_executable(events_test tests/events.cc) - target_link_libraries(events_test matrix_events ${GTEST_BOTH_LIBRARIES}) - - add_executable(event_collection_test tests/event_collection.cc) - target_link_libraries(event_collection_test matrix_events ${GTEST_BOTH_LIBRARIES}) - - add_executable(message_events tests/message_events.cc) - target_link_libraries(message_events matrix_events ${GTEST_BOTH_LIBRARIES}) - - add_test(MatrixEvents events_test) - add_test(MatrixEventCollection event_collection_test) - add_test(MatrixMessageEvents message_events) -endif() - -set(COMMON_LIBS matrix_events matrix_structs Qt5::Widgets Qt5::Network Qt5::Concurrent) +set(COMMON_LIBS matrix_structs Qt5::Widgets Qt5::Network Qt5::Concurrent) if(APPVEYOR_BUILD) set(NHEKO_LIBS ${COMMON_LIBS} lmdb) diff --git a/Makefile b/Makefile index 1a23d6b2..fbbbed9b 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,12 @@ debug: - @cmake -DBUILD_TESTS=OFF -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Debug + @cmake -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Debug @cmake --build build release-debug: - @cmake -DBUILD_TESTS=OFF -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo + @cmake -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo @cmake --build build -test: - @cmake -DBUILD_TESTS=ON -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo - @cmake --build build - @cd build && GTEST_COLOR=1 ctest --verbose - linux-appimage: @./.ci/linux/deploy.sh 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 QJsonObj