From 990a3a97c7578c30223ff4f348b9241be75f5bf9 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 1 Sep 2018 13:35:10 +0300 Subject: [PATCH] Merge matrix-structs into the client lib --- CMakeLists.txt | 19 +++++++++++-- README.md | 1 - deps/CMakeLists.txt | 29 ++++++++------------ deps/cmake/MatrixStructs.cmake | 24 ---------------- deps/cmake/SpdLog.cmake | 1 + src/Cache.cpp | 10 +++---- src/Cache.h | 50 +++++++++++++++++----------------- src/ChatPage.h | 5 ++-- src/Olm.cpp | 6 ++-- src/RoomInfoListItem.cpp | 2 -- src/TextInputWidget.cpp | 2 -- src/Utils.cpp | 38 +++++++++++++------------- src/Utils.h | 19 +++++++------ src/timeline/TimelineView.cpp | 46 ++++++++++++++++--------------- 14 files changed, 121 insertions(+), 131 deletions(-) delete mode 100644 deps/cmake/MatrixStructs.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f2c987d..cb641cd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ option(ASAN "Compile with address sanitizers" OFF) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +add_definitions(-DBOOST_MPL_LIMIT_LIST_SIZE=30) +add_definitions(-DBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) + include(GNUInstallDirs) # Include Qt basic functions @@ -230,9 +233,20 @@ set(SRC_FILES # ExternalProject dependencies set(EXTERNAL_PROJECT_DEPS "") +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_STATIC_RUNTIME OFF) +set(Boost_USE_MULTITHREADED ON) +find_package(Boost 1.66 REQUIRED + COMPONENTS atomic + chrono + date_time + iostreams + random + regex + system + thread) find_package(ZLIB REQUIRED) find_package(OpenSSL REQUIRED) -find_package(MatrixStructs 0.1.0 REQUIRED) find_package(MatrixClient 0.1.0 REQUIRED) find_package(Olm 2 REQUIRED) find_package(spdlog 1.0.0 CONFIG REQUIRED) @@ -259,6 +273,7 @@ include_directories(SYSTEM ${TWEENY_INCLUDE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${CMAKE_CURRENT_BINARY_DIR}/config) +include_directories(${Boost_INCLUDE_DIRS}) qt5_wrap_cpp(MOC_HEADERS # Dialogs @@ -342,8 +357,8 @@ include(Translations) set(TRANSLATION_DEPS ${LANG_QRC} ${QRC} ${QM_SRC}) set(COMMON_LIBS - MatrixStructs::MatrixStructs MatrixClient::MatrixClient + ${Boost_LIBRARIES} Qt5::Widgets Qt5::Svg Qt5::Concurrent diff --git a/README.md b/README.md index c01a2a13..f414092f 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,6 @@ sudo port install nheko Freetype, which is essential to properly support emoji. - CMake 3.1 or greater. - [mtxclient](https://github.com/mujx/mtxclient) -- [matrix-structs](https://github.com/mujx/matrix-structs) - [LMDB](https://symas.com/lightning-memory-mapped-database/) - Boost 1.66 or greater. - [libolm](https://git.matrix.org/git/olm) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 1e079d6f..c9fefebb 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -26,8 +26,6 @@ option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${USE_BUNDLED}) option(USE_BUNDLED_OLM "Use the bundled version of libolm." ${USE_BUNDLED}) option(USE_BUNDLED_TWEENY "Use the bundled version of Tweeny." ${USE_BUNDLED}) option(USE_BUNDLED_LMDBXX "Use the bundled version of lmdbxx." ${USE_BUNDLED}) -option(USE_BUNDLED_MATRIX_STRUCTS "Use the bundled version of matrix-structs." - ${USE_BUNDLED}) option(USE_BUNDLED_MATRIX_CLIENT "Use the bundled version of mtxclient." ${USE_BUNDLED}) @@ -38,19 +36,12 @@ set(BOOST_URL set(BOOST_SHA256 5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9) -set( - MATRIX_STRUCTS_URL - https://github.com/mujx/matrix-structs/archive/8de04afea34e95c14d1dde82af390592dfde90dd.tar.gz - ) -set(MATRIX_STRUCTS_HASH - 255a82a9e463261858cd7da18f34fd60d19882ab507d214e47ea47ff78ae68b6) - set( MTXCLIENT_URL - https://github.com/mujx/mtxclient/archive/10894678e982bc037a0aa4cf650b89a566ccbc52.tar.gz + https://github.com/mujx/mtxclient/archive/343cf4b1589b380443dd7f34f381d655ba9cc87c.tar.gz ) set(MTXCLIENT_HASH - 9bbb4613e6ed7c9886575221e1820c4aeda302ff29703e9040e53a2d0236c8ea) + 68d4f7be55bb62a59e8698ecb04705e7422b63d5caccede26e2e0153f17ccda9) set( TWEENY_URL @@ -69,9 +60,17 @@ set(LMDBXX_HASH set(OLM_URL https://git.matrix.org/git/olm.git) set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae) -set(SPDLOG_URL https://github.com/gabime/spdlog/archive/v1.0.0.tar.gz) +set(SPDLOG_URL https://github.com/gabime/spdlog/archive/v1.1.0.tar.gz) set(SPDLOG_HASH - 90d5365121bcd2c41ce94dfe6a460e89507a2dfef6133fe5fad5bb35ac4ef0a1) + 3dbcbfd8c07e25f5e0d662b194d3a7772ef214358c49ada23c044c4747ce8b19) + +set(JSON_HEADER_URL + https://github.com/nlohmann/json/releases/download/v3.2.0/json.hpp) +set(JSON_HEADER_HASH + ce6b5610a051ec6795fa11c33854abebb086f0fd67c311f5921c3c07f9531b44) + +file(DOWNLOAD ${JSON_HEADER_URL} ${DEPS_INSTALL_DIR}/include/json.hpp + EXPECTED_HASH SHA256=${JSON_HEADER_HASH}) if(USE_BUNDLED_BOOST) include(Boost) @@ -85,10 +84,6 @@ if(USE_BUNDLED_OLM) include(Olm) endif() -if(USE_BUNDLED_MATRIX_STRUCTS) - include(MatrixStructs) -endif() - if(USE_BUNDLED_TWEENY) include(Tweeny) endif() diff --git a/deps/cmake/MatrixStructs.cmake b/deps/cmake/MatrixStructs.cmake deleted file mode 100644 index adc273d5..00000000 --- a/deps/cmake/MatrixStructs.cmake +++ /dev/null @@ -1,24 +0,0 @@ -set(WINDOWS_FLAGS "") - -if(MSVC) - set(WINDOWS_FLAGS "-DCMAKE_GENERATOR_PLATFORM=x64") -endif() - -ExternalProject_Add( - MatrixStructs - - URL ${MATRIX_STRUCTS_URL} - URL_HASH SHA256=${MATRIX_STRUCTS_HASH} - - BUILD_IN_SOURCE 1 - SOURCE_DIR ${DEPS_BUILD_DIR}/matrix_structs - CONFIGURE_COMMAND ${CMAKE_COMMAND} - -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} - -DCMAKE_BUILD_TYPE=Release - ${DEPS_BUILD_DIR}/matrix_structs - ${WINDOWS_FLAGS} - BUILD_COMMAND ${CMAKE_COMMAND} - --build ${DEPS_BUILD_DIR}/matrix_structs - --config Release) - -list(APPEND THIRD_PARTY_DEPS MatrixStructs) diff --git a/deps/cmake/SpdLog.cmake b/deps/cmake/SpdLog.cmake index f4111ed6..27109b66 100644 --- a/deps/cmake/SpdLog.cmake +++ b/deps/cmake/SpdLog.cmake @@ -15,6 +15,7 @@ ExternalProject_Add( CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} -DSPDLOG_BUILD_EXAMPLES=0 + -DSPDLOG_BUILD_BENCH=0 -DSPDLOG_BUILD_TESTING=0 ${DEPS_BUILD_DIR}/spdlog ${WINDOWS_FLAGS}) diff --git a/src/Cache.cpp b/src/Cache.cpp index b8b4a2bf..4965167b 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -24,8 +24,8 @@ #include #include +#include #include -#include #include "Cache.h" #include "Utils.h" @@ -918,8 +918,8 @@ Cache::saveInvite(lmdb::txn &txn, using namespace mtx::events::state; for (const auto &e : room.invite_state) { - if (mpark::holds_alternative>(e)) { - auto msg = mpark::get>(e); + if (boost::get>(&e) != nullptr) { + auto msg = boost::get>(e); auto display_name = msg.content.display_name.empty() ? msg.state_key @@ -930,7 +930,7 @@ Cache::saveInvite(lmdb::txn &txn, lmdb::dbi_put( txn, membersdb, lmdb::val(msg.state_key), lmdb::val(json(tmp).dump())); } else { - mpark::visit( + boost::apply_visitor( [&txn, &statesdb](auto msg) { bool res = lmdb::dbi_put(txn, statesdb, @@ -1744,7 +1744,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn, if (isStateEvent(e)) continue; - if (mpark::holds_alternative>(e)) + if (boost::get>(&e) != nullptr) continue; json obj = json::object(); diff --git a/src/Cache.h b/src/Cache.h index c2f8cfc8..ce531056 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -486,8 +486,8 @@ private: using namespace mtx::events; using namespace mtx::events::state; - if (mpark::holds_alternative>(event)) { - const auto e = mpark::get>(event); + if (boost::get>(&event) != nullptr) { + const auto e = boost::get>(event); switch (e.content.membership) { // @@ -531,7 +531,7 @@ private: } return; - } else if (mpark::holds_alternative>(event)) { + } else if (boost::get>(&event) != nullptr) { setEncryptedRoom(txn, room_id); return; } @@ -539,7 +539,7 @@ private: if (!isStateEvent(event)) return; - mpark::visit( + boost::apply_visitor( [&txn, &statesdb](auto e) { lmdb::dbi_put( txn, statesdb, lmdb::val(to_string(e.type)), lmdb::val(json(e).dump())); @@ -553,17 +553,17 @@ private: using namespace mtx::events; using namespace mtx::events::state; - return mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e); + return boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr; } template @@ -572,11 +572,11 @@ private: using namespace mtx::events; using namespace mtx::events::state; - return mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e); + return boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr; } bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e) @@ -584,11 +584,11 @@ private: using namespace mtx::events; using namespace mtx::events::state; - return mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e) || - mpark::holds_alternative>(e); + return boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr || + boost::get>(&e) != nullptr; } void saveInvites(lmdb::txn &txn, diff --git a/src/ChatPage.h b/src/ChatPage.h index 9398b443..2000b9e5 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include #include @@ -249,8 +250,8 @@ ChatPage::getMemberships(const std::vector &collection) const using Member = mtx::events::StateEvent; for (const auto &event : collection) { - if (mpark::holds_alternative(event)) { - auto member = mpark::get(event); + if (boost::get(event) != nullptr) { + auto member = boost::get(event); memberships.emplace(member.state_key, member); } } diff --git a/src/Olm.cpp b/src/Olm.cpp index f65430f1..d12542ed 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -1,3 +1,5 @@ +#include + #include "Olm.h" #include "Cache.h" @@ -288,14 +290,14 @@ request_keys(const std::string &room_id, const std::string &event_id) return; } - if (!mpark::holds_alternative>(res)) { + if (boost::get>(&res) == nullptr) { nhlog::net()->info( "retrieved event is not encrypted: {} from {}", event_id, room_id); return; } olm::send_key_request_for(room_id, - mpark::get>(res)); + boost::get>(res)); }); } diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index 172cdb90..4edd7b89 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -20,8 +20,6 @@ #include #include -#include - #include "Cache.h" #include "Config.h" #include "RoomInfoListItem.h" diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index 74ca072b..3c5fa9e9 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -29,8 +29,6 @@ #include #include -#include - #include "Cache.h" #include "ChatPage.h" #include "Config.h" diff --git a/src/Utils.cpp b/src/Utils.cpp index ceca53fc..8f7e9992 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include using TimelineEvent = mtx::events::collections::TimelineEvents; @@ -89,24 +89,24 @@ utils::getMessageDescription(const TimelineEvent &event, using Video = mtx::events::RoomEvent; using Encrypted = mtx::events::EncryptedEvent; - if (mpark::holds_alternative