Merge branch 'krille/return-homeserver-summary' into 'main'

feat: Return homeserver summary on checkHomeserver

See merge request famedly/company/frontend/famedlysdk!963
This commit is contained in:
td 2022-02-16 07:07:53 +00:00
commit d543a0314d
1 changed files with 18 additions and 12 deletions

View File

@ -342,21 +342,11 @@ class Client extends MatrixApi {
} }
} }
@Deprecated('Use [checkHomeserver] instead.')
Future<bool> checkServer(dynamic serverUrl) async {
try {
await checkHomeserver(serverUrl);
} catch (_) {
return false;
}
return true;
}
/// Checks the supported versions of the Matrix protocol and the supported /// Checks the supported versions of the Matrix protocol and the supported
/// 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<DiscoveryInformation?> checkHomeserver(dynamic homeserverUrl, Future<HomeserverSummary> checkHomeserver(dynamic homeserverUrl,
{bool checkWellKnown = true}) async { {bool checkWellKnown = true}) async {
try { try {
var homeserver = this.homeserver = var homeserver = this.homeserver =
@ -389,7 +379,11 @@ class Client extends MatrixApi {
loginTypes.map((f) => f.type ?? '').toSet(), supportedLoginTypes); loginTypes.map((f) => f.type ?? '').toSet(), supportedLoginTypes);
} }
return wellKnown; return HomeserverSummary(
discoveryInformation: wellKnown,
versions: versions,
loginFlows: loginTypes,
);
} catch (_) { } catch (_) {
homeserver = null; homeserver = null;
rethrow; rethrow;
@ -2534,3 +2528,15 @@ class BadServerLoginTypesException implements Exception {
String toString() => String toString() =>
'Server supports the Login Types: ${serverLoginTypes.toString()} but this application is only compatible with ${supportedLoginTypes.toString()}.'; 'Server supports the Login Types: ${serverLoginTypes.toString()} but this application is only compatible with ${supportedLoginTypes.toString()}.';
} }
class HomeserverSummary {
final DiscoveryInformation? discoveryInformation;
final GetVersionsResponse versions;
final List<LoginFlow> loginFlows;
HomeserverSummary({
required this.discoveryInformation,
required this.versions,
required this.loginFlows,
});
}