Merge branch 'soru/login-no-server' into 'main'

fix: Allow fallback to previous url if there is no homeserver on the mxid domain

See merge request famedly/fluffychat!477
This commit is contained in:
Krille Fear 2021-08-08 16:38:04 +00:00
commit 3905baa964
2 changed files with 32 additions and 1 deletions

View File

@ -1351,6 +1351,14 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"noMatrixServer": "{server1} is no matrix server, use {server2} instead?",
"@noMatrixServer": {
"type": "text",
"placeholders": {
"server1": {},
"server2": {}
}
},
"noMegolmBootstrap": "Please turn on online key backup from within Element instead.", "noMegolmBootstrap": "Please turn on online key backup from within Element instead.",
"@noMegolmBootstrap": { "@noMegolmBootstrap": {
"type": "text", "type": "text",

View File

@ -117,10 +117,33 @@ class LoginController extends State<Login> {
.setItem(SettingKeys.jitsiInstance, jitsi); .setItem(SettingKeys.jitsiInstance, jitsi);
AppConfig.jitsiInstance = jitsi; AppConfig.jitsiInstance = jitsi;
} }
final oldHomeserver = Matrix.of(context).client.homeserver;
await showFutureLoadingDialog( await showFutureLoadingDialog(
context: context, context: context,
future: () => Matrix.of(context).client.checkHomeserver(newDomain), // do nothing if we error, we'll handle it below
future: () => Matrix.of(context)
.client
.checkHomeserver(newDomain)
.catchError((e) => null),
); );
if (Matrix.of(context).client.homeserver == null) {
Matrix.of(context).client.homeserver = oldHomeserver;
// okay, the server we checked does not appear to be a matrix server
Logs().v(
'$newDomain is not running a homeserver, asking to use $oldHomeserver');
final dialogResult = await showOkCancelAlertDialog(
context: context,
useRootNavigator: false,
message: L10n.of(context).noMatrixServer(newDomain, oldHomeserver),
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
);
if (dialogResult == OkCancelResult.ok) {
setState(() => usernameError = null);
} else {
Navigator.of(context, rootNavigator: false).pop();
}
}
setState(() => usernameError = null); setState(() => usernameError = null);
} }
} catch (e) { } catch (e) {