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:
|
coverage_without_olm:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 5
|
timeout-minutes: 10
|
||||||
env:
|
env:
|
||||||
NO_OLM: 1
|
NO_OLM: 1
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,16 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
final FutureOr<DatabaseApi> Function(Client)? legacyDatabaseBuilder;
|
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? get encryption => _encryption;
|
||||||
Encryption? _encryption;
|
Encryption? _encryption;
|
||||||
|
|
@ -174,7 +183,7 @@ class Client extends MatrixApi {
|
||||||
/// Set [enableDehydratedDevices] to enable experimental support for enabling MSC3814 dehydrated devices.
|
/// Set [enableDehydratedDevices] to enable experimental support for enabling MSC3814 dehydrated devices.
|
||||||
Client(
|
Client(
|
||||||
this.clientName, {
|
this.clientName, {
|
||||||
required this.database,
|
required DatabaseApi database,
|
||||||
this.legacyDatabaseBuilder,
|
this.legacyDatabaseBuilder,
|
||||||
Set<KeyVerificationMethod>? verificationMethods,
|
Set<KeyVerificationMethod>? verificationMethods,
|
||||||
http.Client? httpClient,
|
http.Client? httpClient,
|
||||||
|
|
@ -221,7 +230,8 @@ class Client extends MatrixApi {
|
||||||
/// <br/> tags:
|
/// <br/> tags:
|
||||||
this.convertLinebreaksInFormatting = true,
|
this.convertLinebreaksInFormatting = true,
|
||||||
this.dehydratedDeviceDisplayName = 'Dehydrated Device',
|
this.dehydratedDeviceDisplayName = 'Dehydrated Device',
|
||||||
}) : syncFilter = syncFilter ??
|
}) : _database = database,
|
||||||
|
syncFilter = syncFilter ??
|
||||||
Filter(
|
Filter(
|
||||||
room: RoomFilter(
|
room: RoomFilter(
|
||||||
state: StateFilter(lazyLoadMembers: true),
|
state: StateFilter(lazyLoadMembers: true),
|
||||||
|
|
@ -2199,9 +2209,9 @@ class Client extends MatrixApi {
|
||||||
_backgroundSync = true;
|
_backgroundSync = true;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('Unable to clear database', e, s);
|
Logs().e('Unable to clear database', e, s);
|
||||||
} finally {
|
|
||||||
await database.delete();
|
await database.delete();
|
||||||
await legacyDatabase?.delete();
|
await legacyDatabase?.delete();
|
||||||
|
legacyDatabase = null;
|
||||||
await dispose();
|
await dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ void main() {
|
||||||
test('logout', () async {
|
test('logout', () async {
|
||||||
expect(await File(dbPath).exists(), true);
|
expect(await File(dbPath).exists(), true);
|
||||||
await clientOnPath.logout();
|
await clientOnPath.logout();
|
||||||
|
await clientOnPath.database.delete();
|
||||||
expect(await File(dbPath).exists(), false);
|
expect(await File(dbPath).exists(), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -116,6 +117,22 @@ void main() {
|
||||||
expect(client.isLogged(), true);
|
expect(client.isLogged(), true);
|
||||||
|
|
||||||
await client.logout();
|
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 {
|
test('Login', () async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue