diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/database.cpp | 14 | ||||
-rw-r--r-- | lib/database.h | 1 | ||||
-rw-r--r-- | lib/room.cpp | 4 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/database.cpp b/lib/database.cpp index 41e62935..665b931a 100644 --- a/lib/database.cpp +++ b/lib/database.cpp @@ -14,8 +14,6 @@ #include "e2ee/qolmsession.h" #include "e2ee/qolminboundsession.h" -//TODO: delete room specific data when leaving room - using namespace Quotient; Database::Database(const QString& matrixId, QObject* parent) : QObject(parent) @@ -229,3 +227,15 @@ QSqlQuery Database::prepareQuery(const QString& queryString) query.prepare(queryString); return query; } + +void Database::clearRoomData(const QString& roomId) +{ + auto query = prepareQuery(QStringLiteral("DELETE FROM inbound_megolm_sessions WHERE roomId=:roomId;")); + auto query2 = prepareQuery(QStringLiteral("DELETE FROM outbound_megolm_sessions WHERE roomId=:roomId;")); + auto query3 = prepareQuery(QStringLiteral("DELETE FROM group_session_record_index WHERE roomId=:roomId;")); + transaction(); + execute(query); + execute(query2); + execute(query3); + commit(); +} diff --git a/lib/database.h b/lib/database.h index fbb940c8..b2187ba4 100644 --- a/lib/database.h +++ b/lib/database.h @@ -34,6 +34,7 @@ public: void saveMegolmSession(const QString& roomId, const QString& senderKey, const QString& sessionKey, const QByteArray& pickle); void addGroupSessionIndexRecord(const QString& roomId, const QString& sessionId, uint32_t index, const QString& eventId, qint64 ts); QPair<QString, qint64> groupSessionIndexRecord(const QString& roomId, const QString& sessionId, qint64 index); + void clearRoomData(const QString& roomId); private: void migrateTo1(); diff --git a/lib/room.cpp b/lib/room.cpp index 0a4fcc68..a46892f3 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -461,6 +461,10 @@ Room::Room(Connection* connection, QString id, JoinState initialJoinState) } }); d->loadMegOlmSessions(); + + connect(this, &Room::beforeDestruction, this, [=](){ + connection->database()->clearRoomData(id); + }); #endif qCDebug(STATE) << "New" << terse << initialJoinState << "Room:" << id; } |