Mark encrypted rooms when processing room state

This commit is contained in:
Konstantinos Sideris 2018-06-18 18:36:19 +03:00
parent 604cdcec8a
commit 7ecabcd614
3 changed files with 8 additions and 12 deletions

View file

@ -29,6 +29,8 @@
#include <mtxclient/crypto/client.hpp> #include <mtxclient/crypto/client.hpp>
#include <mutex> #include <mutex>
#include "Logging.hpp"
using mtx::events::state::JoinRule; using mtx::events::state::JoinRule;
struct RoomMember struct RoomMember
@ -345,7 +347,7 @@ public:
bool isNotificationSent(const std::string &event_id); bool isNotificationSent(const std::string &event_id);
//! Mark a room that uses e2e encryption. //! 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); bool isRoomEncrypted(const std::string &room_id);
//! Save the public keys for a device. //! Save the public keys for a device.
@ -467,6 +469,9 @@ private:
} }
} }
return;
} else if (mpark::holds_alternative<StateEvent<Encryption>>(event)) {
setEncryptedRoom(txn, room_id);
return; return;
} }

View file

@ -183,14 +183,12 @@ Cache::setup()
} }
void 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); 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")); lmdb::dbi_put(txn, db, lmdb::val(room_id), lmdb::val("0"));
txn.commit();
} }
bool bool

View file

@ -284,13 +284,6 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &
auto decrypted = auto decrypted =
parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event)); parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event));
return parseMessageEvent(decrypted, direction); return parseMessageEvent(decrypted, direction);
} else if (mpark::holds_alternative<StateEvent<state::Encryption>>(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; return nullptr;