Merge matrix-structs into the client lib

This commit is contained in:
Konstantinos Sideris 2018-09-01 13:35:10 +03:00
parent d0e31c43a6
commit 990a3a97c7
14 changed files with 121 additions and 131 deletions

View file

@ -5,6 +5,9 @@ option(ASAN "Compile with address sanitizers" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 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(GNUInstallDirs)
# Include Qt basic functions # Include Qt basic functions
@ -230,9 +233,20 @@ set(SRC_FILES
# ExternalProject dependencies # ExternalProject dependencies
set(EXTERNAL_PROJECT_DEPS "") 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(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
find_package(MatrixStructs 0.1.0 REQUIRED)
find_package(MatrixClient 0.1.0 REQUIRED) find_package(MatrixClient 0.1.0 REQUIRED)
find_package(Olm 2 REQUIRED) find_package(Olm 2 REQUIRED)
find_package(spdlog 1.0.0 CONFIG 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_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/config) include_directories(${CMAKE_CURRENT_BINARY_DIR}/config)
include_directories(${Boost_INCLUDE_DIRS})
qt5_wrap_cpp(MOC_HEADERS qt5_wrap_cpp(MOC_HEADERS
# Dialogs # Dialogs
@ -342,8 +357,8 @@ include(Translations)
set(TRANSLATION_DEPS ${LANG_QRC} ${QRC} ${QM_SRC}) set(TRANSLATION_DEPS ${LANG_QRC} ${QRC} ${QM_SRC})
set(COMMON_LIBS set(COMMON_LIBS
MatrixStructs::MatrixStructs
MatrixClient::MatrixClient MatrixClient::MatrixClient
${Boost_LIBRARIES}
Qt5::Widgets Qt5::Widgets
Qt5::Svg Qt5::Svg
Qt5::Concurrent Qt5::Concurrent

View file

@ -86,7 +86,6 @@ sudo port install nheko
Freetype, which is essential to properly support emoji. Freetype, which is essential to properly support emoji.
- CMake 3.1 or greater. - CMake 3.1 or greater.
- [mtxclient](https://github.com/mujx/mtxclient) - [mtxclient](https://github.com/mujx/mtxclient)
- [matrix-structs](https://github.com/mujx/matrix-structs)
- [LMDB](https://symas.com/lightning-memory-mapped-database/) - [LMDB](https://symas.com/lightning-memory-mapped-database/)
- Boost 1.66 or greater. - Boost 1.66 or greater.
- [libolm](https://git.matrix.org/git/olm) - [libolm](https://git.matrix.org/git/olm)

29
deps/CMakeLists.txt vendored
View file

@ -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_OLM "Use the bundled version of libolm." ${USE_BUNDLED})
option(USE_BUNDLED_TWEENY "Use the bundled version of Tweeny." ${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_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." option(USE_BUNDLED_MATRIX_CLIENT "Use the bundled version of mtxclient."
${USE_BUNDLED}) ${USE_BUNDLED})
@ -38,19 +36,12 @@ set(BOOST_URL
set(BOOST_SHA256 set(BOOST_SHA256
5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9) 5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9)
set(
MATRIX_STRUCTS_URL
https://github.com/mujx/matrix-structs/archive/8de04afea34e95c14d1dde82af390592dfde90dd.tar.gz
)
set(MATRIX_STRUCTS_HASH
255a82a9e463261858cd7da18f34fd60d19882ab507d214e47ea47ff78ae68b6)
set( set(
MTXCLIENT_URL MTXCLIENT_URL
https://github.com/mujx/mtxclient/archive/10894678e982bc037a0aa4cf650b89a566ccbc52.tar.gz https://github.com/mujx/mtxclient/archive/343cf4b1589b380443dd7f34f381d655ba9cc87c.tar.gz
) )
set(MTXCLIENT_HASH set(MTXCLIENT_HASH
9bbb4613e6ed7c9886575221e1820c4aeda302ff29703e9040e53a2d0236c8ea) 68d4f7be55bb62a59e8698ecb04705e7422b63d5caccede26e2e0153f17ccda9)
set( set(
TWEENY_URL TWEENY_URL
@ -69,9 +60,17 @@ set(LMDBXX_HASH
set(OLM_URL https://git.matrix.org/git/olm.git) set(OLM_URL https://git.matrix.org/git/olm.git)
set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae) 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 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) if(USE_BUNDLED_BOOST)
include(Boost) include(Boost)
@ -85,10 +84,6 @@ if(USE_BUNDLED_OLM)
include(Olm) include(Olm)
endif() endif()
if(USE_BUNDLED_MATRIX_STRUCTS)
include(MatrixStructs)
endif()
if(USE_BUNDLED_TWEENY) if(USE_BUNDLED_TWEENY)
include(Tweeny) include(Tweeny)
endif() endif()

View file

@ -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)

View file

@ -15,6 +15,7 @@ ExternalProject_Add(
CONFIGURE_COMMAND ${CMAKE_COMMAND} CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
-DSPDLOG_BUILD_EXAMPLES=0 -DSPDLOG_BUILD_EXAMPLES=0
-DSPDLOG_BUILD_BENCH=0
-DSPDLOG_BUILD_TESTING=0 -DSPDLOG_BUILD_TESTING=0
${DEPS_BUILD_DIR}/spdlog ${DEPS_BUILD_DIR}/spdlog
${WINDOWS_FLAGS}) ${WINDOWS_FLAGS})

View file

@ -24,8 +24,8 @@
#include <QSettings> #include <QSettings>
#include <QStandardPaths> #include <QStandardPaths>
#include <boost/variant.hpp>
#include <mtx/responses/common.hpp> #include <mtx/responses/common.hpp>
#include <variant.hpp>
#include "Cache.h" #include "Cache.h"
#include "Utils.h" #include "Utils.h"
@ -918,8 +918,8 @@ Cache::saveInvite(lmdb::txn &txn,
using namespace mtx::events::state; using namespace mtx::events::state;
for (const auto &e : room.invite_state) { for (const auto &e : room.invite_state) {
if (mpark::holds_alternative<StrippedEvent<Member>>(e)) { if (boost::get<StrippedEvent<Member>>(&e) != nullptr) {
auto msg = mpark::get<StrippedEvent<Member>>(e); auto msg = boost::get<StrippedEvent<Member>>(e);
auto display_name = msg.content.display_name.empty() auto display_name = msg.content.display_name.empty()
? msg.state_key ? msg.state_key
@ -930,7 +930,7 @@ Cache::saveInvite(lmdb::txn &txn,
lmdb::dbi_put( lmdb::dbi_put(
txn, membersdb, lmdb::val(msg.state_key), lmdb::val(json(tmp).dump())); txn, membersdb, lmdb::val(msg.state_key), lmdb::val(json(tmp).dump()));
} else { } else {
mpark::visit( boost::apply_visitor(
[&txn, &statesdb](auto msg) { [&txn, &statesdb](auto msg) {
bool res = lmdb::dbi_put(txn, bool res = lmdb::dbi_put(txn,
statesdb, statesdb,
@ -1744,7 +1744,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (isStateEvent(e)) if (isStateEvent(e))
continue; continue;
if (mpark::holds_alternative<RedactionEvent<msg::Redaction>>(e)) if (boost::get<RedactionEvent<msg::Redaction>>(&e) != nullptr)
continue; continue;
json obj = json::object(); json obj = json::object();

View file

@ -486,8 +486,8 @@ private:
using namespace mtx::events; using namespace mtx::events;
using namespace mtx::events::state; using namespace mtx::events::state;
if (mpark::holds_alternative<StateEvent<Member>>(event)) { if (boost::get<StateEvent<Member>>(&event) != nullptr) {
const auto e = mpark::get<StateEvent<Member>>(event); const auto e = boost::get<StateEvent<Member>>(event);
switch (e.content.membership) { switch (e.content.membership) {
// //
@ -531,7 +531,7 @@ private:
} }
return; return;
} else if (mpark::holds_alternative<StateEvent<Encryption>>(event)) { } else if (boost::get<StateEvent<Encryption>>(&event) != nullptr) {
setEncryptedRoom(txn, room_id); setEncryptedRoom(txn, room_id);
return; return;
} }
@ -539,7 +539,7 @@ private:
if (!isStateEvent(event)) if (!isStateEvent(event))
return; return;
mpark::visit( boost::apply_visitor(
[&txn, &statesdb](auto e) { [&txn, &statesdb](auto e) {
lmdb::dbi_put( lmdb::dbi_put(
txn, statesdb, lmdb::val(to_string(e.type)), lmdb::val(json(e).dump())); 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;
using namespace mtx::events::state; using namespace mtx::events::state;
return mpark::holds_alternative<StateEvent<Aliases>>(e) || return boost::get<StateEvent<Aliases>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<state::Avatar>>(e) || boost::get<StateEvent<state::Avatar>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<CanonicalAlias>>(e) || boost::get<StateEvent<CanonicalAlias>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Create>>(e) || boost::get<StateEvent<Create>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<GuestAccess>>(e) || boost::get<StateEvent<GuestAccess>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<HistoryVisibility>>(e) || boost::get<StateEvent<HistoryVisibility>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<JoinRules>>(e) || boost::get<StateEvent<JoinRules>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Name>>(e) || boost::get<StateEvent<Name>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Member>>(e) || boost::get<StateEvent<Member>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<PowerLevels>>(e) || boost::get<StateEvent<PowerLevels>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Topic>>(e); boost::get<StateEvent<Topic>>(&e) != nullptr;
} }
template<class T> template<class T>
@ -572,11 +572,11 @@ private:
using namespace mtx::events; using namespace mtx::events;
using namespace mtx::events::state; using namespace mtx::events::state;
return mpark::holds_alternative<StateEvent<state::Avatar>>(e) || return boost::get<StateEvent<state::Avatar>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<CanonicalAlias>>(e) || boost::get<StateEvent<CanonicalAlias>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Name>>(e) || boost::get<StateEvent<Name>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Member>>(e) || boost::get<StateEvent<Member>>(&e) != nullptr ||
mpark::holds_alternative<StateEvent<Topic>>(e); boost::get<StateEvent<Topic>>(&e) != nullptr;
} }
bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e) bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e)
@ -584,11 +584,11 @@ private:
using namespace mtx::events; using namespace mtx::events;
using namespace mtx::events::state; using namespace mtx::events::state;
return mpark::holds_alternative<StrippedEvent<state::Avatar>>(e) || return boost::get<StrippedEvent<state::Avatar>>(&e) != nullptr ||
mpark::holds_alternative<StrippedEvent<CanonicalAlias>>(e) || boost::get<StrippedEvent<CanonicalAlias>>(&e) != nullptr ||
mpark::holds_alternative<StrippedEvent<Name>>(e) || boost::get<StrippedEvent<Name>>(&e) != nullptr ||
mpark::holds_alternative<StrippedEvent<Member>>(e) || boost::get<StrippedEvent<Member>>(&e) != nullptr ||
mpark::holds_alternative<StrippedEvent<Topic>>(e); boost::get<StrippedEvent<Topic>>(&e) != nullptr;
} }
void saveInvites(lmdb::txn &txn, void saveInvites(lmdb::txn &txn,

View file

@ -18,6 +18,7 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <boost/variant.hpp>
#include <QFrame> #include <QFrame>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -249,8 +250,8 @@ ChatPage::getMemberships(const std::vector<Collection> &collection) const
using Member = mtx::events::StateEvent<mtx::events::state::Member>; using Member = mtx::events::StateEvent<mtx::events::state::Member>;
for (const auto &event : collection) { for (const auto &event : collection) {
if (mpark::holds_alternative<Member>(event)) { if (boost::get<Member>(event) != nullptr) {
auto member = mpark::get<Member>(event); auto member = boost::get<Member>(event);
memberships.emplace(member.state_key, member); memberships.emplace(member.state_key, member);
} }
} }

View file

@ -1,3 +1,5 @@
#include <boost/variant.hpp>
#include "Olm.h" #include "Olm.h"
#include "Cache.h" #include "Cache.h"
@ -288,14 +290,14 @@ request_keys(const std::string &room_id, const std::string &event_id)
return; return;
} }
if (!mpark::holds_alternative<EncryptedEvent<msg::Encrypted>>(res)) { if (boost::get<EncryptedEvent<msg::Encrypted>>(&res) == nullptr) {
nhlog::net()->info( nhlog::net()->info(
"retrieved event is not encrypted: {} from {}", event_id, room_id); "retrieved event is not encrypted: {} from {}", event_id, room_id);
return; return;
} }
olm::send_key_request_for(room_id, olm::send_key_request_for(room_id,
mpark::get<EncryptedEvent<msg::Encrypted>>(res)); boost::get<EncryptedEvent<msg::Encrypted>>(res));
}); });
} }

View file

@ -20,8 +20,6 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainter> #include <QPainter>
#include <variant.hpp>
#include "Cache.h" #include "Cache.h"
#include "Config.h" #include "Config.h"
#include "RoomInfoListItem.h" #include "RoomInfoListItem.h"

View file

@ -29,8 +29,6 @@
#include <QStyleOption> #include <QStyleOption>
#include <QtConcurrent> #include <QtConcurrent>
#include <variant.hpp>
#include "Cache.h" #include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Config.h" #include "Config.h"

View file

@ -5,7 +5,7 @@
#include <QSettings> #include <QSettings>
#include <cmath> #include <cmath>
#include <variant.hpp> #include <boost/variant.hpp>
using TimelineEvent = mtx::events::collections::TimelineEvents; using TimelineEvent = mtx::events::collections::TimelineEvents;
@ -89,24 +89,24 @@ utils::getMessageDescription(const TimelineEvent &event,
using Video = mtx::events::RoomEvent<mtx::events::msg::Video>; using Video = mtx::events::RoomEvent<mtx::events::msg::Video>;
using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>; using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>;
if (mpark::holds_alternative<Audio>(event)) { if (boost::get<Audio>(&event) != nullptr) {
return createDescriptionInfo<Audio>(event, localUser, room_id); return createDescriptionInfo<Audio>(event, localUser, room_id);
} else if (mpark::holds_alternative<Emote>(event)) { } else if (boost::get<Emote>(&event) != nullptr) {
return createDescriptionInfo<Emote>(event, localUser, room_id); return createDescriptionInfo<Emote>(event, localUser, room_id);
} else if (mpark::holds_alternative<File>(event)) { } else if (boost::get<File>(&event) != nullptr) {
return createDescriptionInfo<File>(event, localUser, room_id); return createDescriptionInfo<File>(event, localUser, room_id);
} else if (mpark::holds_alternative<Image>(event)) { } else if (boost::get<Image>(&event) != nullptr) {
return createDescriptionInfo<Image>(event, localUser, room_id); return createDescriptionInfo<Image>(event, localUser, room_id);
} else if (mpark::holds_alternative<Notice>(event)) { } else if (boost::get<Notice>(&event) != nullptr) {
return createDescriptionInfo<Notice>(event, localUser, room_id); return createDescriptionInfo<Notice>(event, localUser, room_id);
} else if (mpark::holds_alternative<Text>(event)) { } else if (boost::get<Text>(&event) != nullptr) {
return createDescriptionInfo<Text>(event, localUser, room_id); return createDescriptionInfo<Text>(event, localUser, room_id);
} else if (mpark::holds_alternative<Video>(event)) { } else if (boost::get<Video>(&event) != nullptr) {
return createDescriptionInfo<Video>(event, localUser, room_id); return createDescriptionInfo<Video>(event, localUser, room_id);
} else if (mpark::holds_alternative<mtx::events::Sticker>(event)) { } else if (boost::get<mtx::events::Sticker>(&event) != nullptr) {
return createDescriptionInfo<mtx::events::Sticker>(event, localUser, room_id); return createDescriptionInfo<mtx::events::Sticker>(event, localUser, room_id);
} else if (mpark::holds_alternative<Encrypted>(event)) { } else if (boost::get<Encrypted>(&event) != nullptr) {
const auto msg = mpark::get<Encrypted>(event); const auto msg = boost::get<Encrypted>(event);
const auto sender = QString::fromStdString(msg.sender); const auto sender = QString::fromStdString(msg.sender);
const auto username = Cache::displayName(room_id, sender); const auto username = Cache::displayName(room_id, sender);
@ -193,21 +193,21 @@ utils::event_body(const mtx::events::collections::TimelineEvents &event)
using namespace mtx::events; using namespace mtx::events;
using namespace mtx::events::msg; using namespace mtx::events::msg;
if (mpark::holds_alternative<RoomEvent<Audio>>(event)) { if (boost::get<RoomEvent<Audio>>(&event) != nullptr) {
return message_body<RoomEvent<Audio>>(event); return message_body<RoomEvent<Audio>>(event);
} else if (mpark::holds_alternative<RoomEvent<Emote>>(event)) { } else if (boost::get<RoomEvent<Emote>>(&event) != nullptr) {
return message_body<RoomEvent<Emote>>(event); return message_body<RoomEvent<Emote>>(event);
} else if (mpark::holds_alternative<RoomEvent<File>>(event)) { } else if (boost::get<RoomEvent<File>>(&event) != nullptr) {
return message_body<RoomEvent<File>>(event); return message_body<RoomEvent<File>>(event);
} else if (mpark::holds_alternative<RoomEvent<Image>>(event)) { } else if (boost::get<RoomEvent<Image>>(&event) != nullptr) {
return message_body<RoomEvent<Image>>(event); return message_body<RoomEvent<Image>>(event);
} else if (mpark::holds_alternative<RoomEvent<Notice>>(event)) { } else if (boost::get<RoomEvent<Notice>>(&event) != nullptr) {
return message_body<RoomEvent<Notice>>(event); return message_body<RoomEvent<Notice>>(event);
} else if (mpark::holds_alternative<Sticker>(event)) { } else if (boost::get<Sticker>(&event) != nullptr) {
return message_body<Sticker>(event); return message_body<Sticker>(event);
} else if (mpark::holds_alternative<RoomEvent<Text>>(event)) { } else if (boost::get<RoomEvent<Text>>(&event) != nullptr) {
return message_body<RoomEvent<Text>>(event); return message_body<RoomEvent<Text>>(event);
} else if (mpark::holds_alternative<RoomEvent<Video>>(event)) { } else if (boost::get<RoomEvent<Video>>(&event) != nullptr) {
return message_body<RoomEvent<Video>>(event); return message_body<RoomEvent<Video>>(event);
} }

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <boost/variant.hpp>
#include "Cache.h" #include "Cache.h"
#include "RoomInfoListItem.h" #include "RoomInfoListItem.h"
#include "timeline/widgets/AudioItem.h" #include "timeline/widgets/AudioItem.h"
@ -96,7 +98,7 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin
using Text = mtx::events::RoomEvent<mtx::events::msg::Text>; using Text = mtx::events::RoomEvent<mtx::events::msg::Text>;
using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>; using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>;
const auto msg = mpark::get<T>(event); const auto msg = boost::get<T>(event);
const auto sender = QString::fromStdString(msg.sender); const auto sender = QString::fromStdString(msg.sender);
const auto username = Cache::displayName(room_id, sender); const auto username = Cache::displayName(room_id, sender);
@ -135,25 +137,25 @@ erase_if(ContainerT &items, const PredicateT &predicate)
inline uint64_t inline uint64_t
event_timestamp(const mtx::events::collections::TimelineEvents &event) event_timestamp(const mtx::events::collections::TimelineEvents &event)
{ {
return mpark::visit([](auto msg) { return msg.origin_server_ts; }, event); return boost::apply_visitor([](auto msg) { return msg.origin_server_ts; }, event);
} }
inline nlohmann::json inline nlohmann::json
serialize_event(const mtx::events::collections::TimelineEvents &event) serialize_event(const mtx::events::collections::TimelineEvents &event)
{ {
return mpark::visit([](auto msg) { return json(msg); }, event); return boost::apply_visitor([](auto msg) { return json(msg); }, event);
} }
inline mtx::events::EventType inline mtx::events::EventType
event_type(const mtx::events::collections::TimelineEvents &event) event_type(const mtx::events::collections::TimelineEvents &event)
{ {
return mpark::visit([](auto msg) { return msg.type; }, event); return boost::apply_visitor([](auto msg) { return msg.type; }, event);
} }
inline std::string inline std::string
event_id(const mtx::events::collections::TimelineEvents &event) event_id(const mtx::events::collections::TimelineEvents &event)
{ {
return mpark::visit([](auto msg) { return msg.event_id; }, event); return boost::apply_visitor([](auto msg) { return msg.event_id; }, event);
} }
inline QString inline QString
@ -165,14 +167,15 @@ eventId(const mtx::events::collections::TimelineEvents &event)
inline QString inline QString
event_sender(const mtx::events::collections::TimelineEvents &event) event_sender(const mtx::events::collections::TimelineEvents &event)
{ {
return mpark::visit([](auto msg) { return QString::fromStdString(msg.sender); }, event); return boost::apply_visitor([](auto msg) { return QString::fromStdString(msg.sender); },
event);
} }
template<class T> template<class T>
QString QString
message_body(const mtx::events::collections::TimelineEvents &event) message_body(const mtx::events::collections::TimelineEvents &event)
{ {
return QString::fromStdString(mpark::get<T>(event).content.body); return QString::fromStdString(boost::get<T>(event).content.body);
} }
//! Calculate the Levenshtein distance between two strings with character skipping. //! Calculate the Levenshtein distance between two strings with character skipping.

View file

@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <boost/variant.hpp>
#include <QApplication> #include <QApplication>
#include <QFileInfo> #include <QFileInfo>
#include <QTimer> #include <QTimer>
@ -223,8 +225,8 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &
using TextEvent = RoomEvent<msg::Text>; using TextEvent = RoomEvent<msg::Text>;
using VideoEvent = RoomEvent<msg::Video>; using VideoEvent = RoomEvent<msg::Video>;
if (mpark::holds_alternative<RedactionEvent<msg::Redaction>>(event)) { if (boost::get<RedactionEvent<msg::Redaction>>(&event) != nullptr) {
auto redaction_event = mpark::get<RedactionEvent<msg::Redaction>>(event); auto redaction_event = boost::get<RedactionEvent<msg::Redaction>>(event);
const auto event_id = QString::fromStdString(redaction_event.redacts); const auto event_id = QString::fromStdString(redaction_event.redacts);
QTimer::singleShot(0, this, [event_id, this]() { QTimer::singleShot(0, this, [event_id, this]() {
@ -233,8 +235,8 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &
}); });
return nullptr; return nullptr;
} else if (mpark::holds_alternative<StateEvent<state::Encryption>>(event)) { } else if (boost::get<StateEvent<state::Encryption>>(&event) != nullptr) {
auto msg = mpark::get<StateEvent<state::Encryption>>(event); auto msg = boost::get<StateEvent<state::Encryption>>(event);
auto event_id = QString::fromStdString(msg.event_id); auto event_id = QString::fromStdString(msg.event_id);
if (eventIds_.contains(event_id)) if (eventIds_.contains(event_id))
@ -248,32 +250,32 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &
saveMessageInfo("", msg.origin_server_ts, direction); saveMessageInfo("", msg.origin_server_ts, direction);
return item; return item;
} else if (mpark::holds_alternative<RoomEvent<msg::Audio>>(event)) { } else if (boost::get<RoomEvent<msg::Audio>>(&event) != nullptr) {
auto audio = mpark::get<RoomEvent<msg::Audio>>(event); auto audio = boost::get<RoomEvent<msg::Audio>>(event);
return processMessageEvent<AudioEvent, AudioItem>(audio, direction); return processMessageEvent<AudioEvent, AudioItem>(audio, direction);
} else if (mpark::holds_alternative<RoomEvent<msg::Emote>>(event)) { } else if (boost::get<RoomEvent<msg::Emote>>(&event) != nullptr) {
auto emote = mpark::get<RoomEvent<msg::Emote>>(event); auto emote = boost::get<RoomEvent<msg::Emote>>(event);
return processMessageEvent<EmoteEvent>(emote, direction); return processMessageEvent<EmoteEvent>(emote, direction);
} else if (mpark::holds_alternative<RoomEvent<msg::File>>(event)) { } else if (boost::get<RoomEvent<msg::File>>(&event) != nullptr) {
auto file = mpark::get<RoomEvent<msg::File>>(event); auto file = boost::get<RoomEvent<msg::File>>(event);
return processMessageEvent<FileEvent, FileItem>(file, direction); return processMessageEvent<FileEvent, FileItem>(file, direction);
} else if (mpark::holds_alternative<RoomEvent<msg::Image>>(event)) { } else if (boost::get<RoomEvent<msg::Image>>(&event) != nullptr) {
auto image = mpark::get<RoomEvent<msg::Image>>(event); auto image = boost::get<RoomEvent<msg::Image>>(event);
return processMessageEvent<ImageEvent, ImageItem>(image, direction); return processMessageEvent<ImageEvent, ImageItem>(image, direction);
} else if (mpark::holds_alternative<RoomEvent<msg::Notice>>(event)) { } else if (boost::get<RoomEvent<msg::Notice>>(&event) != nullptr) {
auto notice = mpark::get<RoomEvent<msg::Notice>>(event); auto notice = boost::get<RoomEvent<msg::Notice>>(event);
return processMessageEvent<NoticeEvent>(notice, direction); return processMessageEvent<NoticeEvent>(notice, direction);
} else if (mpark::holds_alternative<RoomEvent<msg::Text>>(event)) { } else if (boost::get<RoomEvent<msg::Text>>(&event) != nullptr) {
auto text = mpark::get<RoomEvent<msg::Text>>(event); auto text = boost::get<RoomEvent<msg::Text>>(event);
return processMessageEvent<TextEvent>(text, direction); return processMessageEvent<TextEvent>(text, direction);
} else if (mpark::holds_alternative<RoomEvent<msg::Video>>(event)) { } else if (boost::get<RoomEvent<msg::Video>>(&event) != nullptr) {
auto video = mpark::get<RoomEvent<msg::Video>>(event); auto video = boost::get<RoomEvent<msg::Video>>(event);
return processMessageEvent<VideoEvent, VideoItem>(video, direction); return processMessageEvent<VideoEvent, VideoItem>(video, direction);
} else if (mpark::holds_alternative<Sticker>(event)) { } else if (boost::get<Sticker>(&event) != nullptr) {
return processMessageEvent<Sticker, StickerItem>(mpark::get<Sticker>(event), return processMessageEvent<Sticker, StickerItem>(boost::get<Sticker>(event),
direction); direction);
} else if (mpark::holds_alternative<EncryptedEvent<msg::Encrypted>>(event)) { } else if (boost::get<EncryptedEvent<msg::Encrypted>>(&event) != nullptr) {
auto res = parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event)); auto res = parseEncryptedEvent(boost::get<EncryptedEvent<msg::Encrypted>>(event));
auto widget = parseMessageEvent(res.event, direction); auto widget = parseMessageEvent(res.event, direction);
if (widget == nullptr) if (widget == nullptr)