diff --git a/core/lib/presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart b/core/lib/presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart index a085814ea..ac579bba6 100644 --- a/core/lib/presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart +++ b/core/lib/presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart @@ -30,7 +30,11 @@ class AddTooltipLinkTransformer extends DomTransformer { if (children.isEmpty && text.isNotEmpty && url != null) { final innerHtml = element.innerHtml; final tagClass = element.attributes['class']; - element.attributes['class'] = '$tagClass $nameClassToolTip'; + if (tagClass != null) { + element.attributes['class'] = '$tagClass $nameClassToolTip'; + } else { + element.attributes['class'] = nameClassToolTip; + } element.innerHtml = innerHtml + textHasToolTip(url); } } diff --git a/core/lib/presentation/utils/html_transformer/dom/image_transformers.dart b/core/lib/presentation/utils/html_transformer/dom/image_transformers.dart index 28eeef2f8..0a237620c 100644 --- a/core/lib/presentation/utils/html_transformer/dom/image_transformers.dart +++ b/core/lib/presentation/utils/html_transformer/dom/image_transformers.dart @@ -23,20 +23,26 @@ class ImageTransformer extends DomTransformer { final imageElements = document.querySelectorAll('img[src^="cid:"]'); log('ImageTransformer::process(): imageElements: ${imageElements.length}'); await Future.wait(imageElements.map((imageElement) async { - final _exStyle = imageElement.attributes['style']; - imageElement.attributes['style'] = '$_exStyle display: inline;max-width: 100%;'; + final exStyle = imageElement.attributes['style']; + if (exStyle != null) { + imageElement.attributes['style'] = '$exStyle display: inline;max-width: 100%;'; + } else { + imageElement.attributes['style'] = 'display: inline;max-width: 100%;'; + } final src = imageElement.attributes['src']; - log('ImageTransformer::process(): src: $src'); - final cid = src?.replaceFirst('cid:', '').trim(); - final urlDownloadCid = mapUrlDownloadCID?[cid]; - log('ImageTransformer::process(): urlDownloadCid: $urlDownloadCid'); - if (urlDownloadCid?.isNotEmpty == true && dioClient != null) { - final imgBase64Uri = await loadAsyncNetworkImageToBase64( + if (src != null) { + log('ImageTransformer::process(): src: $src'); + final cid = src.replaceFirst('cid:', '').trim(); + final urlDownloadCid = mapUrlDownloadCID?[cid]; + log('ImageTransformer::process(): urlDownloadCid: $urlDownloadCid'); + if (urlDownloadCid?.isNotEmpty == true && dioClient != null) { + final imgBase64Uri = await loadAsyncNetworkImageToBase64( dioClient, compressFileUtils, urlDownloadCid!); - if (imgBase64Uri.isNotEmpty) { - imageElement.attributes['src'] = imgBase64Uri; + if (imgBase64Uri.isNotEmpty) { + imageElement.attributes['src'] = imgBase64Uri; + } } } })); diff --git a/lib/features/base/base_controller.dart b/lib/features/base/base_controller.dart index 1f976446b..3af670ccd 100644 --- a/lib/features/base/base_controller.dart +++ b/lib/features/base/base_controller.dart @@ -96,6 +96,7 @@ abstract class BaseController extends GetxController viewState.value.fold( (failure) { if (_handleCommonException(failure)) { + handleFinallyCommonException(); return; } handleFailureViewState(failure); @@ -113,6 +114,7 @@ abstract class BaseController extends GetxController void onError(Object error, StackTrace stackTrace) { logError('BaseController::onError():error: $error | stackTrace: $stackTrace'); if (_handleCommonError(error)) { + handleFinallyCommonException(); return; } handleErrorViewState(error, stackTrace); @@ -142,7 +144,6 @@ abstract class BaseController extends GetxController currentOverlayContext!, AppLocalizations.of(currentContext!).badCredentials); } - checkAuthenticationTypeWhenLogout(); return true; } @@ -152,6 +153,10 @@ abstract class BaseController extends GetxController void handleErrorViewState(Object error, StackTrace stackTrace) {} + void handleFinallyCommonException() { + clearState(); + } + void handleFailureViewState(Failure failure) { logError('BaseController::handleFailureViewState(): $failure'); if (failure is LogoutOidcFailure) { @@ -249,27 +254,18 @@ abstract class BaseController extends GetxController } } - bool fcmEnabled(Session? session, AccountId? accountId) { - bool fcmEnabled = false; - try { - requireCapability(session!, accountId!, [FirebaseCapability.fcmIdentifier]); - if (AppConfig.fcmAvailable) { - fcmEnabled = true; - } else { - fcmEnabled = false; - } - } catch (e) { - logError('BaseController::fcmEnabled(): exception: $e'); - } - return fcmEnabled; - } + bool _isFcmActivated(Session session, AccountId accountId) => + [FirebaseCapability.fcmIdentifier].isSupported(session, accountId) && AppConfig.fcmAvailable; void goToLogin({LoginArguments? arguments}) { pushAndPopAll(AppRoutes.login, arguments: arguments); } void logout(Session? session, AccountId? accountId) { - _isFcmEnabled = fcmEnabled(session, accountId); + if (session == null || accountId == null) { + return; + } + _isFcmEnabled = _isFcmActivated(session, accountId); final authenticationType = authorizationInterceptors.authenticationType; if (authenticationType == AuthenticationType.oidc) { consumeState(logoutOidcInteractor.execute()); diff --git a/lib/features/base/base_mailbox_controller.dart b/lib/features/base/base_mailbox_controller.dart index 5e1b3d497..3ecb69b60 100644 --- a/lib/features/base/base_mailbox_controller.dart +++ b/lib/features/base/base_mailbox_controller.dart @@ -112,9 +112,9 @@ abstract class BaseMailboxController extends BaseController { if (personalMailboxTree.value.updateExpandedNode(selectedMailboxNode, newExpandMode) != null) { log('toggleMailboxFolder() refresh folderMailboxTree'); personalMailboxTree.refresh(); - final _childrenItems = personalMailboxTree.value.root.childrenItems ?? []; + final childrenItems = personalMailboxTree.value.root.childrenItems ?? []; _triggerScrollWhenExpandMailboxFolder( - _childrenItems, + childrenItems, selectedMailboxNode, scrollController); } @@ -122,9 +122,9 @@ abstract class BaseMailboxController extends BaseController { if (teamMailboxesTree.value.updateExpandedNode(selectedMailboxNode, newExpandMode) != null) { log('toggleMailboxFolder() refresh teamMailboxesTree'); teamMailboxesTree.refresh(); - final _childrenItems = teamMailboxesTree.value.root.childrenItems ?? []; + final childrenItems = teamMailboxesTree.value.root.childrenItems ?? []; _triggerScrollWhenExpandMailboxFolder( - _childrenItems, + childrenItems, selectedMailboxNode, scrollController); } @@ -135,13 +135,13 @@ abstract class BaseMailboxController extends BaseController { MailboxNode selectedMailboxNode, ScrollController scrollController) async { await Future.delayed(const Duration(milliseconds: 200)); - final _lastItem = childrenItems.last; + final lastItem = childrenItems.last; if (selectedMailboxNode.expandMode == ExpandMode.COLLAPSE) { return; } - if (_lastItem.mailboxNameAsString.contains(selectedMailboxNode.mailboxNameAsString)) { + if (lastItem.mailboxNameAsString.contains(selectedMailboxNode.mailboxNameAsString)) { scrollController.animateTo( scrollController.position.maxScrollExtent, duration: const Duration(milliseconds: 200), diff --git a/lib/features/base/reloadable/reloadable_controller.dart b/lib/features/base/reloadable/reloadable_controller.dart index f00e30b1f..f97034f7e 100644 --- a/lib/features/base/reloadable/reloadable_controller.dart +++ b/lib/features/base/reloadable/reloadable_controller.dart @@ -3,7 +3,6 @@ import 'package:core/presentation/extensions/uri_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:dartz/dartz.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; @@ -35,30 +34,29 @@ abstract class ReloadableController extends BaseController { ); @override - void onData(Either newState) { - super.onData(newState); - viewState.value.fold( - (failure) { - if (failure is GetCredentialFailure) { - goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); - } else if (failure is GetSessionFailure) { - _handleGetSessionFailure(); - } else if (failure is GetStoredTokenOidcFailure) { - goToLogin(arguments: LoginArguments(LoginFormType.ssoForm)); - } else if (failure is GetAuthenticatedAccountFailure || failure is NoAuthenticatedAccountFailure) { - goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); - } - }, - (success) { - if (success is GetCredentialViewState) { - _handleGetCredentialSuccess(success); - } else if (success is GetSessionSuccess) { - _handleGetSessionSuccess(success); - } else if (success is GetStoredTokenOidcSuccess) { - _handleGetStoredTokenOIDCSuccess(success); - } - } - ); + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is GetCredentialFailure) { + goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); + } else if (failure is GetSessionFailure) { + _handleGetSessionFailure(); + } else if (failure is GetStoredTokenOidcFailure) { + goToLogin(arguments: LoginArguments(LoginFormType.ssoForm)); + } else if (failure is GetAuthenticatedAccountFailure || failure is NoAuthenticatedAccountFailure) { + goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); + } + } + + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetCredentialViewState) { + _handleGetCredentialSuccess(success); + } else if (success is GetSessionSuccess) { + _handleGetSessionSuccess(success); + } else if (success is GetStoredTokenOidcSuccess) { + _handleGetStoredTokenOIDCSuccess(success); + } } /* @@ -91,7 +89,7 @@ abstract class ReloadableController extends BaseController { } void _getSessionAction() { - consumeState(_getSessionInteractor.execute().asStream()); + consumeState(_getSessionInteractor.execute()); } void _handleGetSessionFailure() async { diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 5224d2b72..75cb92dbd 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -266,51 +266,44 @@ class ComposerController extends BaseController { } @override - void onData(Either newState) { - super.onData(newState); - newState.map((success) async { - if (success is GetEmailContentLoading) { - emailContentsViewState.value = Right(success); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetEmailContentLoading) { + emailContentsViewState.value = Right(success); + } else if (success is LocalFilePickerSuccess) { + _pickFileSuccess(success); + } else if (success is GetEmailContentSuccess) { + _getEmailContentSuccess(success); + } else if (success is GetAllIdentitiesSuccess) { + _handleGetAllIdentitiesSuccess(success); + } else if (success is DownloadImageAsBase64Success) { + if (BuildUtils.isWeb) { + richTextWebController.insertImage( + InlineImage( + ImageSource.local, + fileInfo: success.fileInfo, + cid: success.cid, + base64Uri: success.base64Uri)); + } else { + richTextMobileTabletController.insertImage( + InlineImage( + ImageSource.local, + fileInfo: success.fileInfo, + cid: success.cid, + base64Uri: success.base64Uri)); } - }); + maxWithEditor = null; + } } @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is LocalFilePickerFailure || failure is LocalFilePickerCancel) { - _pickFileFailure(failure); - } else if (failure is GetEmailContentFailure) { - emailContentsViewState.value = Left(failure); - } - }, - (success) { - if (success is LocalFilePickerSuccess) { - _pickFileSuccess(success); - } else if (success is GetEmailContentSuccess) { - _getEmailContentSuccess(success); - } else if (success is GetAllIdentitiesSuccess) { - _handleGetAllIdentitiesSuccess(success); - } else if (success is DownloadImageAsBase64Success) { - if(kIsWeb) { - richTextWebController.insertImage( - InlineImage( - ImageSource.local, - fileInfo: success.fileInfo, - cid: success.cid, - base64Uri: success.base64Uri)); - } else { - richTextMobileTabletController.insertImage( - InlineImage( - ImageSource.local, - fileInfo: success.fileInfo, - cid: success.cid, - base64Uri: success.base64Uri)); - } - maxWithEditor = null; - } - }); + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is LocalFilePickerFailure || failure is LocalFilePickerCancel) { + _pickFileFailure(failure); + } else if (failure is GetEmailContentFailure) { + emailContentsViewState.value = Left(failure); + } } void _listenWorker() { diff --git a/lib/features/contact/presentation/contact_controller.dart b/lib/features/contact/presentation/contact_controller.dart index bda1cfa68..17986f5f8 100644 --- a/lib/features/contact/presentation/contact_controller.dart +++ b/lib/features/contact/presentation/contact_controller.dart @@ -190,7 +190,4 @@ class ContactController extends BaseController { popBack(); } } - - @override - void onDone() {} } \ No newline at end of file diff --git a/lib/features/destination_picker/presentation/destination_picker_controller.dart b/lib/features/destination_picker/presentation/destination_picker_controller.dart index cccad51de..802ea9973 100644 --- a/lib/features/destination_picker/presentation/destination_picker_controller.dart +++ b/lib/features/destination_picker/presentation/destination_picker_controller.dart @@ -3,7 +3,6 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/utils/build_utils.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; @@ -112,42 +111,33 @@ class DestinationPickerController extends BaseMailboxController { } @override - void onData(Either newState) { - super.onData(newState); - newState.map((success) { - if (success is GetAllMailboxSuccess) { - if (mailboxAction.value == MailboxActions.move && mailboxIdSelected != null) { - buildTree( - success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes, - mailboxIdSelected: mailboxIdSelected - ); - } else { - buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes); - } - } else if (success is RefreshChangesAllMailboxSuccess) { - refreshTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllMailboxSuccess) { + if (mailboxAction.value == MailboxActions.move && mailboxIdSelected != null) { + buildTree( + success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes, + mailboxIdSelected: mailboxIdSelected); + } else { + buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes); } - }); + } else if (success is RefreshChangesAllMailboxSuccess) { + refreshTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes); + } else if (success is SearchMailboxSuccess) { + _searchMailboxSuccess(success); + } else if (success is CreateNewMailboxSuccess) { + _createNewMailboxSuccess(success); + } } @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is SearchMailboxFailure) { - _searchMailboxFailure(failure); - } else if (failure is CreateNewMailboxFailure) { - _createNewMailboxFailure(failure); - } - }, - (success) { - if (success is SearchMailboxSuccess) { - _searchMailboxSuccess(success); - } else if (success is CreateNewMailboxSuccess) { - _createNewMailboxSuccess(success); - } - } - ); + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is SearchMailboxFailure) { + _searchMailboxFailure(failure); + } else if (failure is CreateNewMailboxFailure) { + _createNewMailboxFailure(failure); + } } @override diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 4584ee234..b1afabc25 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -138,6 +138,44 @@ class SingleEmailController extends BaseController with AppLoaderMixin { super.onClose(); } + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetEmailContentSuccess) { + _getEmailContentSuccess(success); + } else if (success is MarkAsEmailReadSuccess) { + _markAsEmailReadSuccess(success); + } else if (success is ExportAttachmentSuccess) { + _exportAttachmentSuccessAction(success); + } else if (success is MoveToMailboxSuccess) { + _moveToMailboxSuccess(success); + } else if (success is MarkAsStarEmailSuccess) { + _markAsEmailStarSuccess(success); + } else if (success is DownloadAttachmentForWebSuccess) { + _downloadAttachmentForWebSuccessAction(success); + } else if (success is GetAllIdentitiesSuccess) { + _getAllIdentitiesSuccess(success); + } else if (success is SendReceiptToSenderSuccess) { + _sendReceiptToSenderSuccess(success); + } else if (success is CreateNewRuleFilterSuccess) { + _createNewRuleFilterSuccess(success); + } + } + + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is MarkAsEmailReadFailure) { + _markAsEmailReadFailure(failure); + } else if (failure is DownloadAttachmentsFailure) { + _downloadAttachmentsFailure(failure); + } else if (failure is ExportAttachmentFailure) { + _exportAttachmentFailureAction(failure); + } else if (failure is DownloadAttachmentForWebFailure) { + _downloadAttachmentForWebFailureAction(failure); + } + } + void _registerObxStreamListener() { ever(mailboxDashBoardController.accountId, (accountId) { if (accountId is AccountId) { @@ -311,43 +349,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin { } } - @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is MarkAsEmailReadFailure) { - _markAsEmailReadFailure(failure); - } else if (failure is DownloadAttachmentsFailure) { - _downloadAttachmentsFailure(failure); - } else if (failure is ExportAttachmentFailure) { - _exportAttachmentFailureAction(failure); - } else if (failure is DownloadAttachmentForWebFailure) { - _downloadAttachmentForWebFailureAction(failure); - } - }, - (success) { - if (success is GetEmailContentSuccess) { - _getEmailContentSuccess(success); - } else if (success is MarkAsEmailReadSuccess) { - _markAsEmailReadSuccess(success); - } else if (success is ExportAttachmentSuccess) { - _exportAttachmentSuccessAction(success); - } else if (success is MoveToMailboxSuccess) { - _moveToMailboxSuccess(success); - } else if (success is MarkAsStarEmailSuccess) { - _markAsEmailStarSuccess(success); - } else if (success is DownloadAttachmentForWebSuccess) { - _downloadAttachmentForWebSuccessAction(success); - } else if (success is GetAllIdentitiesSuccess) { - _getAllIdentitiesSuccess(success); - } else if (success is SendReceiptToSenderSuccess) { - _sendReceiptToSenderSuccess(success); - } else if (success is CreateNewRuleFilterSuccess) { - _createNewRuleFilterSuccess(success); - } - }); - } - void _getEmailContentSuccess(GetEmailContentSuccess success) { if(emailSupervisorController.presentationEmailsLoaded.length > ThreadConstants.defaultLimit.value.toInt()) { emailSupervisorController.popFirstEmailQueue(); diff --git a/lib/features/home/presentation/home_bindings.dart b/lib/features/home/presentation/home_bindings.dart index 300cd9dd5..3f1f2d07c 100644 --- a/lib/features/home/presentation/home_bindings.dart +++ b/lib/features/home/presentation/home_bindings.dart @@ -48,7 +48,6 @@ class HomeBindings extends BaseBindings { Get.find(), Get.find(), Get.find(), - Get.find(), )); } diff --git a/lib/features/home/presentation/home_controller.dart b/lib/features/home/presentation/home_controller.dart index 504ce952e..2969bef05 100644 --- a/lib/features/home/presentation/home_controller.dart +++ b/lib/features/home/presentation/home_controller.dart @@ -1,5 +1,4 @@ import 'package:core/core.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:get/get.dart'; @@ -17,16 +16,14 @@ 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/login/domain/state/check_oidc_is_available_state.dart'; +import 'package:tmail_ui_user/features/login/domain/state/get_authenticated_account_state.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/features/login/domain/usecases/check_oidc_is_available_interactor.dart'; import 'package:tmail_ui_user/features/login/domain/usecases/get_authenticated_account_interactor.dart'; import 'package:tmail_ui_user/features/login/presentation/login_form_type.dart'; import 'package:tmail_ui_user/features/login/presentation/model/login_arguments.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/utils/app_config.dart'; import 'package:tmail_ui_user/main/utils/email_receive_manager.dart'; class HomeController extends BaseController { @@ -37,7 +34,6 @@ class HomeController extends BaseController { final CleanupRecentSearchCacheInteractor _cleanupRecentSearchCacheInteractor; final CleanupRecentLoginUrlCacheInteractor _cleanupRecentLoginUrlCacheInteractor; final CleanupRecentLoginUsernameCacheInteractor _cleanupRecentLoginUsernameCacheInteractor; - final CheckOIDCIsAvailableInteractor _checkOIDCIsAvailableInteractor; HomeController( this._getAuthenticatedAccountInteractor, @@ -47,14 +43,12 @@ class HomeController extends BaseController { this._cleanupRecentSearchCacheInteractor, this._cleanupRecentLoginUrlCacheInteractor, this._cleanupRecentLoginUsernameCacheInteractor, - this._checkOIDCIsAvailableInteractor, ); Account? currentAccount; @override void onInit() { - log('HomeController::onInit(): '); if (!kIsWeb) { _initFlutterDownloader(); _registerReceivingSharingIntent(); @@ -120,65 +114,23 @@ class HomeController extends BaseController { } @override - void onData(Either newState) { - super.onData(newState); - newState.fold(_handleFailureViewState, _handleSuccessViewState); - } - - @override - void onDone() {} - - @override - void onError(error) { - _clearAllCacheAndCredential(); - } - - void _handleFailureViewState(Failure failure) async { - logError('HomeController::_handleFailureViewState(): ${failure.toString()}'); - if (failure is CheckOIDCIsAvailableFailure) { + void handleFailureViewState(Failure failure) async { + super.handleFailureViewState(failure); + if (failure is NoAuthenticatedAccountFailure || + failure is GetAuthenticatedAccountFailure || + failure is GetStoredTokenOidcFailure || + failure is GetCredentialFailure) { _goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); - } else { - _clearAllCacheAndCredential(); } } - void _handleSuccessViewState(Success success) { - log('HomeController::_handleSuccessViewState(): $success'); + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); if (success is GetStoredTokenOidcSuccess) { _goToSessionWithTokenOidc(success); } else if (success is GetCredentialViewState) { _goToSessionWithBasicAuth(success); - } else if (success is CheckOIDCIsAvailableSuccess) { - _goToLogin(arguments: LoginArguments(LoginFormType.ssoForm)); - } - } - - void _clearAllCacheAndCredential() async { - await Future.wait([ - deleteCredentialInteractor.execute(), - deleteAuthorityOidcInteractor.execute(), - cachingManager.clearAll() - ]).then((value) { - if (BuildUtils.isWeb) { - _checkOIDCIsAvailable(); - } else { - _goToLogin(); - } - }); - } - - Uri? _parseUri(String? url) => url != null && url.trim().isNotEmpty - ? Uri.parse(url.trim()) - : null; - - void _checkOIDCIsAvailable() async { - final baseUri = _parseUri(AppConfig.baseUrl); - if (baseUri != null) { - consumeState(_checkOIDCIsAvailableInteractor.execute(OIDCRequest( - baseUrl: baseUri.toString(), - resourceUrl: baseUri.origin))); - } else { - _goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); } } diff --git a/lib/features/identity_creator/presentation/identity_creator_controller.dart b/lib/features/identity_creator/presentation/identity_creator_controller.dart index 5256a18d3..912be010a 100644 --- a/lib/features/identity_creator/presentation/identity_creator_controller.dart +++ b/lib/features/identity_creator/presentation/identity_creator_controller.dart @@ -1,4 +1,6 @@ +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/build_utils.dart'; import 'package:flutter/cupertino.dart'; @@ -137,19 +139,19 @@ class IdentityCreatorController extends BaseController { } @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is GetAllIdentitiesFailure) { - _getALlIdentitiesFailure(failure); - } - }, - (success) { - if (success is GetAllIdentitiesSuccess) { - _getALlIdentitiesSuccess(success); - } - } - ); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllIdentitiesSuccess) { + _getALlIdentitiesSuccess(success); + } + } + + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is GetAllIdentitiesFailure) { + _getALlIdentitiesFailure(failure); + } } void _checkDefaultIdentityIsSupported() { diff --git a/lib/features/login/presentation/base_login_view.dart b/lib/features/login/presentation/base_login_view.dart index a8cf6c459..5036c6a65 100644 --- a/lib/features/login/presentation/base_login_view.dart +++ b/lib/features/login/presentation/base_login_view.dart @@ -72,30 +72,24 @@ abstract class BaseLoginView extends GetWidget { Widget buildLoginButton(BuildContext context) { return Container( - margin: const EdgeInsets.only(bottom: 16, left: 24, right: 24), - width: responsiveUtils.getDeviceWidth(context),height: 48, - child: AbsorbPointer( - absorbing: !controller.networkConnectionController.isNetworkConnectionAvailable(), - child: ElevatedButton( - key: const Key('loginSubmitForm'), - style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith((Set states) => Colors.white), - backgroundColor: MaterialStateProperty.resolveWith( - (Set states) => AppColor.primaryColor.withOpacity( - controller.networkConnectionController.isNetworkConnectionAvailable() ? 1 : 0.5)), - shape: MaterialStateProperty.all(RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: const BorderSide(width: 0, color: AppColor.primaryColor) - )) - ), - child: Text(AppLocalizations.of(context).signIn, - style: const TextStyle(fontSize: 16, color: Colors.white) - ), - onPressed: () { - loginController.handleLoginPressed(); - } - ), + margin: const EdgeInsets.only(bottom: 16, left: 24, right: 24), + width: responsiveUtils.getDeviceWidth(context),height: 48, + child: ElevatedButton( + key: const Key('loginSubmitForm'), + style: ButtonStyle( + foregroundColor: MaterialStateProperty.resolveWith((Set states) => Colors.white), + backgroundColor: MaterialStateProperty.resolveWith((Set states) => AppColor.primaryColor), + shape: MaterialStateProperty.all(RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + side: const BorderSide(width: 0, color: AppColor.primaryColor) + )) + ), + onPressed: loginController.handleLoginPressed, + child: Text( + AppLocalizations.of(context).signIn, + style: const TextStyle(fontSize: 16, color: Colors.white) ) + ) ); } diff --git a/lib/features/login/presentation/login_controller.dart b/lib/features/login/presentation/login_controller.dart index 84579d231..0db67a368 100644 --- a/lib/features/login/presentation/login_controller.dart +++ b/lib/features/login/presentation/login_controller.dart @@ -48,7 +48,6 @@ import 'package:tmail_ui_user/features/login/presentation/login_form_type.dart'; import 'package:tmail_ui_user/features/login/presentation/model/login_arguments.dart'; import 'package:tmail_ui_user/features/login/presentation/state/login_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; -import 'package:tmail_ui_user/features/network_status_handle/presentation/network_connnection_controller.dart'; import 'package:tmail_ui_user/main/routes/app_routes.dart'; import 'package:tmail_ui_user/main/routes/navigation_router.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; @@ -74,7 +73,6 @@ class LoginController extends ReloadableController { final TextEditingController urlInputController = TextEditingController(); final TextEditingController usernameInputController = TextEditingController(); - final NetworkConnectionController networkConnectionController = Get.find(); LoginController( LogoutOidcInteractor logoutOidcInteractor, @@ -140,54 +138,59 @@ class LoginController extends ReloadableController { } @override - void onData(Either newState) { - super.onData(newState); - viewState.value.fold( - (failure) { - if (failure is GetAuthenticationInfoFailure) { - getAuthenticatedAccountAction(); - } else if (failure is CheckOIDCIsAvailableFailure || - failure is GetStoredOidcConfigurationFailure) { - _showFormLoginWithCredentialAction(); - } else if (failure is GetOIDCIsAvailableFailure) { - loginState.value = LoginState(Left(LoginSSONotAvailableAction())); - _showFormLoginWithCredentialAction(); - } else if (failure is AuthenticationUserFailure) { - _loginFailureAction(failure); - } else if (failure is GetOIDCConfigurationFailure || - failure is GetTokenOIDCFailure || - failure is AuthenticateOidcOnBrowserFailure) { - loginState.value = LoginState(Left(failure)); - } - }, - (success) { - if (success is GetAuthenticationInfoSuccess) { - _getStoredOidcConfiguration(); - } else if (success is GetStoredOidcConfigurationSuccess) { - _getTokenOIDCAction(success.oidcConfiguration); - } else if (success is CheckOIDCIsAvailableSuccess) { - _showFormLoginWithSSOAction(success); - } else if (success is GetOIDCIsAvailableSuccess) { - loginState.value = LoginState(Right(success)); - _oidcResponse = success.oidcResponse; - _getOIDCConfiguration(); - } else if (success is GetOIDCConfigurationSuccess) { - _getOIDCConfigurationSuccess(success); - } else if (success is GetTokenOIDCSuccess) { - _getTokenOIDCSuccess(success); - } else if (success is AuthenticationUserSuccess) { - _loginSuccessAction(success); - } else if (success is GetAuthenticationInfoLoading || - success is CheckOIDCIsAvailableLoading || - success is GetStoredOidcConfigurationLoading || - success is GetOIDCConfigurationLoading || - success is GetTokenOIDCLoading || - success is AuthenticationUserLoading || - success is GetOIDCIsAvailableLoading) { - loginState.value = LoginState(Right(LoginLoadingAction())); - } - } - ); + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is GetAuthenticationInfoFailure) { + getAuthenticatedAccountAction(); + } else if (failure is CheckOIDCIsAvailableFailure || + failure is GetStoredOidcConfigurationFailure) { + _showFormLoginWithCredentialAction(); + } else if (failure is GetOIDCIsAvailableFailure) { + loginState.value = LoginState(Left(LoginSSONotAvailableAction())); + _showFormLoginWithCredentialAction(); + } else if (failure is AuthenticationUserFailure) { + _loginFailureAction(failure); + } else if (failure is GetOIDCConfigurationFailure || + failure is GetTokenOIDCFailure || + failure is AuthenticateOidcOnBrowserFailure) { + loginState.value = LoginState(Left(failure)); + } + } + + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAuthenticationInfoSuccess) { + _getStoredOidcConfiguration(); + } else if (success is GetStoredOidcConfigurationSuccess) { + _getTokenOIDCAction(success.oidcConfiguration); + } else if (success is CheckOIDCIsAvailableSuccess) { + _showFormLoginWithSSOAction(success); + } else if (success is GetOIDCIsAvailableSuccess) { + loginState.value = LoginState(Right(success)); + _oidcResponse = success.oidcResponse; + _getOIDCConfiguration(); + } else if (success is GetOIDCConfigurationSuccess) { + _getOIDCConfigurationSuccess(success); + } else if (success is GetTokenOIDCSuccess) { + _getTokenOIDCSuccess(success); + } else if (success is AuthenticationUserSuccess) { + _loginSuccessAction(success); + } else if (success is GetAuthenticationInfoLoading || + success is CheckOIDCIsAvailableLoading || + success is GetStoredOidcConfigurationLoading || + success is GetOIDCConfigurationLoading || + success is GetTokenOIDCLoading || + success is AuthenticationUserLoading || + success is GetOIDCIsAvailableLoading) { + loginState.value = LoginState(Right(LoginLoadingAction())); + } + } + + @override + void handleFinallyCommonException() { + super.handleFinallyCommonException(); + loginState.value = LoginState(Right(LoginInitAction())); } @override @@ -404,7 +407,4 @@ class LoginController extends ReloadableController { urlInputController.clear(); super.onClose(); } - - @override - void onDone() {} } \ No newline at end of file diff --git a/lib/features/login/presentation/login_view.dart b/lib/features/login/presentation/login_view.dart index 2ee868ae5..c9481cd36 100644 --- a/lib/features/login/presentation/login_view.dart +++ b/lib/features/login/presentation/login_view.dart @@ -178,27 +178,23 @@ class LoginView extends BaseLoginView { return Container( margin: const EdgeInsets.only(bottom: 16, left: 24, right: 24), width: responsiveUtils.getDeviceWidth(context),height: 48, - child: AbsorbPointer( - absorbing: !controller.networkConnectionController.isNetworkConnectionAvailable(), - child: ElevatedButton( - key: const Key('nextToCredentialForm'), - style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith((Set states) => Colors.white), - backgroundColor: MaterialStateProperty.resolveWith( - (Set states) => AppColor.primaryColor.withOpacity( - controller.networkConnectionController.isNetworkConnectionAvailable() ? 1 : 0.5)), - shape: MaterialStateProperty.all(RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: const BorderSide(width: 0, color: AppColor.primaryColor) - )) - ), - child: Text(AppLocalizations.of(context).next, - style: const TextStyle(fontSize: 16, color: Colors.white) - ), - onPressed: () { - loginController.handleNextInUrlInputFormPress(); - } + child: ElevatedButton( + key: const Key('nextToCredentialForm'), + style: ButtonStyle( + foregroundColor: MaterialStateProperty.resolveWith((Set states) => Colors.white), + backgroundColor: MaterialStateProperty.resolveWith( + (Set states) => AppColor.primaryColor), + shape: MaterialStateProperty.all(RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + side: const BorderSide(width: 0, color: AppColor.primaryColor) + )) ), + child: Text(AppLocalizations.of(context).next, + style: const TextStyle(fontSize: 16, color: Colors.white) + ), + onPressed: () { + loginController.handleNextInUrlInputFormPress(); + } ) ); } diff --git a/lib/features/login/presentation/login_view_web.dart b/lib/features/login/presentation/login_view_web.dart index 603bb11af..00eb35b30 100644 --- a/lib/features/login/presentation/login_view_web.dart +++ b/lib/features/login/presentation/login_view_web.dart @@ -276,27 +276,23 @@ class LoginView extends BaseLoginView { return Container( margin: const EdgeInsets.only(bottom: 16, left: 24, right: 24), width: responsiveUtils.getDeviceWidth(context),height: 48, - child: AbsorbPointer( - absorbing: !controller.networkConnectionController.isNetworkConnectionAvailable(), - child: ElevatedButton( - key: const Key('ssoSubmitForm'), - style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith((Set states) => Colors.white), - backgroundColor: MaterialStateProperty.resolveWith( - (Set states) => AppColor.primaryColor.withOpacity( - controller.networkConnectionController.isNetworkConnectionAvailable() ? 1 : 0.5)), - shape: MaterialStateProperty.all(RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: const BorderSide(width: 0, color: AppColor.primaryColor) - )) - ), - child: Text(AppLocalizations.of(context).singleSignOn, - style: const TextStyle(fontSize: 16, color: Colors.white) - ), - onPressed: () { - loginController.handleSSOPressed(); - } - ), + child: ElevatedButton( + key: const Key('ssoSubmitForm'), + style: ButtonStyle( + foregroundColor: MaterialStateProperty.resolveWith((Set states) => Colors.white), + backgroundColor: MaterialStateProperty.resolveWith( + (Set states) => AppColor.primaryColor), + shape: MaterialStateProperty.all(RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + side: const BorderSide(width: 0, color: AppColor.primaryColor) + )) + ), + child: Text(AppLocalizations.of(context).singleSignOn, + style: const TextStyle(fontSize: 16, color: Colors.white) + ), + onPressed: () { + loginController.handleSSOPressed(); + } ) ); } diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index b3ff8e2d5..795927dbc 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:core/core.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -146,53 +145,53 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM } @override - void onData(Either newState) { - super.onData(newState); - newState.map((success) async { - if (success is GetAllMailboxSuccess) { - _handleGetAllMailboxSuccess(success); - } else if (success is RefreshChangesAllMailboxSuccess) { - _handleRefreshChangesAllMailboxSuccess(success); - } - }); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllMailboxSuccess) { + _handleGetAllMailboxSuccess(success); + } else if (success is RefreshChangesAllMailboxSuccess) { + _handleRefreshChangesAllMailboxSuccess(success); + } else if (success is CreateNewMailboxSuccess) { + _createNewMailboxSuccess(success); + } else if (success is DeleteMultipleMailboxAllSuccess) { + _deleteMultipleMailboxSuccess(success.listMailboxIdDeleted, success.currentMailboxState); + } else if (success is DeleteMultipleMailboxHasSomeSuccess) { + _deleteMultipleMailboxSuccess(success.listMailboxIdDeleted, success.currentMailboxState); + } else if (success is RenameMailboxSuccess) { + _refreshMailboxChanges(currentMailboxState: success.currentMailboxState); + } else if (success is MoveMailboxSuccess) { + _moveMailboxSuccess(success); + } else if (success is SubscribeMailboxSuccess) { + _handleUnsubscribeMailboxSuccess(success); + } else if (success is SubscribeMultipleMailboxAllSuccess) { + _handleUnsubscribeMultipleMailboxAllSuccess(success); + } else if (success is SubscribeMultipleMailboxHasSomeSuccess) { + _handleUnsubscribeMultipleMailboxHasSomeSuccess(success); + } + } + + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is CreateNewMailboxFailure) { + _createNewMailboxFailure(failure); + } else if (failure is DeleteMultipleMailboxFailure) { + _deleteMailboxFailure(failure); + } } @override void onDone() { - viewState.value.fold( - (failure) { - if (failure is CreateNewMailboxFailure) { - _createNewMailboxFailure(failure); - } else if (failure is DeleteMultipleMailboxFailure) { - _deleteMailboxFailure(failure); - } - }, - (success) async { - if (success is GetAllMailboxSuccess) { - _initialMailboxVariableStorage(); - mailboxDashBoardController.getSpamReportBanner(); - } else if (success is RefreshChangesAllMailboxSuccess) { - _initialMailboxVariableStorage(isRefreshChange: true); - mailboxDashBoardController.refreshSpamReportBanner(); - } else if (success is CreateNewMailboxSuccess) { - _createNewMailboxSuccess(success); - } else if (success is DeleteMultipleMailboxAllSuccess) { - _deleteMultipleMailboxSuccess(success.listMailboxIdDeleted, success.currentMailboxState); - } else if (success is DeleteMultipleMailboxHasSomeSuccess) { - _deleteMultipleMailboxSuccess(success.listMailboxIdDeleted, success.currentMailboxState); - } else if (success is RenameMailboxSuccess) { - _refreshMailboxChanges(currentMailboxState: success.currentMailboxState); - } else if (success is MoveMailboxSuccess) { - _moveMailboxSuccess(success); - } else if (success is SubscribeMailboxSuccess) { - _handleUnsubscribeMailboxSuccess(success); - } else if (success is SubscribeMultipleMailboxAllSuccess) { - _handleUnsubscribeMultipleMailboxAllSuccess(success); - } else if (success is SubscribeMultipleMailboxHasSomeSuccess) { - _handleUnsubscribeMultipleMailboxHasSomeSuccess(success); - } + super.onDone(); + viewState.value.fold((failure) => null, (success) { + if (success is GetAllMailboxSuccess) { + _initialMailboxVariableStorage(); + mailboxDashBoardController.getSpamReportBanner(); + } else if (success is RefreshChangesAllMailboxSuccess) { + _initialMailboxVariableStorage(isRefreshChange: true); + mailboxDashBoardController.refreshSpamReportBanner(); } - ); + }); } void handleScrollEnable() { diff --git a/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart b/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart index 67cdb11fd..f290a98b2 100644 --- a/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart +++ b/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart @@ -69,9 +69,6 @@ class MailboxCreatorController extends BaseController { } } - @override - void onDone() {} - @override void onClose() { _disposeWidget(); diff --git a/lib/features/mailbox_dashboard/presentation/controller/advanced_filter_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/advanced_filter_controller.dart index ccef1c67b..3b1f9a796 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/advanced_filter_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/advanced_filter_controller.dart @@ -357,7 +357,4 @@ class AdvancedFilterController extends BaseController { _unregisterWorkerListener(); super.onClose(); } - - @override - void onDone() {} } diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index 6f59a2baf..257080dd4 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -80,7 +80,6 @@ import 'package:tmail_ui_user/features/manage_account/presentation/extensions/da import 'package:tmail_ui_user/features/manage_account/presentation/extensions/vacation_response_extension.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.dart'; -import 'package:tmail_ui_user/features/network_status_handle/presentation/network_connnection_controller.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart'; @@ -121,7 +120,6 @@ class MailboxDashBoardController extends ReloadableController { final EmailReceiveManager _emailReceiveManager = Get.find(); final SearchController searchController = Get.find(); final DownloadController downloadController = Get.find(); - final NetworkConnectionController networkConnectionController = Get.find(); final AppGridDashboardController appGridDashboardController = Get.find(); final SpamReportController spamReportController = Get.find(); @@ -252,97 +250,81 @@ class MailboxDashBoardController extends ReloadableController { } @override - void onData(Either newState) { - super.onData(newState); - viewState.value.fold( - (failure) { - log('MailboxDashBoardController::onData():failure $failure'); - }, - (success) { - log('MailboxDashBoardController::onData():success $success'); - if (success is SendingEmailState) { - if (currentOverlayContext != null && currentContext != null) { - _appToast.showToastMessage( - currentOverlayContext!, - AppLocalizations.of(currentContext!).your_email_being_sent, - leadingSVGIcon: _imagePaths.icSendToast - ); - } - } else if (success is GetEmailStateToRefreshSuccess) { - dispatchEmailUIAction(RefreshChangeEmailAction(success.storedState)); - _deleteEmailStateToRefreshAction(); - } else if (success is GetMailboxStateToRefreshSuccess) { - dispatchMailboxUIAction(RefreshChangeMailboxAction(success.storedState)); - _deleteMailboxStateToRefreshAction(); - } + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is SendingEmailState) { + if (currentOverlayContext != null && currentContext != null) { + _appToast.showToastMessage( + currentOverlayContext!, + AppLocalizations.of(currentContext!).your_email_being_sent, + leadingSVGIcon: _imagePaths.icSendToast); } - ); + } else if (success is GetEmailStateToRefreshSuccess) { + dispatchEmailUIAction(RefreshChangeEmailAction(success.storedState)); + _deleteEmailStateToRefreshAction(); + } else if (success is GetMailboxStateToRefreshSuccess) { + dispatchMailboxUIAction(RefreshChangeMailboxAction(success.storedState)); + _deleteMailboxStateToRefreshAction(); + } else if (success is SendEmailSuccess) { + if (currentOverlayContext != null && currentContext != null) { + _appToast.showToastSuccessMessage( + currentOverlayContext!, + AppLocalizations.of(currentContext!).message_has_been_sent_successfully, + leadingSVGIcon: _imagePaths.icSendSuccessToast); + } + } else if (success is SaveEmailAsDraftsSuccess) { + _saveEmailAsDraftsSuccess(success); + } else if (success is MoveToMailboxSuccess) { + _moveToMailboxSuccess(success); + } else if (success is DeleteEmailPermanentlySuccess) { + _deleteEmailPermanentlySuccess(success); + } else if (success is MarkAsMailboxReadAllSuccess || + success is MarkAsMailboxReadHasSomeEmailFailure) { + _markAsReadMailboxSuccess(success); + } else if (success is GetAllVacationSuccess) { + if (success.listVacationResponse.isNotEmpty) { + vacationResponse.value = success.listVacationResponse.first; + } + } else if (success is UpdateVacationSuccess) { + _handleUpdateVacationSuccess(success); + } else if (success is MarkAsMultipleEmailReadAllSuccess || + success is MarkAsMultipleEmailReadHasSomeEmailFailure) { + _markAsReadSelectedMultipleEmailSuccess(success); + } else if (success is MarkAsStarMultipleEmailAllSuccess || + success is MarkAsStarMultipleEmailHasSomeEmailFailure) { + _markAsStarMultipleEmailSuccess(success); + } else if (success is MoveMultipleEmailToMailboxAllSuccess || + success is MoveMultipleEmailToMailboxHasSomeEmailFailure) { + _moveSelectedMultipleEmailToMailboxSuccess(success); + } else if (success is EmptyTrashFolderSuccess) { + _emptyTrashFolderSuccess(success); + } else if (success is DeleteMultipleEmailsPermanentlyAllSuccess || + success is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) { + _deleteMultipleEmailsPermanentlySuccess(success); + } else if (success is GetAppDashboardConfigurationSuccess) { + appGridDashboardController.handleShowAppDashboard(success.linagoraApplications); + } else if(success is GetEmailByIdSuccess) { + _moveToEmailDetailedView(success); + } } @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is SendEmailFailure) { - _handleSendEmailFailure(failure); - } else if (failure is SaveEmailAsDraftsFailure) { - _handleSaveEmailAsDraftsFailure(failure); - } else if (failure is UpdateEmailDraftsFailure) { - _handleUpdateEmailAsDraftsFailure(failure); - } else if (failure is RemoveEmailDraftsFailure) { - clearState(); - } else if (failure is MarkAsMailboxReadAllFailure || - failure is MarkAsMailboxReadFailure) { - _markAsReadMailboxFailure(failure); - } else if (failure is GetEmailByIdFailure) { - _handleGetEmailDetailedFailed(failure); - } - }, - (success) { - if (success is SendEmailSuccess) { - if (currentOverlayContext != null && currentContext != null) { - _appToast.showToastSuccessMessage( - currentOverlayContext!, - AppLocalizations.of(currentContext!).message_has_been_sent_successfully, - leadingSVGIcon: _imagePaths.icSendSuccessToast); - } - } else if (success is SaveEmailAsDraftsSuccess) { - log('MailboxDashBoardController::onDone(): SaveEmailAsDraftsSuccess'); - _saveEmailAsDraftsSuccess(success); - } else if (success is MoveToMailboxSuccess) { - _moveToMailboxSuccess(success); - } else if (success is DeleteEmailPermanentlySuccess) { - _deleteEmailPermanentlySuccess(success); - } else if (success is MarkAsMailboxReadAllSuccess || - success is MarkAsMailboxReadHasSomeEmailFailure) { - _markAsReadMailboxSuccess(success); - } else if (success is GetAllVacationSuccess) { - if (success.listVacationResponse.isNotEmpty) { - vacationResponse.value = success.listVacationResponse.first; - } - } else if (success is UpdateVacationSuccess) { - _handleUpdateVacationSuccess(success); - } else if (success is MarkAsMultipleEmailReadAllSuccess - || success is MarkAsMultipleEmailReadHasSomeEmailFailure) { - _markAsReadSelectedMultipleEmailSuccess(success); - } else if (success is MarkAsStarMultipleEmailAllSuccess - || success is MarkAsStarMultipleEmailHasSomeEmailFailure) { - _markAsStarMultipleEmailSuccess(success); - } else if (success is MoveMultipleEmailToMailboxAllSuccess - || success is MoveMultipleEmailToMailboxHasSomeEmailFailure) { - _moveSelectedMultipleEmailToMailboxSuccess(success); - } else if (success is EmptyTrashFolderSuccess) { - _emptyTrashFolderSuccess(success); - } else if (success is DeleteMultipleEmailsPermanentlyAllSuccess - || success is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) { - _deleteMultipleEmailsPermanentlySuccess(success); - } else if (success is GetAppDashboardConfigurationSuccess) { - appGridDashboardController.handleShowAppDashboard(success.linagoraApplications); - } else if(success is GetEmailByIdSuccess) { - _moveToEmailDetailedView(success); - } - } - ); + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is SendEmailFailure) { + _handleSendEmailFailure(failure); + } else if (failure is SaveEmailAsDraftsFailure) { + _handleSaveEmailAsDraftsFailure(failure); + } else if (failure is UpdateEmailDraftsFailure) { + _handleUpdateEmailAsDraftsFailure(failure); + } else if (failure is RemoveEmailDraftsFailure) { + clearState(); + } else if (failure is MarkAsMailboxReadAllFailure || + failure is MarkAsMailboxReadFailure) { + _markAsReadMailboxFailure(failure); + } else if (failure is GetEmailByIdFailure) { + _handleGetEmailDetailedFailed(failure); + } } void _registerPendingEmailAddress() { diff --git a/lib/features/mailbox_dashboard/presentation/controller/search_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/search_controller.dart index e61a38eee..a7e4cc7ea 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/search_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/search_controller.dart @@ -303,9 +303,6 @@ class SearchController extends BaseController with DateRangePickerMixin { hideAdvancedSearchFormView(); } - @override - void onDone() {} - @override void onClose() { searchInputController.dispose(); diff --git a/lib/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart index 452776f0e..a9b45c25f 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart @@ -1,3 +1,5 @@ +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; @@ -39,29 +41,29 @@ class SpamReportController extends BaseController { ); @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is GetUnreadSpamMailboxFailure || failure is GetSpamMailboxCachedFailure) { - _presentationSpamMailbox.value = null; - } - }, - (success) { - if (success is GetUnreadSpamMailboxSuccess){ - _presentationSpamMailbox.value = success.unreadSpamMailbox.toPresentationMailbox(); - } else if (success is StoreLastTimeDismissedSpamReportSuccess) { - _presentationSpamMailbox.value = null; - } else if (success is GetSpamReportStateSuccess) { - _spamReportState.value = success.spamReportState; - } else if (success is StoreSpamReportStateSuccess) { - _spamReportState.value = success.spamReportState; - } else if (success is GetSpamMailboxCachedSuccess) { - _presentationSpamMailbox.value = success.spamMailbox.toPresentationMailbox(); - } - }, - ); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetUnreadSpamMailboxSuccess){ + _presentationSpamMailbox.value = success.unreadSpamMailbox.toPresentationMailbox(); + } else if (success is StoreLastTimeDismissedSpamReportSuccess) { + _presentationSpamMailbox.value = null; + } else if (success is GetSpamReportStateSuccess) { + _spamReportState.value = success.spamReportState; + } else if (success is StoreSpamReportStateSuccess) { + _spamReportState.value = success.spamReportState; + } else if (success is GetSpamMailboxCachedSuccess) { + _presentationSpamMailbox.value = success.spamMailbox.toPresentationMailbox(); + } } - + + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is GetUnreadSpamMailboxFailure || failure is GetSpamMailboxCachedFailure) { + _presentationSpamMailbox.value = null; + } + } + void dismissSpamReportAction() { if (Get.isRegistered()) { final mailboxDashBoardController = Get.find(); diff --git a/lib/features/manage_account/data/datasource_impl/identity_data_source_impl.dart b/lib/features/manage_account/data/datasource_impl/identity_data_source_impl.dart index a7997af27..bce58bc5c 100644 --- a/lib/features/manage_account/data/datasource_impl/identity_data_source_impl.dart +++ b/lib/features/manage_account/data/datasource_impl/identity_data_source_impl.dart @@ -4,9 +4,9 @@ import 'package:core/presentation/utils/html_transformer/dom/blockcode_transform import 'package:core/presentation/utils/html_transformer/dom/blockquoted_transformers.dart'; import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart'; import 'package:core/presentation/utils/html_transformer/dom/script_transformers.dart'; -import 'package:core/presentation/utils/html_transformer/dom/sigature_transformers.dart'; import 'package:core/presentation/utils/html_transformer/html_transform.dart'; import 'package:core/presentation/utils/html_transformer/transform_configuration.dart'; +import 'package:core/utils/build_utils.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; @@ -59,12 +59,11 @@ class IdentityDataSourceImpl extends IdentityDataSource { final signatureUnescape = await HtmlTransform(signature).transformToHtml( transformConfiguration: TransformConfiguration.create(customDomTransformers: [ const RemoveScriptTransformer(), - const SignatureTransformer(), const BlockQuotedTransformer(), const BlockCodeTransformer(), const AddTargetBlankInTagATransformer(), const ImageTransformer(), - const AddTooltipLinkTransformer() + if (BuildUtils.isWeb) const AddTooltipLinkTransformer() ])); return signatureUnescape; }).catchError(_exceptionThrower.throwException); diff --git a/lib/features/manage_account/presentation/email_rules/email_rules_controller.dart b/lib/features/manage_account/presentation/email_rules/email_rules_controller.dart index 5d696dc91..0018f3bbd 100644 --- a/lib/features/manage_account/presentation/email_rules/email_rules_controller.dart +++ b/lib/features/manage_account/presentation/email_rules/email_rules_controller.dart @@ -1,5 +1,6 @@ import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/resources/image_paths.dart'; +import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/presentation/utils/responsive_utils.dart'; import 'package:core/presentation/views/bottom_popup/confirmation_dialog_action_sheet_builder.dart'; @@ -46,25 +47,6 @@ class EmailRulesController extends BaseController { final listEmailRule = [].obs; - EmailRulesController(); - - @override - void onDone() { - viewState.value.fold((failure) {}, (success) { - if (success is GetAllRulesSuccess) { - if (success.rules?.isNotEmpty == true) { - listEmailRule.addAll(success.rules!); - } - } else if (success is DeleteEmailRuleSuccess) { - _handleDeleteEmailRuleSuccess(success); - } else if (success is CreateNewRuleFilterSuccess) { - _createNewRuleFilterSuccess(success); - } else if (success is EditEmailRuleFilterSuccess) { - _editEmailRuleFilterSuccess(success); - } - }); - } - @override void onInit() { super.onInit(); @@ -84,6 +66,22 @@ class EmailRulesController extends BaseController { super.onReady(); } + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllRulesSuccess) { + if (success.rules?.isNotEmpty == true) { + listEmailRule.addAll(success.rules!); + } + } else if (success is DeleteEmailRuleSuccess) { + _handleDeleteEmailRuleSuccess(success); + } else if (success is CreateNewRuleFilterSuccess) { + _createNewRuleFilterSuccess(success); + } else if (success is EditEmailRuleFilterSuccess) { + _editEmailRuleFilterSuccess(success); + } + } + void goToCreateNewRule(BuildContext context) async { final accountId = _accountDashBoardController.accountId.value; final session = _accountDashBoardController.sessionCurrent; diff --git a/lib/features/manage_account/presentation/forward/forward_controller.dart b/lib/features/manage_account/presentation/forward/forward_controller.dart index 65d044311..04de35c2c 100644 --- a/lib/features/manage_account/presentation/forward/forward_controller.dart +++ b/lib/features/manage_account/presentation/forward/forward_controller.dart @@ -1,5 +1,7 @@ import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/resources/image_paths.dart'; +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/utils/app_logger.dart'; import 'package:flutter/material.dart'; @@ -75,34 +77,35 @@ class ForwardController extends BaseController { super.onClose(); } - @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is DeleteRecipientInForwardingFailure) { - cancelSelectionMode(); - } - }, - (success) { - if (success is GetForwardSuccess) { - currentForward.value = success.forward; - listRecipientForward.value = currentForward.value!.listRecipientForward; - } else if (success is DeleteRecipientInForwardingSuccess) { - _handleDeleteRecipientSuccess(success); - } else if (success is AddRecipientsInForwardingSuccess) { - _handleAddRecipientsSuccess(success); - } else if (success is EditLocalCopyInForwardingSuccess) { - _handleEditLocalCopySuccess(success); - } - }); - } - @override void onReady() { _getForward(); super.onReady(); } + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetForwardSuccess) { + currentForward.value = success.forward; + listRecipientForward.value = currentForward.value!.listRecipientForward; + } else if (success is DeleteRecipientInForwardingSuccess) { + _handleDeleteRecipientSuccess(success); + } else if (success is AddRecipientsInForwardingSuccess) { + _handleAddRecipientsSuccess(success); + } else if (success is EditLocalCopyInForwardingSuccess) { + _handleEditLocalCopySuccess(success); + } + } + + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is DeleteRecipientInForwardingFailure) { + cancelSelectionMode(); + } + } + void _getForward() { if (_getForwardInteractor != null) { consumeState(_getForwardInteractor!.execute(accountDashBoardController.accountId.value!)); diff --git a/lib/features/manage_account/presentation/language_and_region/language_and_region_controller.dart b/lib/features/manage_account/presentation/language_and_region/language_and_region_controller.dart index c78de2260..0de0089de 100644 --- a/lib/features/manage_account/presentation/language_and_region/language_and_region_controller.dart +++ b/lib/features/manage_account/presentation/language_and_region/language_and_region_controller.dart @@ -1,6 +1,7 @@ import 'dart:ui'; +import 'package:core/presentation/state/success.dart'; import 'package:core/utils/app_logger.dart'; import 'package:get/get.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart'; @@ -25,14 +26,11 @@ class LanguageAndRegionController extends BaseController { } @override - void onDone() { - viewState.value.fold( - (failure) => null, - (success) { - if (success is SaveLanguageSuccess) { - LocalizationService.changeLocale(success.localeStored.languageCode); - } - }); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is SaveLanguageSuccess) { + LocalizationService.changeLocale(success.localeStored.languageCode); + } } void _setUpSupportedLanguages() { diff --git a/lib/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart b/lib/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart index 8b37fac63..6cc33ebee 100644 --- a/lib/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart +++ b/lib/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart @@ -1,6 +1,5 @@ import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/resources/image_paths.dart'; -import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/utils/app_logger.dart'; @@ -66,30 +65,21 @@ class MailboxVisibilityController extends BaseMailboxController { } @override - void onData(Either newState) { - super.onData(newState); - newState.fold((failure) => null, (success) { - if (success is GetAllMailboxSuccess) { - currentMailboxState = success.currentMailboxState; - _handleBuildTree(success.mailboxList); - } else if (success is RefreshChangesAllMailboxSuccess) { - currentMailboxState = success.currentMailboxState; - refreshTree(success.mailboxList); - } - }); - } - - @override - void onDone() { - viewState.value.fold((failure) {}, (success) { - if (success is SubscribeMailboxSuccess) { - _subscribeMailboxSuccess(success); - } else if (success is SubscribeMultipleMailboxAllSuccess) { - _handleUnsubscribeMultipleMailboxAllSuccess(success); - } else if (success is SubscribeMultipleMailboxHasSomeSuccess) { - _handleUnsubscribeMultipleMailboxHasSomeSuccess(success); - } - }); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllMailboxSuccess) { + currentMailboxState = success.currentMailboxState; + _handleBuildTree(success.mailboxList); + } else if (success is RefreshChangesAllMailboxSuccess) { + currentMailboxState = success.currentMailboxState; + refreshTree(success.mailboxList); + } else if (success is SubscribeMailboxSuccess) { + _subscribeMailboxSuccess(success); + } else if (success is SubscribeMultipleMailboxAllSuccess) { + _handleUnsubscribeMultipleMailboxAllSuccess(success); + } else if (success is SubscribeMultipleMailboxHasSomeSuccess) { + _handleUnsubscribeMultipleMailboxHasSomeSuccess(success); + } } @override diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart index e9cdaab38..d67623824 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart @@ -77,21 +77,17 @@ class ManageAccountDashBoardController extends ReloadableController { } @override - void onDone() { - viewState.value.fold( - (failure) {}, - (success) { - if (success is GetUserProfileSuccess) { - userProfile.value = success.userProfile; - } else if (success is GetAllVacationSuccess) { - if (success.listVacationResponse.isNotEmpty) { - vacationResponse.value = success.listVacationResponse.first; - } - } else if (success is UpdateVacationSuccess) { - _handleUpdateVacationSuccess(success); - } + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetUserProfileSuccess) { + userProfile.value = success.userProfile; + } else if (success is GetAllVacationSuccess) { + if (success.listVacationResponse.isNotEmpty) { + vacationResponse.value = success.listVacationResponse.first; } - ); + } else if (success is UpdateVacationSuccess) { + _handleUpdateVacationSuccess(success); + } } @override diff --git a/lib/features/manage_account/presentation/profiles/identities/identities_controller.dart b/lib/features/manage_account/presentation/profiles/identities/identities_controller.dart index 2238eb471..88159ce47 100644 --- a/lib/features/manage_account/presentation/profiles/identities/identities_controller.dart +++ b/lib/features/manage_account/presentation/profiles/identities/identities_controller.dart @@ -1,6 +1,8 @@ import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/resources/image_paths.dart'; +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/presentation/utils/responsive_utils.dart'; import 'package:core/presentation/views/dialog/confirmation_dialog_builder.dart'; @@ -72,29 +74,29 @@ class IdentitiesController extends BaseController { } @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is DeleteIdentityFailure) { - _deleteIdentityFailure(failure); - } - }, - (success) { - if (success is GetAllIdentitiesSuccess) { - _handleGetAllIdentitiesSuccess(success); - } else if (success is CreateNewIdentitySuccess) { - _createNewIdentitySuccess(success); - } else if (success is CreateNewDefaultIdentitySuccess) { - _createNewDefaultIdentitySuccess(success); - } else if (success is DeleteIdentitySuccess) { - _deleteIdentitySuccess(success); - } else if (success is EditIdentitySuccess) { - _editIdentitySuccess(success); - } else if (success is TransformHtmlSignatureSuccess) { - signatureSelected.value = success.signature; - } - } - ); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllIdentitiesSuccess) { + _handleGetAllIdentitiesSuccess(success); + } else if (success is CreateNewIdentitySuccess) { + _createNewIdentitySuccess(success); + } else if (success is CreateNewDefaultIdentitySuccess) { + _createNewDefaultIdentitySuccess(success); + } else if (success is DeleteIdentitySuccess) { + _deleteIdentitySuccess(success); + } else if (success is EditIdentitySuccess) { + _editIdentitySuccess(success); + } else if (success is TransformHtmlSignatureSuccess) { + signatureSelected.value = success.signature; + } + } + + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is DeleteIdentityFailure) { + _deleteIdentityFailure(failure); + } } void _registerObxStreamListener() { diff --git a/lib/features/manage_account/presentation/vacation/vacation_controller.dart b/lib/features/manage_account/presentation/vacation/vacation_controller.dart index 1166f81fc..93712f2a5 100644 --- a/lib/features/manage_account/presentation/vacation/vacation_controller.dart +++ b/lib/features/manage_account/presentation/vacation/vacation_controller.dart @@ -75,17 +75,13 @@ class VacationController extends BaseController { } @override - void onDone() { - viewState.value.fold( - (failure) => null, - (success) { - if (success is GetAllVacationSuccess) { - _handleGetAllVacationSuccess(success); - } else if (success is UpdateVacationSuccess) { - _handleUpdateVacationSuccess(success); - } - } - ); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllVacationSuccess) { + _handleGetAllVacationSuccess(success); + } else if (success is UpdateVacationSuccess) { + _handleUpdateVacationSuccess(success); + } } void _initWorker() { diff --git a/lib/features/network_status_handle/presentation/network_connnection_controller.dart b/lib/features/network_status_handle/presentation/network_connnection_controller.dart index 668b9c8f1..047f0a236 100644 --- a/lib/features/network_status_handle/presentation/network_connnection_controller.dart +++ b/lib/features/network_status_handle/presentation/network_connnection_controller.dart @@ -40,9 +40,6 @@ class NetworkConnectionController extends BaseController { super.onClose(); } - @override - void onDone() {} - void _getCurrentNetworkConnectionState() async { final currentConnectionResult = await _connectivity.checkConnectivity(); log('NetworkConnectionController::onReady():_getCurrentNetworkConnectionState: $currentConnectionResult'); diff --git a/lib/features/push_notification/presentation/controller/fcm_message_controller.dart b/lib/features/push_notification/presentation/controller/fcm_message_controller.dart index 203960679..32f70bb1c 100644 --- a/lib/features/push_notification/presentation/controller/fcm_message_controller.dart +++ b/lib/features/push_notification/presentation/controller/fcm_message_controller.dart @@ -257,7 +257,7 @@ class FcmMessageController extends FcmBaseController { void _getSessionAction() { if (_getSessionInteractor != null) { - consumeState(_getSessionInteractor!.execute().asStream()); + consumeState(_getSessionInteractor!.execute()); } else { _clearRemoteMessageBackground(); logError('FcmMessageController::_getSessionAction():_getSessionInteractor is null'); diff --git a/lib/features/quotas/presentation/quotas_controller.dart b/lib/features/quotas/presentation/quotas_controller.dart index 10c8f0acf..5a00a4dad 100644 --- a/lib/features/quotas/presentation/quotas_controller.dart +++ b/lib/features/quotas/presentation/quotas_controller.dart @@ -45,22 +45,6 @@ class QuotasController extends BaseController { } } - @override - void onDone() { - viewState.value.fold( - (failure) { - if (failure is GetQuotasFailure) { - logError('QuotasController::onDone():[GetQuotasFailure]: ${failure.exception}'); - } - }, - (success) { - if (success is GetQuotasSuccess) { - _handleGetQuotasSuccess(success); - } - } - ); - } - void _handleGetQuotasSuccess(GetQuotasSuccess success) { try { final quotas = success.quotas.firstWhere((e) => e.resourceType == ResourceType.octets); @@ -85,10 +69,6 @@ class QuotasController extends BaseController { } } - void covertBytesToGB() { - - } - void _initWorker() { accountIdWorker = ever(mailboxDashBoardController.accountId, (accountId) { if (accountId is AccountId && mailboxDashBoardController.sessionCurrent!= null) { @@ -108,4 +88,12 @@ class QuotasController extends BaseController { accountIdWorker.call(); super.onClose(); } + + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetQuotasSuccess) { + _handleGetQuotasSuccess(success); + } + } } diff --git a/lib/features/rules_filter_creator/presentation/rules_filter_creator_controller.dart b/lib/features/rules_filter_creator/presentation/rules_filter_creator_controller.dart index 931eb5d11..e76c7fa38 100644 --- a/lib/features/rules_filter_creator/presentation/rules_filter_creator_controller.dart +++ b/lib/features/rules_filter_creator/presentation/rules_filter_creator_controller.dart @@ -1,10 +1,8 @@ -import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/utils/app_logger.dart'; import 'package:core/utils/build_utils.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; @@ -116,28 +114,17 @@ class RulesFilterCreatorController extends BaseMailboxController { } @override - void onDone() { - viewState.value.fold((failure) {}, (success) { - if (success is GetAllRulesSuccess) { - log('RulesFilterCreatorController::onDone():GetAllRulesSuccess: ${success.rules}'); - if (success.rules?.isNotEmpty == true) { - _listEmailRule = success.rules!; - } + void handleSuccessViewState(Success success) async { + super.handleSuccessViewState(success); + if (success is GetAllMailboxSuccess) { + await buildTree(success.mailboxList); + _setUpMailboxSelected(); + } else if (success is GetAllRulesSuccess) { + log('RulesFilterCreatorController::handleSuccessViewState():GetAllRulesSuccess: ${success.rules}'); + if (success.rules?.isNotEmpty == true) { + _listEmailRule = success.rules!; } - }); - } - - @override - void onData(Either newState) { - super.onData(newState); - newState.fold( - (failure) => null, - (success) async { - if (success is GetAllMailboxSuccess) { - await buildTree(success.mailboxList); - _setUpMailboxSelected(); - } - }); + } } void _getAllRules() { diff --git a/lib/features/search/email/presentation/search_email_controller.dart b/lib/features/search/email/presentation/search_email_controller.dart index b0071f4e2..70cc19dbf 100644 --- a/lib/features/search/email/presentation/search_email_controller.dart +++ b/lib/features/search/email/presentation/search_email_controller.dart @@ -134,32 +134,28 @@ class SearchEmailController extends BaseController } @override - void onData(Either newState) { - super.onData(newState); - newState.fold( - (failure) { - if (failure is SearchEmailFailure) { - _searchEmailsFailure(failure); - } else if (failure is SearchMoreEmailFailure) { - _searchMoreEmailsFailure(failure); - } - }, - (success) { - if (success is SearchEmailSuccess) { - _searchEmailsSuccess(success); - } else if (success is SearchingMoreState) { - searchMoreState = SearchMoreState.waiting; - } else if (success is SearchMoreEmailSuccess) { - _searchMoreEmailsSuccess(success); - } else if (success is RefreshChangesSearchEmailSuccess) { - _refreshChangesSearchEmailsSuccess(success); - } - } - ); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is SearchEmailSuccess) { + _searchEmailsSuccess(success); + } else if (success is SearchingMoreState) { + searchMoreState = SearchMoreState.waiting; + } else if (success is SearchMoreEmailSuccess) { + _searchMoreEmailsSuccess(success); + } else if (success is RefreshChangesSearchEmailSuccess) { + _refreshChangesSearchEmailsSuccess(success); + } } @override - void onDone() {} + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is SearchEmailFailure) { + _searchEmailsFailure(failure); + } else if (failure is SearchMoreEmailFailure) { + _searchMoreEmailsFailure(failure); + } + } void _initializeDebounceTimeTextSearchChange() { _deBouncerTime = Debouncer( diff --git a/lib/features/search/mailbox/presentation/search_mailbox_controller.dart b/lib/features/search/mailbox/presentation/search_mailbox_controller.dart index 3e2afe318..961904ff0 100644 --- a/lib/features/search/mailbox/presentation/search_mailbox_controller.dart +++ b/lib/features/search/mailbox/presentation/search_mailbox_controller.dart @@ -7,7 +7,6 @@ import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/presentation/utils/responsive_utils.dart'; import 'package:core/utils/app_logger.dart'; import 'package:core/utils/build_utils.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; @@ -107,33 +106,24 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa } @override - void onDone() { - viewState.value.fold(_handleFailureViewState, _handleSuccessViewState); - } - - @override - void onData(Either newState) { - super.onData(newState); - newState.fold((failure) => null, (success) async { - if (success is GetAllMailboxSuccess) { - currentMailboxState = success.currentMailboxState; - buildTree(success.mailboxList); - } else if (success is RefreshChangesAllMailboxSuccess) { - currentMailboxState = success.currentMailboxState; - await refreshTree(success.mailboxList); - searchMailboxAction(); - } - }); - } - - void _handleFailureViewState(Failure failure) { + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); if (failure is SearchMailboxFailure) { _handleSearchMailboxFailure(failure); } } - void _handleSuccessViewState(Success success) { - if (success is SearchMailboxSuccess) { + @override + void handleSuccessViewState(Success success) async { + super.handleSuccessViewState(success); + if (success is GetAllMailboxSuccess) { + currentMailboxState = success.currentMailboxState; + buildTree(success.mailboxList); + } else if (success is RefreshChangesAllMailboxSuccess) { + currentMailboxState = success.currentMailboxState; + await refreshTree(success.mailboxList); + searchMailboxAction(); + } else if (success is SearchMailboxSuccess) { _handleSearchMailboxSuccess(success); } else if (success is MarkAsMailboxReadAllSuccess) { _refreshMailboxChanges(mailboxState: success.currentMailboxState); diff --git a/lib/features/session/domain/usecases/get_session_interactor.dart b/lib/features/session/domain/usecases/get_session_interactor.dart index 95d4973ec..b65a02e95 100644 --- a/lib/features/session/domain/usecases/get_session_interactor.dart +++ b/lib/features/session/domain/usecases/get_session_interactor.dart @@ -1,4 +1,5 @@ -import 'package:core/core.dart'; +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; import 'package:dartz/dartz.dart'; import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart'; import 'package:tmail_ui_user/features/session/domain/state/get_session_state.dart'; @@ -8,12 +9,12 @@ class GetSessionInteractor { GetSessionInteractor(this.sessionRepository); - Future> execute() async { + Stream> execute() async* { try { final session = await sessionRepository.getSession(); - return Right(GetSessionSuccess(session)); + yield Right(GetSessionSuccess(session)); } catch (e) { - return Left(GetSessionFailure(e)); + yield Left(GetSessionFailure(e)); } } } \ No newline at end of file diff --git a/lib/features/session/presentation/session_controller.dart b/lib/features/session/presentation/session_controller.dart index c0c9f9cc9..55eceb8cc 100644 --- a/lib/features/session/presentation/session_controller.dart +++ b/lib/features/session/presentation/session_controller.dart @@ -1,6 +1,7 @@ import 'package:core/data/network/config/dynamic_url_interceptors.dart'; import 'package:core/presentation/extensions/uri_extension.dart'; import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/utils/app_logger.dart'; import 'package:get/get.dart'; @@ -49,6 +50,23 @@ class SessionController extends ReloadableController { } } + @override + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is GetSessionFailure) { + _handleSessionFailure(failure); + _goToLogin(); + } + } + + @override + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetSessionSuccess) { + _goToMailboxDashBoard(success); + } + } + @override void handleReloaded(Session session) { pushAndPop( @@ -57,15 +75,7 @@ class SessionController extends ReloadableController { } void _getSession() async { - await _getSessionInteractor.execute() - .then((response) => response.fold( - (failure) { - _handleSessionFailure(failure); - _goToLogin(); - }, - (success) => success is GetSessionSuccess - ? _goToMailboxDashBoard(success) - : _goToLogin())); + consumeState(_getSessionInteractor.execute()); } void _handleSessionFailure(Failure failure) { @@ -93,7 +103,7 @@ class SessionController extends ReloadableController { } bool _checkUrlError(dynamic sessionException) { - return sessionException is ConnectError || sessionException is BadGateway; + return sessionException is ConnectError || sessionException is BadGateway || sessionException is SocketError; } void _goToLogin() async { @@ -121,7 +131,4 @@ class SessionController extends ReloadableController { _goToLogin(); } } - - @override - void onDone() {} } \ No newline at end of file diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index e3296e00d..2c1b5db57 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -146,50 +146,47 @@ class ThreadController extends BaseController with EmailActionController { } @override - void onData(Either newState) { - super.onData(newState); - newState.fold( - (failure) { - if (failure is SearchEmailFailure) { - canSearchMore = false; - mailboxDashBoardController.emailsInCurrentMailbox.clear(); - } else if (failure is SearchMoreEmailFailure || failure is LoadMoreEmailsFailure) { - _isLoadingMore = false; - } else if (failure is GetEmailByIdFailure) { - openingEmail.value = false; - _navigationRouter = null; - pushAndPop(AppRoutes.unknownRoutePage); - } - }, - (success) { - if (success is GetAllEmailSuccess) { - _getAllEmailSuccess(success); - } else if (success is RefreshChangesAllEmailSuccess) { - _refreshChangesAllEmailSuccess(success); - } else if (success is LoadMoreEmailsSuccess) { - _loadMoreEmailsSuccess(success); - } else if (success is SearchEmailSuccess) { - _searchEmailsSuccess(success); - } else if (success is SearchMoreEmailSuccess) { - _searchMoreEmailsSuccess(success); - } else if (success is SearchingMoreState || success is LoadingMoreState) { - _isLoadingMore = true; - } else if (success is GetEmailByIdLoading) { - openingEmail.value = true; - } else if (success is GetEmailByIdSuccess) { - openingEmail.value = false; - _openEmailDetailView(success.email); - } - } - ); + void handleSuccessViewState(Success success) { + super.handleSuccessViewState(success); + if (success is GetAllEmailSuccess) { + _getAllEmailSuccess(success); + } else if (success is RefreshChangesAllEmailSuccess) { + _refreshChangesAllEmailSuccess(success); + } else if (success is LoadMoreEmailsSuccess) { + _loadMoreEmailsSuccess(success); + } else if (success is SearchEmailSuccess) { + _searchEmailsSuccess(success); + } else if (success is SearchMoreEmailSuccess) { + _searchMoreEmailsSuccess(success); + } else if (success is SearchingMoreState || success is LoadingMoreState) { + _isLoadingMore = true; + } else if (success is GetEmailByIdLoading) { + openingEmail.value = true; + } else if (success is GetEmailByIdSuccess) { + openingEmail.value = false; + _openEmailDetailView(success.email); + } } @override - void onDone() {} + void handleFailureViewState(Failure failure) { + super.handleFailureViewState(failure); + if (failure is SearchEmailFailure) { + canSearchMore = false; + mailboxDashBoardController.emailsInCurrentMailbox.clear(); + } else if (failure is SearchMoreEmailFailure || failure is LoadMoreEmailsFailure) { + _isLoadingMore = false; + } else if (failure is GetEmailByIdFailure) { + openingEmail.value = false; + _navigationRouter = null; + pushAndPop(AppRoutes.unknownRoutePage); + } + } @override - void onError(error) { - _handleErrorGetAllOrRefreshChangesEmail(error); + void handleErrorViewState(Object error, StackTrace stackTrace) { + super.handleErrorViewState(error, stackTrace); + _handleErrorGetAllOrRefreshChangesEmail(error, stackTrace); } void _registerObxStreamListener() { @@ -337,13 +334,13 @@ class ThreadController extends BaseController with EmailActionController { _searchEmail(); } - void _handleErrorGetAllOrRefreshChangesEmail(dynamic error) async { + void _handleErrorGetAllOrRefreshChangesEmail(Object error, StackTrace stackTrace) async { logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error'); if (error is CannotCalculateChangesMethodResponseException) { await cachingManager.clearEmailCache(); _getAllEmailAction(); } else { - super.onError(error); + super.onError(error, stackTrace); } } diff --git a/lib/features/upload/presentation/controller/upload_controller.dart b/lib/features/upload/presentation/controller/upload_controller.dart index ba851bc4d..c842e2af9 100644 --- a/lib/features/upload/presentation/controller/upload_controller.dart +++ b/lib/features/upload/presentation/controller/upload_controller.dart @@ -340,12 +340,8 @@ class UploadController extends BaseController { } @override - void onDone() { - viewState.value.fold(_handleFailureViewState, _handleSuccessViewState); - } - - void _handleFailureViewState(Failure failure) async { - logError('UploadController::_handleFailureViewState():failure: $failure'); + void handleFailureViewState(Failure failure) async { + super.handleFailureViewState(failure); if (failure is UploadAttachmentFailure) { if (failure.isInline) { if (currentContext != null && currentOverlayContext != null) { @@ -367,8 +363,9 @@ class UploadController extends BaseController { } } - void _handleSuccessViewState(Success success) async { - log('UploadController::_handleSuccessViewState():success: $success'); + @override + void handleSuccessViewState(Success success) async { + super.handleSuccessViewState(success); if (success is UploadAttachmentSuccess) { if (success.isInline) { _uploadingStateInlineFiles.add(success.uploadAttachment.toUploadFileState()); diff --git a/lib/main/exceptions/remote_exception.dart b/lib/main/exceptions/remote_exception.dart index cd0b70caf..e9cb9be99 100644 --- a/lib/main/exceptions/remote_exception.dart +++ b/lib/main/exceptions/remote_exception.dart @@ -8,6 +8,7 @@ abstract class RemoteException with EquatableMixin implements Exception { static const internalServerError = 'Internal Server Error'; static const noNetworkError = 'No network error'; static const badCredentials = 'Bad credentials'; + static const socketException = 'Socket exception'; final String? message; final int? code; @@ -36,6 +37,13 @@ class ConnectError extends RemoteException { List get props => []; } +class SocketError extends RemoteException { + const SocketError() : super(message: RemoteException.socketException); + + @override + List get props => []; +} + class InternalServerError extends RemoteException { const InternalServerError() : super(message: RemoteException.internalServerError); diff --git a/lib/main/exceptions/remote_exception_thrower.dart b/lib/main/exceptions/remote_exception_thrower.dart index 9530bc4b6..cd9b3a8df 100644 --- a/lib/main/exceptions/remote_exception_thrower.dart +++ b/lib/main/exceptions/remote_exception_thrower.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:core/utils/app_logger.dart'; import 'package:dio/dio.dart'; import 'package:get/get_connect/http/src/status/http_status.dart'; @@ -20,7 +22,7 @@ class RemoteExceptionThrower extends ExceptionThrower { throw const NoNetworkError(); } else { if (error is DioError) { - logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response}'); + logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response} | error: ${error.error}'); switch (error.type) { case DioErrorType.connectionTimeout: throw const ConnectError(); @@ -31,6 +33,8 @@ class RemoteExceptionThrower extends ExceptionThrower { throw BadGateway(); } else if (error.response?.statusCode == HttpStatus.unauthorized) { throw const BadCredentialsException(); + } else if (error.error is SocketException) { + throw const SocketError(); } else { throw UnknownError( code: error.response?.statusCode,