TF-3278 Handle open app via deep link at TwakeWelcome screen
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/data/datasource/cleanup_datasource.dart';
|
||||
@@ -12,11 +11,8 @@ import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_email_cac
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_login_url_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_login_username_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_search_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/usecases/auto_sign_in_via_deep_link_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/home/presentation/home_controller.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/check_oidc_is_available_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
|
||||
@@ -58,13 +54,6 @@ class HomeBindings extends BaseBindings {
|
||||
Get.lazyPut(() => CleanupRecentLoginUrlCacheInteractor(Get.find<CleanupRepository>()));
|
||||
Get.lazyPut(() => CleanupRecentLoginUsernameCacheInteractor(Get.find<CleanupRepository>()));
|
||||
Get.lazyPut(() => CheckOIDCIsAvailableInteractor(Get.find<AuthenticationOIDCRepository>()));
|
||||
if (PlatformInfo.isMobile) {
|
||||
Get.lazyPut(() => AutoSignInViaDeepLinkInteractor(
|
||||
Get.find<AuthenticationOIDCRepository>(),
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
|
||||
@@ -24,8 +21,6 @@ import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_lo
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_search_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/usecases/auto_sign_in_via_deep_link_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/get_credential_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/get_stored_token_oidc_state.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_data.dart';
|
||||
@@ -33,7 +28,6 @@ import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_utils.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_config.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_links_manager.dart';
|
||||
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
|
||||
import 'package:tmail_ui_user/main/utils/ios_notification_manager.dart';
|
||||
@@ -47,7 +41,6 @@ class HomeController extends ReloadableController {
|
||||
|
||||
IOSNotificationManager? _iosNotificationManager;
|
||||
DeepLinksManager? _deepLinksManager;
|
||||
AutoSignInViaDeepLinkInteractor? _autoSignInViaDeepLinkInteractor;
|
||||
|
||||
HomeController(
|
||||
this._cleanupEmailCacheInteractor,
|
||||
@@ -113,65 +106,9 @@ class HomeController extends ReloadableController {
|
||||
|
||||
void _registerDeepLinks() {
|
||||
_deepLinksManager = getBinding<DeepLinksManager>();
|
||||
_autoSignInViaDeepLinkInteractor = getBinding<AutoSignInViaDeepLinkInteractor>();
|
||||
}
|
||||
|
||||
Future<void> _handleDeepLinksNotSignedIn() async {
|
||||
final deepLinkData = await _deepLinksManager?.getDeepLinkData();
|
||||
log('HomeController::_handleDeepLinksNotSignedIn:DeepLinkData = $deepLinkData');
|
||||
if (deepLinkData == null) {
|
||||
goToLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
if (deepLinkData.action.toLowerCase() == AppConfig.openAppHostDeepLink.toLowerCase()) {
|
||||
_handleOpenApp(deepLinkData);
|
||||
} else {
|
||||
goToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
void _handleOpenApp(DeepLinkData deepLinkData) {
|
||||
_autoSignInViaDeepLink(deepLinkData);
|
||||
}
|
||||
|
||||
Future<void> _handleDeepLinksSignedIn(Success authenticationViewStateSuccess) async {
|
||||
final deepLinkData = await _deepLinksManager?.getDeepLinkData();
|
||||
log('HomeController::_handleDeepLinksSignedIn:DeepLinkData = $deepLinkData');
|
||||
if (deepLinkData == null) {
|
||||
_continueUsingTheApp(authenticationViewStateSuccess);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deepLinkData.action.toLowerCase() == AppConfig.openAppHostDeepLink.toLowerCase()) {
|
||||
final personalAccount = _getPersonalAccountFromViewStateSuccess(authenticationViewStateSuccess);
|
||||
|
||||
if (deepLinkData.username?.isNotEmpty != true ||
|
||||
personalAccount?.userName?.value.isNotEmpty != true) {
|
||||
_continueUsingTheApp(authenticationViewStateSuccess);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deepLinkData.username == personalAccount?.userName?.value || currentContext == null) {
|
||||
_continueUsingTheApp(authenticationViewStateSuccess);
|
||||
} else {
|
||||
_showConfirmDialogSwitchAccount(
|
||||
username: personalAccount!.userName!.value,
|
||||
onConfirmAction: () => _handleLogOutAndSignInNewAccount(
|
||||
authenticationViewStateSuccess: authenticationViewStateSuccess,
|
||||
personalAccount: personalAccount,
|
||||
deepLinkData: deepLinkData,
|
||||
),
|
||||
onCancelAction: () => _continueUsingTheApp(authenticationViewStateSuccess)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_continueUsingTheApp(authenticationViewStateSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
void _continueUsingTheApp(Success authenticationViewStateSuccess) {
|
||||
log('HomeController::_continueUsingTheApp:');
|
||||
super.handleSuccessViewState(authenticationViewStateSuccess);
|
||||
}
|
||||
|
||||
@@ -184,44 +121,6 @@ class HomeController extends ReloadableController {
|
||||
return null;
|
||||
}
|
||||
|
||||
void _showConfirmDialogSwitchAccount({
|
||||
required String username,
|
||||
required Function onConfirmAction,
|
||||
required Function onCancelAction,
|
||||
}) {
|
||||
final appLocalizations = AppLocalizations.of(currentContext!);
|
||||
|
||||
showConfirmDialogAction(
|
||||
currentContext!,
|
||||
'',
|
||||
appLocalizations.yesLogout,
|
||||
title: appLocalizations.logoutConfirmation,
|
||||
alignCenter: true,
|
||||
outsideDismissible: false,
|
||||
titleActionButtonMaxLines: 1,
|
||||
titlePadding: const EdgeInsetsDirectional.only(start: 24, top: 24, end: 24, bottom: 12),
|
||||
messageStyle: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
listTextSpan: [
|
||||
TextSpan(text: appLocalizations.messageConfirmationLogout),
|
||||
TextSpan(
|
||||
text: ' $username',
|
||||
style: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' ?'),
|
||||
],
|
||||
onConfirmAction: onConfirmAction,
|
||||
onCancelAction: onCancelAction
|
||||
);
|
||||
}
|
||||
|
||||
void _handleLogOutAndSignInNewAccount({
|
||||
required Success authenticationViewStateSuccess,
|
||||
required PersonalAccount personalAccount,
|
||||
@@ -283,7 +182,11 @@ class HomeController extends ReloadableController {
|
||||
accountId: personalAccount.accountId!,
|
||||
onFailureCallback: () =>
|
||||
_continueUsingTheApp(authenticationViewStateSuccess),
|
||||
onSuccessCallback: () => _autoSignInViaDeepLink(deepLinkData),
|
||||
onSuccessCallback: () => _deepLinksManager?.autoSignInViaDeepLink(
|
||||
deepLinkData: deepLinkData,
|
||||
onFailureCallback: () => _continueUsingTheApp(authenticationViewStateSuccess),
|
||||
onSuccessCallback: _handleAutoSignInViaDeepLinkSuccess,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_continueUsingTheApp(authenticationViewStateSuccess);
|
||||
@@ -303,44 +206,6 @@ class HomeController extends ReloadableController {
|
||||
);
|
||||
}
|
||||
|
||||
void _autoSignInViaDeepLink(DeepLinkData deepLinkData) {
|
||||
if (deepLinkData.isValidToken() && _autoSignInViaDeepLinkInteractor != null) {
|
||||
consumeState(_autoSignInViaDeepLinkInteractor!.execute(
|
||||
baseUri: Uri.parse(AppConfig.saasJmapServerUrl),
|
||||
tokenOIDC: deepLinkData.getTokenOIDC(),
|
||||
oidcConfiguration: OIDCConfiguration(
|
||||
authority: AppConfig.saasRegistrationUrl,
|
||||
clientId: OIDCConstant.clientId,
|
||||
scopes: AppConfig.oidcScopes,
|
||||
),
|
||||
));
|
||||
} else {
|
||||
goToLogin();
|
||||
|
||||
if (currentContext == null || currentOverlayContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).tokenInvalid,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleAutoSignInViaDeepLinkFailure() {
|
||||
goToLogin();
|
||||
|
||||
if (currentContext == null || currentOverlayContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).tokenInvalid,
|
||||
);
|
||||
}
|
||||
|
||||
void _handleAutoSignInViaDeepLinkSuccess(AutoSignInViaDeepLinkSuccess success) {
|
||||
setDataToInterceptors(
|
||||
baseUrl: success.baseUri.toString(),
|
||||
@@ -350,12 +215,29 @@ class HomeController extends ReloadableController {
|
||||
getSessionAction();
|
||||
}
|
||||
|
||||
bool _validateToHandleDeepLinksNotSignedIn(Failure failure) {
|
||||
return PlatformInfo.isMobile &&
|
||||
isNotSignedIn(failure) &&
|
||||
_deepLinksManager != null;
|
||||
}
|
||||
|
||||
bool _validateToHandleDeepLinksSignedIn(Success success) {
|
||||
final personalAccount = _getPersonalAccountFromViewStateSuccess(success);
|
||||
|
||||
return PlatformInfo.isMobile &&
|
||||
(success is GetCredentialViewState ||
|
||||
success is GetStoredTokenOidcSuccess) &&
|
||||
personalAccount != null &&
|
||||
_deepLinksManager != null;
|
||||
}
|
||||
|
||||
@override
|
||||
void handleFailureViewState(Failure failure) {
|
||||
if (PlatformInfo.isMobile && isNotSignedIn(failure)) {
|
||||
_handleDeepLinksNotSignedIn();
|
||||
} else if (failure is AutoSignInViaDeepLinkFailure) {
|
||||
_handleAutoSignInViaDeepLinkFailure();
|
||||
if (_validateToHandleDeepLinksNotSignedIn(failure)) {
|
||||
_deepLinksManager!.handleDeepLinksWhenAppTerminatedNotSignedIn(
|
||||
onSuccessCallback: _handleAutoSignInViaDeepLinkSuccess,
|
||||
onFailureCallback: goToLogin,
|
||||
);
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
@@ -363,12 +245,18 @@ class HomeController extends ReloadableController {
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
if (PlatformInfo.isMobile &&
|
||||
(success is GetCredentialViewState ||
|
||||
success is GetStoredTokenOidcSuccess)) {
|
||||
_handleDeepLinksSignedIn(success);
|
||||
} else if (success is AutoSignInViaDeepLinkSuccess) {
|
||||
_handleAutoSignInViaDeepLinkSuccess(success);
|
||||
if (_validateToHandleDeepLinksSignedIn(success)) {
|
||||
final personalAccount = _getPersonalAccountFromViewStateSuccess(success);
|
||||
|
||||
_deepLinksManager!.handleDeepLinksWhenAppTerminatedSignedIn(
|
||||
username: personalAccount?.userName?.value,
|
||||
onFailureCallback: () => _continueUsingTheApp(success),
|
||||
onConfirmCallback: (deepLinkData) => _handleLogOutAndSignInNewAccount(
|
||||
authenticationViewStateSuccess: success,
|
||||
personalAccount: personalAccount!,
|
||||
deepLinkData: deepLinkData,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
super.handleSuccessViewState(success);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
|
||||
@@ -37,6 +38,9 @@ class TwakeWelcomeBindings extends BaseBindings {
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
));
|
||||
if (PlatformInfo.isMobile) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
+62
-8
@@ -1,5 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -7,6 +11,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
@@ -16,6 +21,8 @@ import 'package:tmail_ui_user/features/starting_page/domain/state/sign_in_twake_
|
||||
import 'package:tmail_ui_user/features/starting_page/domain/state/sign_up_twake_workplace_state.dart';
|
||||
import 'package:tmail_ui_user/features/starting_page/domain/usecase/sign_in_twake_workplace_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/starting_page/domain/usecase/sign_up_twake_workplace_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_data.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_links_manager.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
@@ -28,11 +35,53 @@ class TwakeWelcomeController extends ReloadableController {
|
||||
final SignInTwakeWorkplaceInteractor _signInTwakeWorkplaceInteractor;
|
||||
final SignUpTwakeWorkplaceInteractor _signUpTwakeWorkplaceInteractor;
|
||||
|
||||
DeepLinksManager? _deepLinksManager;
|
||||
StreamSubscription<DeepLinkData?>? _deepLinkDataStreamSubscription;
|
||||
|
||||
TwakeWelcomeController(
|
||||
this._signInTwakeWorkplaceInteractor,
|
||||
this._signUpTwakeWorkplaceInteractor,
|
||||
);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (PlatformInfo.isMobile) {
|
||||
_registerDeepLinks();
|
||||
}
|
||||
}
|
||||
|
||||
void _registerDeepLinks() {
|
||||
_deepLinksManager = getBinding<DeepLinksManager>();
|
||||
_deepLinksManager?.clearPendingDeepLinkData();
|
||||
_deepLinkDataStreamSubscription = _deepLinksManager
|
||||
?.pendingDeepLinkData.stream
|
||||
.listen(_handlePendingDeepLinkDataStream);
|
||||
}
|
||||
|
||||
void _handlePendingDeepLinkDataStream(DeepLinkData? deepLinkData) {
|
||||
log('TwakeWelcomeController::_handlePendingDeepLinkDataStream:DeepLinkData = $deepLinkData');
|
||||
if (deepLinkData == null) return;
|
||||
|
||||
if (currentContext != null) {
|
||||
TipDialogHelper.loading(AppLocalizations.of(currentContext!).loadingPleaseWait);
|
||||
}
|
||||
|
||||
_deepLinksManager?.handleDeepLinksWhenAppOnForegroundNotSignedIn(
|
||||
deepLinkData: deepLinkData,
|
||||
onSuccessCallback: _handleAutoSignInViaDeepLinkSuccess,
|
||||
onFailureCallback: TipDialogHelper.dismiss
|
||||
);
|
||||
}
|
||||
|
||||
void _handleAutoSignInViaDeepLinkSuccess(AutoSignInViaDeepLinkSuccess success) {
|
||||
_synchronizeTokenAndGetSession(
|
||||
baseUri: success.baseUri,
|
||||
tokenOIDC: success.tokenOIDC,
|
||||
oidcConfiguration: success.oidcConfiguration,
|
||||
);
|
||||
}
|
||||
|
||||
void handleUseCompanyServer() {
|
||||
popAndPush(
|
||||
AppRoutes.login,
|
||||
@@ -134,14 +183,11 @@ class TwakeWelcomeController extends ReloadableController {
|
||||
required TokenOIDC tokenOIDC,
|
||||
required OIDCConfiguration oidcConfiguration,
|
||||
}) {
|
||||
dynamicUrlInterceptors.setJmapUrl(baseUri.toString());
|
||||
dynamicUrlInterceptors.changeBaseUrl(baseUri.toString());
|
||||
authorizationInterceptors.setTokenAndAuthorityOidc(
|
||||
newToken: tokenOIDC,
|
||||
newConfig: oidcConfiguration);
|
||||
authorizationIsolateInterceptors.setTokenAndAuthorityOidc(
|
||||
newToken: tokenOIDC,
|
||||
newConfig: oidcConfiguration);
|
||||
setDataToInterceptors(
|
||||
baseUrl: baseUri.toString(),
|
||||
tokenOIDC: tokenOIDC,
|
||||
oidcConfiguration: oidcConfiguration,
|
||||
);
|
||||
|
||||
getSessionAction();
|
||||
}
|
||||
@@ -157,4 +203,12 @@ class TwakeWelcomeController extends ReloadableController {
|
||||
|
||||
toastManager.showMessageFailure(failure);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
if (PlatformInfo.isMobile) {
|
||||
_deepLinkDataStreamSubscription?.cancel();
|
||||
}
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user