diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index 39291992..941bc50a 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -93,6 +93,7 @@ class FakeMatrixApi extends BaseClient { Set servers = { 'https://fakeserver.notexisting', + 'https://fakeserver.notexisting:1337', 'https://fakeserverpriortoauthmedia.notexisting' }; diff --git a/lib/src/client.dart b/lib/src/client.dart index f185ac06..fc6778f2 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -526,7 +526,7 @@ class Client extends MatrixApi { } // Check if server supports at least one supported version - final versions = _versionsCache = await getVersions(); + final versions = await getVersions(); if (!versions.versions .any((version) => supportedVersions.contains(version))) { throw BadServerVersionsException( @@ -1199,10 +1199,11 @@ class Client extends MatrixApi { _archivedRooms.add(ArchivedRoom(room: archivedRoom, timeline: timeline)); } - GetVersionsResponse? _versionsCache; + final _versionsCache = + AsyncCache(const Duration(hours: 1)); Future authenticatedMediaSupported() async { - final versionsResponse = _versionsCache ??= await getVersions(); + final versionsResponse = await _versionsCache.fetch(() => getVersions()); return versionsResponse.versions.any( (v) => isVersionGreaterThanOrEqualTo(v, 'v1.11'), ) || @@ -1870,7 +1871,12 @@ class Client extends MatrixApi { } _groupCallSessionId = randomAlpha(12); + + /// while I would like to move these to a onLoginStateChanged stream listener + /// that might be too much overhead and you don't have any use of these + /// when you are logged out anyway. So we just invalidate them on next login _serverConfigCache.invalidate(); + _versionsCache.invalidate(); final account = await this.database?.getClient(clientName); newRefreshToken ??= account?.tryGet('refresh_token');