refactor: Homeserver picker

This commit is contained in:
Krille Fear 2021-11-15 12:14:00 +01:00
parent 44da6c9d33
commit fa9d62ce60
3 changed files with 96 additions and 127 deletions

View File

@ -137,6 +137,17 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.setItem(SettingKeys.jitsiInstance, jitsi); .setItem(SettingKeys.jitsiInstance, jitsi);
AppConfig.jitsiInstance = jitsi; AppConfig.jitsiInstance = jitsi;
} }
_rawLoginTypes = await Matrix.of(context).getLoginClient().request(
RequestType.GET,
'/client/r0/login',
);
try {
await Matrix.of(context).getLoginClient().register();
registrationSupported = true;
} on MatrixException catch (e) {
registrationSupported = e.requireAdditionalAuthentication ?? false;
}
} catch (e) { } catch (e) {
setState(() => error = (e as Object).toLocalizedString(context)); setState(() => error = (e as Object).toLocalizedString(context));
} finally { } finally {
@ -181,22 +192,6 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.tryGetList('flows') .tryGetList('flows')
.any((flow) => flow['type'] == AuthenticationTypes.sso); .any((flow) => flow['type'] == AuthenticationTypes.sso);
Future<Map<String, dynamic>> getLoginTypes() async {
_rawLoginTypes ??= await Matrix.of(context).getLoginClient().request(
RequestType.GET,
'/client/r0/login',
);
if (registrationSupported == null) {
try {
await Matrix.of(context).getLoginClient().register();
registrationSupported = true;
} on MatrixException catch (e) {
registrationSupported = e.requireAdditionalAuthentication ?? false;
}
}
return _rawLoginTypes;
}
ChromeSafariBrowser browser; ChromeSafariBrowser browser;
static const String ssoHomeserverKey = 'sso-homeserver'; static const String ssoHomeserverKey = 'sso-homeserver';

View File

@ -13,7 +13,6 @@ import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/default_app_bar_search_field.dart'; import 'package:fluffychat/widgets/default_app_bar_search_field.dart';
import 'package:fluffychat/widgets/layouts/one_page_card.dart'; import 'package:fluffychat/widgets/layouts/one_page_card.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/localized_exception_extension.dart';
import 'homeserver_picker.dart'; import 'homeserver_picker.dart';
class HomeserverPickerView extends StatelessWidget { class HomeserverPickerView extends StatelessWidget {
@ -48,11 +47,11 @@ class HomeserverPickerView extends StatelessWidget {
? 'assets/banner_dark.png' ? 'assets/banner_dark.png'
: 'assets/banner.png', : 'assets/banner.png',
), ),
controller.isLoading if (controller.isLoading)
? const Center( const Center(
child: CircularProgressIndicator.adaptive(strokeWidth: 2)) child: CircularProgressIndicator.adaptive(strokeWidth: 2))
: controller.error != null else if (controller.error != null)
? Center( Center(
child: Padding( child: Padding(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
child: Text( child: Text(
@ -65,23 +64,8 @@ class HomeserverPickerView extends StatelessWidget {
), ),
), ),
) )
: FutureBuilder( else
future: controller.getLoginTypes(), Padding(
builder: (context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(
snapshot.error.toLocalizedString(context),
textAlign: TextAlign.center,
),
);
}
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator.adaptive(
strokeWidth: 2));
}
return Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 12.0, horizontal: 12.0,
vertical: 4.0, vertical: 4.0,
@ -94,8 +78,7 @@ class HomeserverPickerView extends StatelessWidget {
const Expanded(child: Divider()), const Expanded(child: Divider()),
Padding( Padding(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
child: Text( child: Text(L10n.of(context).loginWithOneClick),
L10n.of(context).loginWithOneClick),
), ),
const Expanded(child: Divider()), const Expanded(child: Divider()),
]), ]),
@ -106,8 +89,7 @@ class HomeserverPickerView extends StatelessWidget {
in controller.identityProviders) in controller.identityProviders)
_SsoButton( _SsoButton(
onPressed: () => onPressed: () =>
controller.ssoLoginAction( controller.ssoLoginAction(identityProvider.id),
identityProvider.id),
identityProvider: identityProvider, identityProvider: identityProvider,
), ),
}, },
@ -127,14 +109,10 @@ class HomeserverPickerView extends StatelessWidget {
if (controller.passwordLoginSupported) ...[ if (controller.passwordLoginSupported) ...[
Center( Center(
child: _LoginButton( child: _LoginButton(
onPressed: () => onPressed: () => VRouter.of(context).to('login'),
VRouter.of(context).to('login'),
icon: Icon( icon: Icon(
CupertinoIcons.lock_open_fill, CupertinoIcons.lock_open_fill,
color: Theme.of(context) color: Theme.of(context).textTheme.bodyText1.color,
.textTheme
.bodyText1
.color,
), ),
labelText: L10n.of(context).login, labelText: L10n.of(context).login,
), ),
@ -147,18 +125,14 @@ class HomeserverPickerView extends StatelessWidget {
onPressed: controller.signUpAction, onPressed: controller.signUpAction,
icon: Icon( icon: Icon(
CupertinoIcons.person_add, CupertinoIcons.person_add,
color: Theme.of(context) color: Theme.of(context).textTheme.bodyText1.color,
.textTheme
.bodyText1
.color,
), ),
labelText: L10n.of(context).register, labelText: L10n.of(context).register,
), ),
), ),
], ],
), ),
); ),
}),
]), ]),
bottomNavigationBar: Material( bottomNavigationBar: Material(
elevation: 6, elevation: 6,

View File

@ -80,7 +80,7 @@ abstract class ClientManager {
legacyDatabaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder, legacyDatabaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder,
supportedLoginTypes: { supportedLoginTypes: {
AuthenticationTypes.password, AuthenticationTypes.password,
//if (PlatformInfos.isMobile || PlatformInfos.isWeb) if (PlatformInfos.isMobile || PlatformInfos.isWeb)
AuthenticationTypes.sso AuthenticationTypes.sso
}, },
compute: compute, compute: compute,