fix: (BREAKING) Can not logout and login again with same Client object

This commit is contained in:
Christian Kußowski 2025-07-10 12:18:36 +02:00
parent 12c6c082fc
commit 3129f7cb47
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
3 changed files with 32 additions and 5 deletions

View File

@ -37,7 +37,7 @@ jobs:
coverage_without_olm:
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 10
env:
NO_OLM: 1
steps:

View File

@ -68,7 +68,16 @@ class Client extends MatrixApi {
final FutureOr<DatabaseApi> 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<KeyVerificationMethod>? verificationMethods,
http.Client? httpClient,
@ -221,7 +230,8 @@ class Client extends MatrixApi {
/// <br/> 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();
}

View File

@ -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 {