From 6b610d0115b396040280808e6ff0baa65b19d37e Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Wed, 16 Feb 2022 07:07:53 +0000 Subject: [PATCH] feat: Return homeserver summary on checkHomeserver --- lib/src/client.dart | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index b8b31060..f856d334 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -342,21 +342,11 @@ class Client extends MatrixApi { } } - @Deprecated('Use [checkHomeserver] instead.') - Future checkServer(dynamic serverUrl) async { - try { - await checkHomeserver(serverUrl); - } catch (_) { - return false; - } - return true; - } - /// Checks the supported versions of the Matrix protocol and the supported /// login types. Throws an exception if the server is not compatible with the /// client and sets [homeserver] to [homeserverUrl] if it is. Supports the /// types `Uri` and `String`. - Future checkHomeserver(dynamic homeserverUrl, + Future checkHomeserver(dynamic homeserverUrl, {bool checkWellKnown = true}) async { try { var homeserver = this.homeserver = @@ -389,7 +379,11 @@ class Client extends MatrixApi { loginTypes.map((f) => f.type ?? '').toSet(), supportedLoginTypes); } - return wellKnown; + return HomeserverSummary( + discoveryInformation: wellKnown, + versions: versions, + loginFlows: loginTypes, + ); } catch (_) { homeserver = null; rethrow; @@ -2534,3 +2528,15 @@ class BadServerLoginTypesException implements Exception { String 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 loginFlows; + + HomeserverSummary({ + required this.discoveryInformation, + required this.versions, + required this.loginFlows, + }); +}