summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-01-03 15:33:36 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-01-03 15:33:36 +0100
commit970ed56fa5bece0dc2363c1bc73ca2df97650cce (patch)
treed88e5d7d6dd58787a139a2fc89bbfd66039070fd /src
parentUpdate translations (diff)
downloadnheko-970ed56fa5bece0dc2363c1bc73ca2df97650cce.tar.xz
Fix presence db creation on servers without presence
fixes #873
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp17
-rw-r--r--src/Cache_p.h3
2 files changed, 9 insertions, 11 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp

index d04da275..5a08ad27 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp
@@ -66,6 +66,7 @@ constexpr auto SYNC_STATE_DB("sync_state"); //! Read receipts per room/event. constexpr auto READ_RECEIPTS_DB("read_receipts"); constexpr auto NOTIFICATIONS_DB("sent_notifications"); +constexpr auto PRESENCE_DB("presence"); //! Encryption related databases. @@ -293,6 +294,7 @@ Cache::setup() invitesDb_ = lmdb::dbi::open(txn, INVITES_DB, MDB_CREATE); readReceiptsDb_ = lmdb::dbi::open(txn, READ_RECEIPTS_DB, MDB_CREATE); notificationsDb_ = lmdb::dbi::open(txn, NOTIFICATIONS_DB, MDB_CREATE); + presenceDb_ = lmdb::dbi::open(txn, PRESENCE_DB, MDB_CREATE); // Device management devicesDb_ = lmdb::dbi::open(txn, DEVICES_DB, MDB_CREATE); @@ -1701,9 +1703,7 @@ Cache::savePresence( const std::vector<mtx::events::Event<mtx::events::presence::Presence>> &presenceUpdates) { for (const auto &update : presenceUpdates) { - auto presenceDb = getPresenceDb(txn); - - presenceDb.put(txn, update.sender, json(update.content).dump()); + presenceDb_.put(txn, update.sender, json(update.content).dump()); } } @@ -3905,17 +3905,16 @@ Cache::avatarUrl(const QString &room_id, const QString &user_id) mtx::events::presence::Presence Cache::presence(const std::string &user_id) { + mtx::events::presence::Presence presence_{}; + presence_.presence = mtx::presence::PresenceState::offline; + if (user_id.empty()) - return {}; + return presence_; std::string_view presenceVal; auto txn = ro_txn(env_); - auto db = getPresenceDb(txn); - auto res = db.get(txn, user_id, presenceVal); - - mtx::events::presence::Presence presence_{}; - presence_.presence = mtx::presence::PresenceState::offline; + auto res = presenceDb_.get(txn, user_id, presenceVal); if (res) { presence_ = json::parse(std::string_view(presenceVal.data(), presenceVal.size())); diff --git a/src/Cache_p.h b/src/Cache_p.h
index 9270e191..b30e8f47 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h
@@ -638,8 +638,6 @@ private: return lmdb::dbi::open(txn, std::string(room_id + "/mentions").c_str(), MDB_CREATE); } - lmdb::dbi getPresenceDb(lmdb::txn &txn) { return lmdb::dbi::open(txn, "presence", MDB_CREATE); } - lmdb::dbi getUserKeysDb(lmdb::txn &txn) { return lmdb::dbi::open(txn, "user_key", MDB_CREATE); } lmdb::dbi getVerificationDb(lmdb::txn &txn) @@ -678,6 +676,7 @@ private: lmdb::dbi invitesDb_; lmdb::dbi readReceiptsDb_; lmdb::dbi notificationsDb_; + lmdb::dbi presenceDb_; lmdb::dbi devicesDb_; lmdb::dbi deviceKeysDb_;