Skip to content

Commit

Permalink
fixup! Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Apr 11, 2024
1 parent ad32e1f commit b478b3e
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 145 deletions.
26 changes: 17 additions & 9 deletions lib/pages/bootstrap/bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,17 @@ class BootstrapDialogState extends State<BootstrapDialog> {
);
break;
case BootstrapState.done:
titleText = L10n.of(context)!.everythingReady;
titleText = null;
body = Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/backup.png', fit: BoxFit.contain),
Text(L10n.of(context)!.yourChatBackupHasBeenSetUp),
Flexible(
child: Text(
L10n.of(context)!.yourChatBackupHasBeenSetUp,
textAlign: TextAlign.center,
),
),
],
);
buttons.add(
Expand All @@ -446,16 +451,19 @@ class BootstrapDialogState extends State<BootstrapDialog> {
return AlertDialog(
content: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: body,
),
Expanded(
child: Text(
titleText!,
overflow: TextOverflow.ellipsis,
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: body,
),
),
if (titleText != null)
Expanded(
child: Text(
titleText!,
overflow: TextOverflow.ellipsis,
),
),
],
),
actions: buttons.isNotEmpty ? buttons : null,
Expand Down
74 changes: 16 additions & 58 deletions lib/pages/bootstrap/tom_bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:fluffychat/domain/usecase/recovery/save_recovery_words_interacto
import 'package:fluffychat/pages/bootstrap/linear_progress_indicator_widget.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:flutter/material.dart';
import 'package:linagora_design_flutter/colors/linagora_sys_colors.dart';
import 'package:matrix/encryption.dart';
import 'package:matrix/encryption/utils/bootstrap.dart';
import 'package:matrix/matrix.dart';
Expand All @@ -23,7 +24,7 @@ class TomBootstrapDialog extends StatefulWidget {

Future<bool?> show() => TwakeDialog.showDialogFullScreen(
builder: () => this,
barrierColor: Colors.white,
barrierColor: LinagoraSysColors.material().onPrimary,
);

@override
Expand Down Expand Up @@ -107,6 +108,7 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState(): no recovery existed then call bootstrap',
);
Navigator.pop(context);
await BootstrapDialog(client: widget.client).show();
}
}
Expand Down Expand Up @@ -179,51 +181,16 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
_handleBootstrapState();
break;
case UploadRecoveryKeyState.unlockError:
// titleText = L10n.of(context)!.chatBackup;
// body = Text(
// L10n.of(context)!.cannotUnlockBackupKey,
// style: Theme.of(context).textTheme.bodyMedium?.copyWith(
// color: Theme.of(context).colorScheme.onSurfaceVariant,
// ),
// );
// buttons.clear();
// buttons
// ..add(
// AdaptiveFlatButton(
// label: L10n.of(context)!.close,
// onPressed: () =>
// Navigator.of(context, rootNavigator: false).pop<bool>(false),
// ),
// )
// ..add(
// AdaptiveFlatButton(
// label: L10n.of(context)!.next,
// onPressed: () async {
// await BootstrapDialog(client: widget.client).show().then(
// (value) => Navigator.of(context, rootNavigator: false)
// .pop<bool>(false),
// );
// },
// ),
// );
WidgetsBinding.instance.addPostFrameCallback((_) async {
Navigator.pop(context);
await BootstrapDialog(client: widget.client).show();
});
break;
case UploadRecoveryKeyState.uploadError:
Logs().e('TomBootstrapDialogState::build(): upload recovery key error');
// titleText = L10n.of(context)!.chatBackup;
// body = Text(
// L10n.of(context)!.cannotUploadKey,
// style: Theme.of(context).textTheme.bodyMedium?.copyWith(
// color: Theme.of(context).colorScheme.onSurfaceVariant,
// ),
// );
// buttons.clear();
// buttons.add(
// AdaptiveFlatButton(
// label: L10n.of(context)!.close,
// onPressed: () =>
// Navigator.of(context, rootNavigator: false).pop<bool>(false),
// ),
// );
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context, rootNavigator: false).pop<bool>(false);
});
break;
default:
_handleBootstrapState();
Expand Down Expand Up @@ -361,23 +328,14 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
);
break;
case BootstrapState.error:
// titleText = L10n.of(context)!.oopsSomethingWentWrong;
// body = const Icon(Icons.error_outline, color: Colors.red, size: 40);
// buttons.clear();
// buttons.add(
// AdaptiveFlatButton(
// label: L10n.of(context)!.close,
// onPressed: () =>
// Navigator.of(context, rootNavigator: false).pop<bool>(false),
// ),
// );
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context, rootNavigator: false).pop<bool>(false);
});
break;
case BootstrapState.done:
WidgetsBinding.instance.addPostFrameCallback(
(_) {
Navigator.of(context, rootNavigator: false).pop<bool>(true);
},
);
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context, rootNavigator: false).pop<bool>(true);
});
break;
}
}
Expand Down
56 changes: 32 additions & 24 deletions lib/pages/connect/connect_page_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/auto_homeserver_picker/auto_homeserver_picker.dart';
import 'package:fluffychat/pages/connect/connect_page.dart';
import 'package:fluffychat/pages/connect/sso_login_state.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/exception/check_homeserver_exception.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand Down Expand Up @@ -102,47 +103,54 @@ mixin ConnectPageMixin {
);
}

