feat: Allow overriding supportedVersions

This commit is contained in:
Christian Pauly 2022-06-07 08:53:08 +02:00
parent f24c551721
commit 4692c95910
1 changed files with 10 additions and 3 deletions

View File

@ -355,8 +355,13 @@ class Client extends MatrixApi {
/// login types. Throws an exception if the server is not compatible with the /// login types. Throws an exception if the server is not compatible with the
/// client and sets [homeserver] to [homeserverUrl] if it is. Supports the /// client and sets [homeserver] to [homeserverUrl] if it is. Supports the
/// types `Uri` and `String`. /// types `Uri` and `String`.
Future<HomeserverSummary> checkHomeserver(Uri homeserverUrl, Future<HomeserverSummary> checkHomeserver(
{bool checkWellKnown = true}) async { Uri homeserverUrl, {
bool checkWellKnown = true,
Set<String>? overrideSupportedVersions,
}) async {
final supportedVersions =
overrideSupportedVersions ?? Client.supportedVersions;
try { try {
homeserver = homeserverUrl.stripTrailingSlash(); homeserver = homeserverUrl.stripTrailingSlash();
@ -376,7 +381,9 @@ class Client extends MatrixApi {
if (!versions.versions if (!versions.versions
.any((version) => supportedVersions.contains(version))) { .any((version) => supportedVersions.contains(version))) {
throw BadServerVersionsException( throw BadServerVersionsException(
versions.versions.toSet(), supportedVersions); versions.versions.toSet(),
supportedVersions,
);
} }
final loginTypes = await getLoginFlows() ?? []; final loginTypes = await getLoginFlows() ?? [];