diff --git a/include/Cache.h b/include/Cache.h index 46107062..1be56620 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include "RoomState.h" @@ -32,6 +33,7 @@ public: QString nextBatchToken() const; QMap states(); + inline void deleteData(); inline void unmount(); inline QString memberDbName(const QString &roomid); @@ -46,6 +48,7 @@ private: bool isMounted_; QString userId_; + QString cacheDirectory_; }; inline void @@ -59,3 +62,10 @@ Cache::memberDbName(const QString &roomid) { return QString("m.%1").arg(roomid); } + +inline void +Cache::deleteData() +{ + if (!cacheDirectory_.isEmpty()) + QDir(cacheDirectory_).removeRecursively(); +} diff --git a/src/Cache.cc b/src/Cache.cc index 01df492c..6733428e 100644 --- a/src/Cache.cc +++ b/src/Cache.cc @@ -83,7 +83,10 @@ Cache::Cache(const QString &userId) txn.commit(); - isMounted_ = true; + isMounted_ = true; + cacheDirectory_ = QString("%1/%2") + .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) + .arg(QString::fromUtf8(userId_.toUtf8().toHex())); } void diff --git a/src/ChatPage.cc b/src/ChatPage.cc index d199f98c..9bbf58b7 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -194,6 +194,8 @@ ChatPage::logout() settings.remove(""); settings.endGroup(); + cache_->deleteData(); + // Clear the environment. room_list_->clear(); view_manager_->clearAll();