Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Merge matrix-structs into the client lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mujx committed Sep 1, 2018
1 parent d0e31c4 commit 990a3a9
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 131 deletions.
19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 12 additions & 17 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand Down
24 changes: 0 additions & 24 deletions deps/cmake/MatrixStructs.cmake

This file was deleted.

1 change: 1 addition & 0 deletions deps/cmake/SpdLog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
10 changes: 5 additions & 5 deletions src/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <QSettings>
#include <QStandardPaths>

#include <boost/variant.hpp>
#include <mtx/responses/common.hpp>
#include <variant.hpp>

#include "Cache.h"
#include "Utils.h"
Expand Down Expand Up @@ -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<StrippedEvent<Member>>(e)) {
auto msg = mpark::get<StrippedEvent<Member>>(e);
if (boost::get<StrippedEvent<Member>>(&e) != nullptr) {
auto msg = boost::get<StrippedEvent<Member>>(e);

auto display_name = msg.content.display_name.empty()
? msg.state_key
Expand All @@ -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,
Expand Down Expand Up @@ -1744,7 +1744,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (isStateEvent(e))
continue;

if (mpark::holds_alternative<RedactionEvent<msg::Redaction>>(e))
if (boost::get<RedactionEvent<msg::Redaction>>(&e) != nullptr)
continue;

json obj = json::object();
Expand Down
50 changes: 25 additions & 25 deletions src/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ class Cache : public QObject
using namespace mtx::events;
using namespace mtx::events::state;

if (mpark::holds_alternative<StateEvent<Member>>(event)) {
const auto e = mpark::get<StateEvent<Member>>(event);
if (boost::get<StateEvent<Member>>(&event) != nullptr) {
const auto e = boost::get<StateEvent<Member>>(event);

switch (e.content.membership) {
//
Expand Down Expand Up @@ -531,15 +531,15 @@ class Cache : public QObject
}

return;
} else if (mpark::holds_alternative<StateEvent<Encryption>>(event)) {
} else if (boost::get<StateEvent<Encryption>>(&event) != nullptr) {
setEncryptedRoom(txn, room_id);
return;
}

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()));
Expand All @@ -553,17 +553,17 @@ class Cache : public QObject
using namespace mtx::events;
using namespace mtx::events::state;

return mpark::holds_alternative<StateEvent<Aliases>>(e) ||
mpark::holds_alternative<StateEvent<state::Avatar>>(e) ||
mpark::holds_alternative<StateEvent<CanonicalAlias>>(e) ||
mpark::holds_alternative<StateEvent<Create>>(e) ||
mpark::holds_alternative<StateEvent<GuestAccess>>(e) ||
mpark::holds_alternative<StateEvent<HistoryVisibility>>(e) ||
mpark::holds_alternative<StateEvent<JoinRules>>(e) ||
mpark::holds_alternative<StateEvent<Name>>(e) ||
mpark::holds_alternative<StateEvent<Member>>(e) ||
mpark::holds_alternative<StateEvent<PowerLevels>>(e) ||
mpark::holds_alternative<StateEvent<Topic>>(e);
return boost::get<StateEvent<Aliases>>(&e) != nullptr ||
boost::get<StateEvent<state::Avatar>>(&e) != nullptr ||
boost::get<StateEvent<CanonicalAlias>>(&e) != nullptr ||
boost::get<StateEvent<Create>>(&e) != nullptr ||
boost::get<StateEvent<GuestAccess>>(&e) != nullptr ||
boost::get<StateEvent<HistoryVisibility>>(&e) != nullptr ||
boost::get<StateEvent<JoinRules>>(&e) != nullptr ||
boost::get<StateEvent<Name>>(&e) != nullptr ||
boost::get<StateEvent<Member>>(&e) != nullptr ||
boost::get<StateEvent<PowerLevels>>(&e) != nullptr ||
boost::get<StateEvent<Topic>>(&e) != nullptr;
}

template<class T>
Expand All @@ -572,23 +572,23 @@ class Cache : public QObject
using namespace mtx::events;
using namespace mtx::events::state;

return mpark::holds_alternative<StateEvent<state::Avatar>>(e) ||
mpark::holds_alternative<StateEvent<CanonicalAlias>>(e) ||
mpark::holds_alternative<StateEvent<Name>>(e) ||
mpark::holds_alternative<StateEvent<Member>>(e) ||
mpark::holds_alternative<StateEvent<Topic>>(e);
return boost::get<StateEvent<state::Avatar>>(&e) != nullptr ||
boost::get<StateEvent<CanonicalAlias>>(&e) != nullptr ||
boost::get<StateEvent<Name>>(&e) != nullptr ||
boost::get<StateEvent<Member>>(&e) != nullptr ||
boost::get<StateEvent<Topic>>(&e) != nullptr;
}

bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e)
{
using namespace mtx::events;
using namespace mtx::events::state;

return mpark::holds_alternative<StrippedEvent<state::Avatar>>(e) ||
mpark::holds_alternative<StrippedEvent<CanonicalAlias>>(e) ||
mpark::holds_alternative<StrippedEvent<Name>>(e) ||
mpark::holds_alternative<StrippedEvent<Member>>(e) ||
mpark::holds_alternative<StrippedEvent<Topic>>(e);
return boost::get<StrippedEvent<state::Avatar>>(&e) != nullptr ||
boost::get<StrippedEvent<CanonicalAlias>>(&e) != nullptr ||
boost::get<StrippedEvent<Name>>(&e) != nullptr ||
boost::get<StrippedEvent<Member>>(&e) != nullptr ||
boost::get<StrippedEvent<Topic>>(&e) != nullptr;
}

void saveInvites(lmdb::txn &txn,
Expand Down
5 changes: 3 additions & 2 deletions src/ChatPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <atomic>
#include <boost/variant.hpp>

#include <QFrame>
#include <QHBoxLayout>
Expand Down Expand Up @@ -249,8 +250,8 @@ ChatPage::getMemberships(const std::vector<Collection> &collection) const
using Member = mtx::events::StateEvent<mtx::events::state::Member>;

for (const auto &event : collection) {
if (mpark::holds_alternative<Member>(event)) {
auto member = mpark::get<Member>(event);
if (boost::get<Member>(event) != nullptr) {
auto member = boost::get<Member>(event);
memberships.emplace(member.state_key, member);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Olm.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <boost/variant.hpp>

#include "Olm.h"

#include "Cache.h"
Expand Down Expand Up @@ -288,14 +290,14 @@ request_keys(const std::string &room_id, const std::string &event_id)
return;
}

if (!mpark::holds_alternative<EncryptedEvent<msg::Encrypted>>(res)) {
if (boost::get<EncryptedEvent<msg::Encrypted>>(&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<EncryptedEvent<msg::Encrypted>>(res));
boost::get<EncryptedEvent<msg::Encrypted>>(res));
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/RoomInfoListItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <QMouseEvent>
#include <QPainter>

#include <variant.hpp>

#include "Cache.h"
#include "Config.h"
#include "RoomInfoListItem.h"
Expand Down
2 changes: 0 additions & 2 deletions src/TextInputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <QStyleOption>
#include <QtConcurrent>

#include <variant.hpp>

#include "Cache.h"
#include "ChatPage.h"
#include "Config.h"
Expand Down
Loading

0 comments on commit 990a3a9

Please sign in to comment.