Set Jitsi instance from well-known

This commit is contained in:
Inex Code 2020-06-14 15:12:47 +03:00
parent f219a69285
commit ec52badcf3
4 changed files with 62 additions and 5 deletions

View file

@ -44,6 +44,7 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
if (success != false) { if (success != false) {
await Navigator.of(context).push(AppRoute(Login( await Navigator.of(context).push(AppRoute(Login(
username: homeserver, username: homeserver,
wellknown: wellknown,
))); )));
} }
} else { } else {
@ -57,7 +58,9 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
? 'https://${Uri.parse(wellknown.mHomeserver.baseUrl).host}' ? 'https://${Uri.parse(wellknown.mHomeserver.baseUrl).host}'
: homeserver)); : homeserver));
if (success != false) { if (success != false) {
await Navigator.of(context).push(AppRoute(SignUp())); await Navigator.of(context).push(AppRoute(SignUp(
wellknown: wellknown,
)));
} }
} }
} }

View file

@ -13,9 +13,14 @@ import 'package:flutter/material.dart';
import 'chat_list.dart'; import 'chat_list.dart';
class Login extends StatefulWidget { class Login extends StatefulWidget {
Login({Key key, String this.username: null}) : super(key: key); Login(
{Key key,
String this.username: null,
WellKnownInformations this.wellknown: null})
: super(key: key);
final String username; final String username;
final WellKnownInformations wellknown;
@override @override
_LoginState createState() => _LoginState(); _LoginState createState() => _LoginState();
@ -28,6 +33,7 @@ class _LoginState extends State<Login> {
String passwordError; String passwordError;
bool loading = false; bool loading = false;
bool showPassword = false; bool showPassword = false;
WellKnownInformations newWellknown;
void login(BuildContext context) async { void login(BuildContext context) async {
var matrix = Matrix.of(context); var matrix = Matrix.of(context);
@ -72,6 +78,29 @@ class _LoginState extends State<Login> {
} }
} }
setState(() => loading = false); setState(() => loading = false);
if (newWellknown != null) {
if (newWellknown.jitsiHomeserver?.baseUrl != null) {
if (!newWellknown.jitsiHomeserver.baseUrl.startsWith('https://')) {
newWellknown.jitsiHomeserver.baseUrl =
'https://${newWellknown.jitsiHomeserver.baseUrl}';
}
Matrix.of(context).store.setItem('chat.fluffy.jitsi_instance',
'https://${Uri.parse(newWellknown.jitsiHomeserver.baseUrl).host}/');
Matrix.of(context).jitsiInstance =
'https://${Uri.parse(newWellknown.jitsiHomeserver.baseUrl).host}/';
}
} else if (widget.wellknown != null) {
if (widget.wellknown.jitsiHomeserver?.baseUrl != null) {
if (!widget.wellknown.jitsiHomeserver.baseUrl.startsWith('https://')) {
widget.wellknown.jitsiHomeserver.baseUrl =
'https://${widget.wellknown.jitsiHomeserver.baseUrl}';
}
Matrix.of(context).store.setItem('chat.fluffy.jitsi_instance',
'https://${Uri.parse(widget.wellknown.jitsiHomeserver.baseUrl).host}/');
Matrix.of(context).jitsiInstance =
'https://${Uri.parse(widget.wellknown.jitsiHomeserver.baseUrl).host}/';
}
}
await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), (r) => false); AppRoute.defaultRoute(context, ChatListView()), (r) => false);
} }
@ -100,8 +129,10 @@ class _LoginState extends State<Login> {
Matrix.of(context).client.checkServer(newDomain)); Matrix.of(context).client.checkServer(newDomain));
setState(() => usernameError = null); setState(() => usernameError = null);
} }
newWellknown = wellKnownInformations;
} catch (e) { } catch (e) {
setState(() => usernameError = e.toString()); setState(() => usernameError = e.toString());
newWellknown = null;
} }
} }

View file

@ -12,6 +12,11 @@ import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
class SignUp extends StatefulWidget { class SignUp extends StatefulWidget {
SignUp({Key key, WellKnownInformations this.wellknown: null})
: super(key: key);
final WellKnownInformations wellknown;
@override @override
_SignUpState createState() => _SignUpState(); _SignUpState createState() => _SignUpState();
} }
@ -60,8 +65,12 @@ class _SignUpState extends State<SignUp> {
setState(() => loading = false); setState(() => loading = false);
await Navigator.of(context).push( await Navigator.of(context).push(
AppRoute( AppRoute(
SignUpPassword(preferredUsername, SignUpPassword(
avatar: avatar, displayname: usernameController.text), preferredUsername,
avatar: avatar,
displayname: usernameController.text,
wellknown: widget.wellknown,
),
), ),
); );
} }

View file

@ -15,7 +15,9 @@ class SignUpPassword extends StatefulWidget {
final File avatar; final File avatar;
final String username; final String username;
final String displayname; final String displayname;
const SignUpPassword(this.username, {this.avatar, this.displayname}); final WellKnownInformations wellknown;
const SignUpPassword(this.username,
{this.avatar, this.displayname, this.wellknown});
@override @override
_SignUpPasswordState createState() => _SignUpPasswordState(); _SignUpPasswordState createState() => _SignUpPasswordState();
} }
@ -108,6 +110,18 @@ class _SignUpPasswordState extends State<SignUpPassword> {
BotToast.showText(text: L10n.of(context).couldNotSetAvatar); BotToast.showText(text: L10n.of(context).couldNotSetAvatar);
} }
} }
if (widget.wellknown != null) {
if (widget.wellknown.jitsiHomeserver?.baseUrl != null) {
if (!widget.wellknown.jitsiHomeserver.baseUrl.startsWith('https://')) {
widget.wellknown.jitsiHomeserver.baseUrl =
'https://${widget.wellknown.jitsiHomeserver.baseUrl}';
}
Matrix.of(context).store.setItem('chat.fluffy.jitsi_instance',
'https://${Uri.parse(widget.wellknown.jitsiHomeserver.baseUrl).host}/');
Matrix.of(context).jitsiInstance =
'https://${Uri.parse(widget.wellknown.jitsiHomeserver.baseUrl).host}/';
}
}
await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), (r) => false); AppRoute.defaultRoute(context, ChatListView()), (r) => false);
setState(() => loading = false); setState(() => loading = false);