Future<void> ssoLoginAction({
Future<SsoLoginState> ssoLoginAction({
required BuildContext context,
required String id,
}) async {
if (PlatformInfos.isWeb) {
await ssoLoginActionWeb(context: context, id: id);
return ssoLoginActionWeb(context: context, id: id);
} else {
ssoLoginActionMobile(context: context, id: id);
return ssoLoginActionMobile(context: context, id: id);
}
}

Future<void> ssoLoginActionWeb({
Future<SsoLoginState> ssoLoginActionWeb({
required BuildContext context,
required String id,
}) async {
await authenticateWithWebAuth(context: context, id: id);
return SsoLoginState.success;
}

void ssoLoginActionMobile({
Future<SsoLoginState> ssoLoginActionMobile({
required BuildContext context,
required String id,
}) async {
final result = await authenticateWithWebAuth(context: context, id: id);
final token = Uri.parse(result).queryParameters['loginToken'];
if (token?.isEmpty ?? false) return;
Matrix.of(context).loginType = LoginType.mLoginToken;
await TwakeDialog.showStreamDialogFullScreen(
future: () => Matrix.of(context)
.getLoginClient()
.login(
LoginType.mLoginToken,
token: token,
initialDeviceDisplayName: PlatformInfos.clientName,
)
.timeout(
AutoHomeserverPickerController.autoHomeserverPickerTimeout,
onTimeout: () {
throw CheckHomeserverTimeoutException();
},
),
);
try {
final result = await authenticateWithWebAuth(context: context, id: id);
final token = Uri.parse(result).queryParameters['loginToken'];
if (token?.isEmpty ?? false) return SsoLoginState.tokenEmpty;
Matrix.of(context).loginType = LoginType.mLoginToken;
await TwakeDialog.showStreamDialogFullScreen(
future: () => Matrix.of(context)
.getLoginClient()
.login(
LoginType.mLoginToken,
token: token,
initialDeviceDisplayName: PlatformInfos.clientName,
)
.timeout(
AutoHomeserverPickerController.autoHomeserverPickerTimeout,
onTimeout: () {
throw CheckHomeserverTimeoutException();
},
),
);
return SsoLoginState.success;
} catch (e) {
Logs().e('ConnectPageMixin:: ssoLoginActionMobil(): error: $e');
return SsoLoginState.error;
}
}

Future<void> tryLogoutSso(BuildContext context) async {
Expand Down
5 changes: 5 additions & 0 deletions lib/pages/connect/sso_login_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum SsoLoginState {
success,
error,
tokenEmpty,
}
10 changes: 8 additions & 2 deletions lib/pages/homeserver_picker/homeserver_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/pages/connect/connect_page_mixin.dart';
import 'package:fluffychat/pages/connect/sso_login_state.dart';
import 'package:fluffychat/pages/homeserver_picker/homeserver_state.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/twake_snackbar.dart';
Expand Down Expand Up @@ -187,9 +188,14 @@ class HomeserverPickerController extends State<HomeserverPicker>
identityProviders(rawLoginTypes: rawLoginTypes);

if (supportsSso(context) && identitiesProvider?.length == 1) {
ssoLoginAction(context: context, id: identitiesProvider!.single.id!);
final result = await ssoLoginAction(
context: context,
id: identitiesProvider!.single.id!,
);
if (result == SsoLoginState.error) {
state = HomeserverState.ssoLoginServer;
}
}
state = HomeserverState.ssoLoginServer;
FocusManager.instance.primaryFocus?.unfocus();
setState(() {});
} else {
Expand Down
12 changes: 6 additions & 6 deletions lib/presentation/model/client_login_state_event.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import 'package:equatable/equatable.dart';
import 'package:matrix/matrix.dart';

enum MultiLoginState {
primaryAccount,
secondaryAccount,
enum MultipleAccountLoginType {
firstLoggedIn,
otherAccountLoggedIn,
}

class ClientLoginStateEvent with EquatableMixin {
final Client client;
final LoginState loginState;
final MultiLoginState multiLoginState;
final MultipleAccountLoginType multipleAccountLoginType;

ClientLoginStateEvent({
required this.client,
required this.loginState,
required this.multiLoginState,
required this.multipleAccountLoginType,
});

@override
List<Object?> get props => [
client,
loginState,
multiLoginState,
multipleAccountLoginType,
];
}
Loading

0 comments on commit b478b3e

Please sign in to comment.