summary refs log tree commit diff
path: root/src/ChatPage.cpp
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2020-05-03 01:56:06 +0200
committerGitHub <noreply@github.com>2020-05-03 01:56:06 +0200
commitccd55c70df1ad57c848e06944d8eef49dc85cdec (patch)
treea9bfae6a1cd69ddde2c076e04b181c2adc1062fd /src/ChatPage.cpp
parentMerge pull request #184 from shocklateboy92/features/backlog-progress (diff)
parentAdd delete pending_receipts migration (diff)
downloadnheko-ccd55c70df1ad57c848e06944d8eef49dc85cdec.tar.xz
Merge pull request #189 from Nheko-Reborn/db-migrations
Db migrations
Diffstat (limited to 'src/ChatPage.cpp')
-rw-r--r--src/ChatPage.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp

index 981e6b80..689e9ca4 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp
@@ -17,6 +17,7 @@ #include <QApplication> #include <QImageReader> +#include <QMessageBox> #include <QSettings> #include <QShortcut> #include <QtConcurrent> @@ -642,20 +643,37 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token) &NotificationsManager::removeNotification); const bool isInitialized = cache::isInitialized(); - const bool isValid = cache::isFormatValid(); + const auto cacheVersion = cache::formatVersion(); if (!isInitialized) { cache::setCurrentFormat(); - } else if (isInitialized && !isValid) { - // TODO: Deleting session data but keep using the - // same device doesn't work. - cache::deleteData(); - - cache::init(userid); - cache::setCurrentFormat(); - } else if (isInitialized) { - loadStateFromCache(); - return; + } else { + if (cacheVersion == cache::CacheVersion::Current) { + loadStateFromCache(); + return; + } else if (cacheVersion == cache::CacheVersion::Older) { + if (!cache::runMigrations()) { + QMessageBox::critical( + this, + tr("Cache migration failed!"), + tr("Migrating the cache to the current version failed. " + "This can have different reasons. Please open an " + "issue and try to use an older version in the mean " + "time. Alternatively you can try deleting the cache " + "manually")); + QCoreApplication::quit(); + } + loadStateFromCache(); + return; + } else if (cacheVersion == cache::CacheVersion::Newer) { + QMessageBox::critical( + this, + tr("Incompatible cache version"), + tr("The cache on your disk is newer than this version of Nheko " + "supports. Please update or clear your cache.")); + QCoreApplication::quit(); + return; + } } } catch (const lmdb::error &e) {