Merge pull request #2114 from famedly/krille/fix-relogin-with-same-client
fix: Can not logout and login again with same Client object
This commit is contained in:
commit
1991098b2f
|
|
@ -37,7 +37,7 @@ jobs:
|
|||
|
||||
coverage_without_olm:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
timeout-minutes: 10
|
||||
env:
|
||||
NO_OLM: 1
|
||||
steps:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue