Properly clean stale invites

pull/1/head
Konstantinos Sideris 7 years ago
parent 6d0bc0c05e
commit c0e355f485
  1. 7
      include/Cache.h
  2. 17
      src/Cache.cc

@ -155,6 +155,7 @@ public:
void deleteData(); void deleteData();
void removeInvite(lmdb::txn &txn, const std::string &room_id);
void removeInvite(const std::string &room_id); void removeInvite(const std::string &room_id);
void removeRoom(lmdb::txn &txn, const std::string &roomid); void removeRoom(lmdb::txn &txn, const std::string &roomid);
void removeRoom(const std::string &roomid); void removeRoom(const std::string &roomid);
@ -335,8 +336,12 @@ private:
void removeLeftRooms(lmdb::txn &txn, void removeLeftRooms(lmdb::txn &txn,
const std::map<std::string, mtx::responses::LeftRoom> &rooms) const std::map<std::string, mtx::responses::LeftRoom> &rooms)
{ {
for (const auto &room : rooms) for (const auto &room : rooms) {
removeRoom(txn, room.first); removeRoom(txn, room.first);
// Clean up leftover invites.
removeInvite(txn, room.first);
}
} }
lmdb::dbi getInviteStatesDb(lmdb::txn &txn, const std::string &room_id) lmdb::dbi getInviteStatesDb(lmdb::txn &txn, const std::string &room_id)

@ -39,7 +39,7 @@ static const lmdb::val CACHE_FORMAT_VERSION_KEY("cache_format_version");
//! Contains UI information for the joined rooms. (i.e name, topic, avatar url etc). //! Contains UI information for the joined rooms. (i.e name, topic, avatar url etc).
//! Format: room_id -> RoomInfo //! Format: room_id -> RoomInfo
static constexpr const char *ROOMS_DB = "rooms"; static constexpr const char *ROOMS_DB = "rooms";
static constexpr const char *INVITES_DB = "rooms"; static constexpr const char *INVITES_DB = "invites";
//! Keeps already downloaded media for reuse. //! Keeps already downloaded media for reuse.
//! Format: matrix_url -> binary data. //! Format: matrix_url -> binary data.
static constexpr const char *MEDIA_DB = "media"; static constexpr const char *MEDIA_DB = "media";
@ -169,11 +169,19 @@ Cache::image(const QString &url) const
return QByteArray(); return QByteArray();
} }
void
Cache::removeInvite(lmdb::txn &txn, const std::string &room_id)
{
lmdb::dbi_del(txn, invitesDb_, lmdb::val(room_id), nullptr);
lmdb::dbi_drop(txn, getInviteStatesDb(txn, room_id), true);
lmdb::dbi_drop(txn, getInviteMembersDb(txn, room_id), true);
}
void void
Cache::removeInvite(const std::string &room_id) Cache::removeInvite(const std::string &room_id)
{ {
auto txn = lmdb::txn::begin(env_); auto txn = lmdb::txn::begin(env_);
lmdb::dbi_del(txn, invitesDb_, lmdb::val(room_id), nullptr); removeInvite(txn, room_id);
txn.commit(); txn.commit();
} }
@ -181,6 +189,8 @@ void
Cache::removeRoom(lmdb::txn &txn, const std::string &roomid) Cache::removeRoom(lmdb::txn &txn, const std::string &roomid)
{ {
lmdb::dbi_del(txn, roomsDb_, lmdb::val(roomid), nullptr); lmdb::dbi_del(txn, roomsDb_, lmdb::val(roomid), nullptr);
lmdb::dbi_drop(txn, getStatesDb(txn, roomid), true);
lmdb::dbi_drop(txn, getMembersDb(txn, roomid), true);
} }
void void
@ -386,6 +396,9 @@ Cache::saveState(const mtx::responses::Sync &res)
txn, roomsDb_, lmdb::val(room.first), lmdb::val(json(updatedInfo).dump())); txn, roomsDb_, lmdb::val(room.first), lmdb::val(json(updatedInfo).dump()));
updateReadReceipt(txn, room.first, room.second.ephemeral.receipts); updateReadReceipt(txn, room.first, room.second.ephemeral.receipts);
// Clean up non-valid invites.
removeInvite(txn, room.first);
} }
saveInvites(txn, res.rooms.invite); saveInvites(txn, res.rooms.invite);

Loading…
Cancel
Save