From 86766b739d634adcaa3953c78510d5b10fa88835 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 15 Mar 2021 17:11:02 +0100 Subject: Store all state events --- src/Cache.cpp | 20 ++++++++++++++++++ src/Cache_p.h | 67 +++++++++++++++-------------------------------------------- src/Olm.cpp | 2 +- 3 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index cfc6a727..ec0f2858 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -91,6 +91,26 @@ namespace { std::unique_ptr instance_ = nullptr; } +template +bool +containsStateUpdates(const T &e) +{ + return std::visit([](const auto &ev) { return Cache::isStateEvent(ev); }, e); +} + +bool +containsStateUpdates(const mtx::events::collections::StrippedEvents &e) +{ + using namespace mtx::events; + using namespace mtx::events::state; + + return std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e); +} + bool Cache::isHiddenEvent(lmdb::txn &txn, mtx::events::collections::TimelineEvents e, diff --git a/src/Cache_p.h b/src/Cache_p.h index b6c555dc..473c6319 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -271,6 +271,17 @@ public: void deleteSecret(const std::string &name); std::optional secret(const std::string &name); + template + static constexpr bool isStateEvent(const mtx::events::StateEvent &) + { + return true; + } + template + static constexpr bool isStateEvent(const mtx::events::Event &) + { + return false; + } + signals: void newReadReceipts(const QString &room_id, const std::vector &event_ids); void roomReadStatus(const std::map &status); @@ -368,56 +379,12 @@ private: return; } - if (!isStateEvent(event)) - return; - - std::visit([&txn, &statesdb]( - auto e) { statesdb.put(txn, to_string(e.type), json(e).dump()); }, - event); - } - - template - bool isStateEvent(const T &e) - { - using namespace mtx::events; - using namespace mtx::events::state; - - return std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e); - } - - template - bool containsStateUpdates(const T &e) - { - using namespace mtx::events; - using namespace mtx::events::state; - - return std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e); - } - - bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e) - { - using namespace mtx::events; - using namespace mtx::events::state; - - return std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e) || - std::holds_alternative>(e); + std::visit( + [&txn, &statesdb](auto e) { + if constexpr (isStateEvent(e)) + statesdb.put(txn, to_string(e.type), json(e).dump()); + }, + event); } void saveInvites(lmdb::txn &txn, diff --git a/src/Olm.cpp b/src/Olm.cpp index d2f78b76..895afee4 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -430,7 +430,7 @@ encrypt_group_message(const std::string &room_id, const std::string &device_id, OutboundGroupSessionData group_session_data; if (cache::outboundMegolmSessionExists(room_id)) { - auto res = cache::getOutboundMegolmSession(room_id); + auto res = cache::getOutboundMegolmSession(room_id); auto encryptionSettings = cache::client()->roomEncryptionSettings(room_id); mtx::events::state::Encryption defaultSettings; -- cgit 1.4.1