From e04137cddbbc61527a5bfb6dc9e2bf565aa61da5 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 18 Aug 2021 17:50:06 +0200 Subject: [PATCH] fix: Re-add login fixes with the new SDK --- lib/pages/login.dart | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/pages/login.dart b/lib/pages/login.dart index 5004fc81..a43efec9 100644 --- a/lib/pages/login.dart +++ b/lib/pages/login.dart @@ -98,25 +98,20 @@ class LoginController extends State { setState(() => usernameError = null); if (!userId.isValidMatrixId) return; try { - final wellKnownInformations = - await Matrix.of(context).client.getWellknown(); - final newDomain = wellKnownInformations.mHomeserver?.baseUrl; - if ((newDomain?.toString()?.isNotEmpty ?? false) && - newDomain != Matrix.of(context).client.homeserver) { - var jitsi = wellKnownInformations?.additionalProperties - ?.tryGet>('im.vector.riot.jitsi') - ?.tryGet('preferredDomain'); - if (jitsi != null) { - if (!jitsi.endsWith('/')) { - jitsi += '/'; - } - Logs().v('Found custom jitsi instance $jitsi'); - await Matrix.of(context) - .store - .setItem(SettingKeys.jitsiInstance, jitsi); - AppConfig.jitsiInstance = jitsi; + final oldHomeserver = Matrix.of(context).client.homeserver; + var newDomain = Uri.https(userId.domain, ''); + Matrix.of(context).client.homeserver = newDomain; + DiscoveryInformation wellKnownInformation; + try { + wellKnownInformation = await Matrix.of(context).client.getWellknown(); + if (wellKnownInformation.mHomeserver?.baseUrl?.toString()?.isNotEmpty ?? + false) { + newDomain = wellKnownInformation.mHomeserver.baseUrl; } - final oldHomeserver = Matrix.of(context).client.homeserver; + } catch (_) { + // do nothing, newDomain is already set to a reasonable fallback + } + if (newDomain != oldHomeserver) { await showFutureLoadingDialog( context: context, // do nothing if we error, we'll handle it below @@ -141,8 +136,22 @@ class LoginController extends State { setState(() => usernameError = null); } else { Navigator.of(context, rootNavigator: false).pop(); + return; } } + var jitsi = wellKnownInformation?.additionalProperties + ?.tryGet>('im.vector.riot.jitsi') + ?.tryGet('preferredDomain'); + if (jitsi != null) { + if (!jitsi.endsWith('/')) { + jitsi += '/'; + } + Logs().v('Found custom jitsi instance $jitsi'); + await Matrix.of(context) + .store + .setItem(SettingKeys.jitsiInstance, jitsi); + AppConfig.jitsiInstance = jitsi; + } setState(() => usernameError = null); } } catch (e) {