From dad2de7ba2323ff0f5c229968ec95f05b10b6f45 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 2 May 2020 16:44:50 +0200 Subject: [PATCH] Add support for db migrations --- resources/langs/nheko_de.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_el.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_en.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_fi.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_fr.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_ja.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_nl.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_pl.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_ru.ts | 46 ++++++++++++++++++++++++---------- resources/langs/nheko_zh_CN.ts | 46 ++++++++++++++++++++++++---------- src/Cache.cpp | 36 +++++++++++++++++--------- src/Cache.h | 9 +++++-- src/CacheStructs.h | 9 +++++++ src/Cache_p.h | 3 ++- src/ChatPage.cpp | 40 +++++++++++++++++++++-------- 15 files changed, 401 insertions(+), 156 deletions(-) diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index a97c3fb3..3f9cdc52 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 Nutzer konnte nicht eingeladen werden: %1 - + Invited user: %1 Eingeladener Benutzer: %1 @@ -50,12 +50,32 @@ Verbannung von %1 wurde aufgehoben. - + Failed to upload media. Please try again. Medienupload fehlgeschlagen. Bitte versuche es erneut. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. Wiederherstellung des OLM Accounts fehlgeschlagen. Bitte logge dich erneut ein. @@ -71,7 +91,7 @@ - + Please try to login again: %1 Bitte melde dich erneut an: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored keine Version gespeichert @@ -368,7 +388,7 @@ Raum verlassen - + Accept Akzeptieren @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- Entschlüsselungsfehler (Fehler bei Kommunikation mit Datenbank) -- @@ -489,7 +509,7 @@ -- Entschlüsselungsfehler (%1) -- - + Message redaction failed: %1 Nachricht zurückziehen fehlgeschlagen: %1 @@ -514,7 +534,7 @@ Datei speichern - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- Verschlüsseltes Event (keine Schlüssel zur Entschlüsselung gefunden) -- @@ -526,7 +546,7 @@ -- Verschlüsseltes Event (Unbekannter Eventtyp) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +697,7 @@ TimelineView - + Reply Antworten @@ -971,7 +991,7 @@ descriptiveTime - + Yesterday Gestern diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 1f4c355c..7cd94593 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. @@ -71,7 +91,7 @@ - + Please try to login again: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored @@ -368,7 +388,7 @@ Βγές - + Accept Αποδοχή @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. @@ -489,7 +509,7 @@ - + Message redaction failed: %1 @@ -514,7 +534,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. @@ -526,7 +546,7 @@ - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +697,7 @@ TimelineView - + Reply @@ -971,7 +991,7 @@ descriptiveTime - + Yesterday diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index 52eb4a4c..10295fcf 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 Failed to invite user: %1 - + Invited user: %1 Invited user: %1 @@ -50,12 +50,32 @@ Unbanned user: %1 - + Failed to upload media. Please try again. Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. Failed to restore OLM account. Please login again. @@ -71,7 +91,7 @@ - + Please try to login again: %1 Please try to login again: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored no version stored @@ -368,7 +388,7 @@ Leave room - + Accept Accept @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- Decryption Error (failed to communicate with DB) -- @@ -489,7 +509,7 @@ -- Decryption Error (%1) -- - + Message redaction failed: %1 Message redaction failed: %1 @@ -514,7 +534,7 @@ Save file - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- Encrypted Event (No keys found for decryption) -- @@ -526,7 +546,7 @@ -- Encrypted Event (Unknown event type) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +697,7 @@ TimelineView - + Reply Reply @@ -971,7 +991,7 @@ descriptiveTime - + Yesterday Yesterday diff --git a/resources/langs/nheko_fi.ts b/resources/langs/nheko_fi.ts index 3ab797d8..0f0cf1ac 100644 --- a/resources/langs/nheko_fi.ts +++ b/resources/langs/nheko_fi.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. OLM-tilin palauttaminen epäonnistui. Ole hyvä ja kirjaudu sisään uudelleen. @@ -71,7 +91,7 @@ - + Please try to login again: %1 Ole hyvä ja yritä kirjautua sisään uudelleen: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored ei tallennettua versiota @@ -368,7 +388,7 @@ Poistu huoneesta - + Accept Hyväksy @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- Virhe purkaessa salausta (tietokannan kanssa kommunikointi epäonnistui) -- @@ -489,7 +509,7 @@ -- Virhe purkaessa salausta (%1) -- - + Message redaction failed: %1 Viestin poisto epäonnistui: %1 @@ -514,7 +534,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- Salattu viesti (salauksen purkuavaimia ei löydetty) -- @@ -526,7 +546,7 @@ -- Salattu viesti (tuntematon viestityyppi) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +697,7 @@ TimelineView - + Reply @@ -971,7 +991,7 @@ descriptiveTime - + Yesterday Eilen diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index f90ff8c0..3668e53e 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. @@ -71,7 +91,7 @@ - + Please try to login again: %1 @@ -356,7 +376,7 @@ RoomInfo - + no version stored @@ -369,7 +389,7 @@ Quitter le salon - + Accept Accepter @@ -472,7 +492,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. @@ -490,7 +510,7 @@ - + Message redaction failed: %1 @@ -515,7 +535,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. @@ -527,7 +547,7 @@ - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -678,7 +698,7 @@ TimelineView - + Reply @@ -972,7 +992,7 @@ descriptiveTime - + Yesterday diff --git a/resources/langs/nheko_ja.ts b/resources/langs/nheko_ja.ts index 884ca357..c6f38fed 100644 --- a/resources/langs/nheko_ja.ts +++ b/resources/langs/nheko_ja.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 ユーザーを招待できませんでした: %1 - + Invited user: %1 招待されたユーザー: %1 @@ -50,12 +50,32 @@ 永久追放を解除されたユーザー: %1 - + Failed to upload media. Please try again. メディアをアップロードできませんでした。やり直して下さい。 - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. OLMアカウントを復元できませんでした。もう一度ログインして下さい。 @@ -71,7 +91,7 @@ - + Please try to login again: %1 もう一度ログインしてみて下さい: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored バージョンが保存されていません @@ -368,7 +388,7 @@ 部屋を出る - + Accept 容認 @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- 復号エラー (データベースと通信できませんでした) -- @@ -489,7 +509,7 @@ -- 復号エラー (%1) -- - + Message redaction failed: %1 メッセージを編集できませんでした: %1 @@ -514,7 +534,7 @@ ファイルを保存 - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- 暗号化イベント (復号鍵が見つかりません) -- @@ -526,7 +546,7 @@ -- 暗号化イベント (不明なイベント型です) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -676,7 +696,7 @@ TimelineView - + Reply 返信 @@ -970,7 +990,7 @@ descriptiveTime - + Yesterday 昨日 diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index 88b25e7f..f70e1fef 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. @@ -71,7 +91,7 @@ - + Please try to login again: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored @@ -368,7 +388,7 @@ Kamer verlaten - + Accept Accepteren @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. @@ -489,7 +509,7 @@ - + Message redaction failed: %1 @@ -514,7 +534,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. @@ -526,7 +546,7 @@ - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +697,7 @@ TimelineView - + Reply @@ -971,7 +991,7 @@ descriptiveTime - + Yesterday diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index 749e172b..07ecf4a4 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. Nie udało się przywrócić konta OLM. Spróbuj zalogować się ponownie. @@ -71,7 +91,7 @@ - + Please try to login again: %1 Spróbuj zalogować się ponownie: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored @@ -368,7 +388,7 @@ Opuść pokój - + Accept Akceptuj @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. @@ -489,7 +509,7 @@ - + Message redaction failed: %1 Redagowanie wiadomości nie powiodło się: %1 @@ -514,7 +534,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. @@ -526,7 +546,7 @@ - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -678,7 +698,7 @@ TimelineView - + Reply @@ -972,7 +992,7 @@ descriptiveTime - + Yesterday diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index 05240613..25abbe40 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. Не удалось восстановить учетную запись OLM. Пожалуйста, войдите снова. @@ -71,7 +91,7 @@ - + Please try to login again: %1 Повторите попытку входа: %1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored @@ -368,7 +388,7 @@ Покинуть комнату - + Accept Принять @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. @@ -489,7 +509,7 @@ - + Message redaction failed: %1 Ошибка редактирования сообщения: %1 @@ -514,7 +534,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. @@ -526,7 +546,7 @@ - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -678,7 +698,7 @@ TimelineView - + Reply @@ -973,7 +993,7 @@ descriptiveTime - + Yesterday diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index b6fe6d1d..ddd8c017 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -4,13 +4,13 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 @@ -50,12 +50,32 @@ - + Failed to upload media. Please try again. - + + Cache migration failed! + + + + + 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 + + + + + Incompatible cache version + + + + + The cache on your disk is newer than this version of Nheko supports. Please update or clear your cache. + + + + Failed to restore OLM account. Please login again. 恢复 OLM 账户失败。请重新登录。 @@ -71,7 +91,7 @@ - + Please try to login again: %1 请尝试再次登录:%1 @@ -355,7 +375,7 @@ RoomInfo - + no version stored @@ -368,7 +388,7 @@ 离开聊天室 - + Accept 接受 @@ -471,7 +491,7 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. @@ -489,7 +509,7 @@ - + Message redaction failed: %1 删除消息失败:%1 @@ -514,7 +534,7 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. @@ -526,7 +546,7 @@ - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -676,7 +696,7 @@ TimelineView - + Reply @@ -970,7 +990,7 @@ descriptiveTime - + Yesterday diff --git a/src/Cache.cpp b/src/Cache.cpp index eb5c93aa..1a097cff 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -665,8 +665,15 @@ Cache::deleteData() } } +//! migrates db to the current format bool -Cache::isFormatValid() +Cache::runMigrations() +{ + return true; +} + +cache::CacheVersion +Cache::formatVersion() { auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); @@ -676,18 +683,16 @@ Cache::isFormatValid() txn.commit(); if (!res) - return false; + return cache::CacheVersion::Older; std::string stored_version(current_version.data(), current_version.size()); - if (stored_version != CURRENT_CACHE_FORMAT_VERSION) { - nhlog::db()->warn("breaking changes in the cache format. stored: {}, current: {}", - stored_version, - CURRENT_CACHE_FORMAT_VERSION); - return false; - } - - return true; + if (stored_version < CURRENT_CACHE_FORMAT_VERSION) + return cache::CacheVersion::Older; + else if (stored_version > CURRENT_CACHE_FORMAT_VERSION) + return cache::CacheVersion::Older; + else + return cache::CacheVersion::Current; } void @@ -2468,10 +2473,17 @@ setup() } bool -isFormatValid() +runMigrations() { - return instance_->isFormatValid(); + return instance_->runMigrations(); } + +cache::CacheVersion +formatVersion() +{ + return instance_->formatVersion(); +} + void setCurrentFormat() { diff --git a/src/Cache.h b/src/Cache.h index 99c63550..12465c9d 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -111,10 +111,15 @@ removeRoom(const QString &roomid); void setup(); -bool -isFormatValid(); +//! returns if the format is current, older or newer +cache::CacheVersion +formatVersion(); +//! set the format version to the current version void setCurrentFormat(); +//! migrates db to the current format +bool +runMigrations(); std::map roomMessages(); diff --git a/src/CacheStructs.h b/src/CacheStructs.h index ab7bbc71..ef08cfcb 100644 --- a/src/CacheStructs.h +++ b/src/CacheStructs.h @@ -8,6 +8,15 @@ #include +namespace cache { +enum class CacheVersion : int +{ + Older = -1, + Current = 0, + Newer = 1, +}; +} + struct RoomMember { QString user_id; diff --git a/src/Cache_p.h b/src/Cache_p.h index 982099ea..0d66a608 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -102,8 +102,9 @@ public: void removeRoom(const std::string &roomid); void setup(); - bool isFormatValid(); + cache::CacheVersion formatVersion(); void setCurrentFormat(); + bool runMigrations(); std::map roomMessages(); 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 #include +#include #include #include #include @@ -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) {