From 7ecabcd61410783267f1ef4353d65716b84f7f83 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 18 Jun 2018 18:36:19 +0300 Subject: [PATCH] Mark encrypted rooms when processing room state --- include/Cache.h | 7 ++++++- src/Cache.cc | 6 ++---- src/timeline/TimelineView.cc | 7 ------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/Cache.h b/include/Cache.h index f5a655cf..3d906f02 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -29,6 +29,8 @@ #include #include +#include "Logging.hpp" + using mtx::events::state::JoinRule; struct RoomMember @@ -345,7 +347,7 @@ public: bool isNotificationSent(const std::string &event_id); //! Mark a room that uses e2e encryption. - void setEncryptedRoom(const std::string &room_id); + void setEncryptedRoom(lmdb::txn &txn, const std::string &room_id); bool isRoomEncrypted(const std::string &room_id); //! Save the public keys for a device. @@ -467,6 +469,9 @@ private: } } + return; + } else if (mpark::holds_alternative>(event)) { + setEncryptedRoom(txn, room_id); return; } diff --git a/src/Cache.cc b/src/Cache.cc index 397dd05f..ed4194ec 100644 --- a/src/Cache.cc +++ b/src/Cache.cc @@ -183,14 +183,12 @@ Cache::setup() } void -Cache::setEncryptedRoom(const std::string &room_id) +Cache::setEncryptedRoom(lmdb::txn &txn, const std::string &room_id) { nhlog::db()->info("mark room {} as encrypted", room_id); - auto txn = lmdb::txn::begin(env_); - auto db = lmdb::dbi::open(txn, ENCRYPTED_ROOMS_DB, MDB_CREATE); + auto db = lmdb::dbi::open(txn, ENCRYPTED_ROOMS_DB, MDB_CREATE); lmdb::dbi_put(txn, db, lmdb::val(room_id), lmdb::val("0")); - txn.commit(); } bool diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 270e1d9a..d99b3a37 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -284,13 +284,6 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents & auto decrypted = parseEncryptedEvent(mpark::get>(event)); return parseMessageEvent(decrypted, direction); - } else if (mpark::holds_alternative>(event)) { - try { - cache::client()->setEncryptedRoom(room_id_.toStdString()); - } catch (const lmdb::error &e) { - nhlog::db()->critical("failed to save room {} as encrypted", - room_id_.toStdString()); - } } return nullptr;