diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index e916e2d9..b8383ee7 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -37,7 +37,7 @@ jobs: coverage_without_olm: runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 10 env: NO_OLM: 1 steps: diff --git a/lib/src/client.dart b/lib/src/client.dart index ba92e608..15fd29c0 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -68,7 +68,16 @@ class Client extends MatrixApi { final FutureOr Function(Client)? legacyDatabaseBuilder; - final DatabaseApi database; + DatabaseApi _database; + + DatabaseApi get database => _database; + + set database(DatabaseApi db) { + if (isLogged()) { + throw Exception('You can not switch the database while being logged in!'); + } + _database = db; + } Encryption? get encryption => _encryption; Encryption? _encryption; @@ -174,7 +183,7 @@ class Client extends MatrixApi { /// Set [enableDehydratedDevices] to enable experimental support for enabling MSC3814 dehydrated devices. Client( this.clientName, { - required this.database, + required DatabaseApi database, this.legacyDatabaseBuilder, Set? verificationMethods, http.Client? httpClient, @@ -221,7 +230,8 @@ class Client extends MatrixApi { ///
tags: this.convertLinebreaksInFormatting = true, this.dehydratedDeviceDisplayName = 'Dehydrated Device', - }) : syncFilter = syncFilter ?? + }) : _database = database, + syncFilter = syncFilter ?? Filter( room: RoomFilter( state: StateFilter(lazyLoadMembers: true), @@ -2199,9 +2209,9 @@ class Client extends MatrixApi { _backgroundSync = true; } catch (e, s) { Logs().e('Unable to clear database', e, s); - } finally { await database.delete(); await legacyDatabase?.delete(); + legacyDatabase = null; await dispose(); } diff --git a/test/client_test.dart b/test/client_test.dart index 1f5f80ea..dfb28580 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -59,6 +59,7 @@ void main() { test('logout', () async { expect(await File(dbPath).exists(), true); await clientOnPath.logout(); + await clientOnPath.database.delete(); expect(await File(dbPath).exists(), false); }); }); @@ -116,6 +117,22 @@ void main() { expect(client.isLogged(), true); await client.logout(); + + expect(client.isLogged(), false); + + await client.login( + LoginType.mLoginPassword, + token: 'abcd', + identifier: + AuthenticationUserIdentifier(user: '@test:fakeServer.notExisting'), + deviceId: 'GHTYAJCE', + onInitStateChanged: initStates.add, + ); + expect(client.isLogged(), true); + + await client.logout(); + + expect(client.isLogged(), false); }); test('Login', () async {