From 6f4adc3f94bafad429b511647ebf467ff9ddfb76 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 29 May 2024 01:51:31 +0700 Subject: [PATCH] TF-2143 Implement delete composed email on local storage browser after open new tab completed --- .../local_storage_browser_datasource.dart | 2 ++ .../local_storage_browser_datasoure_impl.dart | 7 +++++++ .../composer_cache_repository_impl.dart | 5 +++++ .../repository/composer_cache_repository.dart | 2 ++ ..._email_on_local_storage_browser_state.dart | 11 ++++++++++ ...l_on_local_storage_browser_interactor.dart | 21 +++++++++++++++++++ .../bindings/mailbox_dashboard_bindings.dart | 3 +++ .../mailbox_dashboard_controller.dart | 10 +++++++++ .../mailbox_dashboard_controller_test.dart | 5 +++++ 9 files changed, 66 insertions(+) create mode 100644 lib/features/mailbox_dashboard/domain/state/delete_composed_email_on_local_storage_browser_state.dart create mode 100644 lib/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart diff --git a/lib/features/mailbox_dashboard/data/datasource/local_storage_browser_datasource.dart b/lib/features/mailbox_dashboard/data/datasource/local_storage_browser_datasource.dart index f4f9ea2509..2a2427c82d 100644 --- a/lib/features/mailbox_dashboard/data/datasource/local_storage_browser_datasource.dart +++ b/lib/features/mailbox_dashboard/data/datasource/local_storage_browser_datasource.dart @@ -4,4 +4,6 @@ abstract class LocalStorageBrowserDatasource { Future storeComposedEmail(Email email); Future getComposedEmail(); + + Future deleteComposedEmail(); } \ No newline at end of file diff --git a/lib/features/mailbox_dashboard/data/datasource_impl/local_storage_browser_datasoure_impl.dart b/lib/features/mailbox_dashboard/data/datasource_impl/local_storage_browser_datasoure_impl.dart index 3013d20c6a..32c450a6db 100644 --- a/lib/features/mailbox_dashboard/data/datasource_impl/local_storage_browser_datasoure_impl.dart +++ b/lib/features/mailbox_dashboard/data/datasource_impl/local_storage_browser_datasoure_impl.dart @@ -35,4 +35,11 @@ class LocalStorageBrowserDatasourceImpl extends LocalStorageBrowserDatasource { } }).catchError(_exceptionThrower.throwException); } + + @override + Future deleteComposedEmail() { + return Future.sync(() async { + return html.window.localStorage.remove(composedEmailLocalStorageKey); + }).catchError(_exceptionThrower.throwException); + } } diff --git a/lib/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart b/lib/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart index 03660f512f..1c0dbda13a 100644 --- a/lib/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart +++ b/lib/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart @@ -38,4 +38,9 @@ class ComposerCacheRepositoryImpl extends ComposerCacheRepository { Future storeComposedEmailToLocalStorageBrowser(Email email) { return _localStorageBrowserDatasource.storeComposedEmail(email); } + + @override + Future deleteComposedEmailOnLocalStorageBrowser() { + return _localStorageBrowserDatasource.deleteComposedEmail(); + } } \ No newline at end of file diff --git a/lib/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart b/lib/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart index 6866ff1a52..c9b98f6fe4 100644 --- a/lib/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart +++ b/lib/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart @@ -11,4 +11,6 @@ abstract class ComposerCacheRepository { Future storeComposedEmailToLocalStorageBrowser(Email email); Future getComposedEmailFromLocalStorageBrowser(); + + Future deleteComposedEmailOnLocalStorageBrowser(); } diff --git a/lib/features/mailbox_dashboard/domain/state/delete_composed_email_on_local_storage_browser_state.dart b/lib/features/mailbox_dashboard/domain/state/delete_composed_email_on_local_storage_browser_state.dart new file mode 100644 index 0000000000..d04169aa35 --- /dev/null +++ b/lib/features/mailbox_dashboard/domain/state/delete_composed_email_on_local_storage_browser_state.dart @@ -0,0 +1,11 @@ +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; + +class DeleteComposedEmailOnLocalStorageBrowserLoading extends LoadingState {} + +class DeleteComposedEmailOnLocalStorageBrowserSuccess extends UIState {} + +class DeleteComposedEmailOnLocalStorageBrowserFailure extends FeatureFailure { + + DeleteComposedEmailOnLocalStorageBrowserFailure(dynamic exception) : super(exception: exception); +} \ No newline at end of file diff --git a/lib/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart b/lib/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart new file mode 100644 index 0000000000..20455c88fd --- /dev/null +++ b/lib/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart @@ -0,0 +1,21 @@ +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/mailbox_dashboard/domain/repository/composer_cache_repository.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/delete_composed_email_on_local_storage_browser_state.dart'; + +class DeleteComposedEmailOnLocalStorageBrowserInteractor { + final ComposerCacheRepository _composerCacheRepository; + + DeleteComposedEmailOnLocalStorageBrowserInteractor(this._composerCacheRepository); + + Stream> execute() async* { + try { + yield Right(DeleteComposedEmailOnLocalStorageBrowserLoading()); + await _composerCacheRepository.deleteComposedEmailOnLocalStorageBrowser(); + yield Right(DeleteComposedEmailOnLocalStorageBrowserSuccess()); + } catch (exception) { + yield Left(DeleteComposedEmailOnLocalStorageBrowserFailure(exception)); + } + } +} diff --git a/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart b/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart index 7256f79488..48433bf46f 100644 --- a/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart +++ b/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart @@ -62,6 +62,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/data/repository/spam_re import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/search_repository.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/spam_report_repository.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_all_recent_search_latest_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_app_dashboard_configuration_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_composer_cache_on_web_interactor.dart'; @@ -181,6 +182,7 @@ class MailboxDashBoardBindings extends BaseBindings { Get.find(), Get.find(), Get.find(), + Get.find(), )); Get.put(AdvancedFilterController()); } @@ -288,6 +290,7 @@ class MailboxDashBoardBindings extends BaseBindings { ); Get.lazyPut(() => GetComposerCacheOnWebInteractor(Get.find())); Get.lazyPut(() => GetComposedEmailFromLocalStorageBrowserInteractor(Get.find())); + Get.lazyPut(() => DeleteComposedEmailOnLocalStorageBrowserInteractor(Get.find())); Get.lazyPut(() => RemoveComposerCacheOnWebInteractor(Get.find())); Get.lazyPut(() => MarkAsEmailReadInteractor( Get.find(), 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 0853d344a5..e43bf112c9 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -82,6 +82,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_app_da import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_composer_cache_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/remove_email_drafts_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_composed_email_from_local_storage_browser_state.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_composer_cache_on_web_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/remove_composer_cache_on_web_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/remove_email_drafts_interactor.dart'; @@ -192,6 +193,7 @@ class MailboxDashBoardController extends ReloadableController { final RemoveComposerCacheOnWebInteractor _removeComposerCacheOnWebInteractor; final GetAllIdentitiesInteractor _getAllIdentitiesInteractor; final GetComposedEmailFromLocalStorageBrowserInteractor _getComposedEmailFromLocalStorageBrowserInteractor; + final DeleteComposedEmailOnLocalStorageBrowserInteractor _deleteComposedEmailOnLocalStorageBrowserInteractor; GetAllVacationInteractor? _getAllVacationInteractor; UpdateVacationInteractor? _updateVacationInteractor; @@ -273,6 +275,7 @@ class MailboxDashBoardController extends ReloadableController { this._removeComposerCacheOnWebInteractor, this._getAllIdentitiesInteractor, this._getComposedEmailFromLocalStorageBrowserInteractor, + this._deleteComposedEmailOnLocalStorageBrowserInteractor, ); @override @@ -379,6 +382,7 @@ class MailboxDashBoardController extends ReloadableController { _handleGetAllIdentitiesSuccess(success); } else if (success is GetComposedEmailFromLocalStorageBrowserSuccess) { goToComposer(ComposerArguments.fromLocalStorageBrowser(success.email)); + _deleteComposedEmailOnLocalStorageBrowser(); } } @@ -403,6 +407,8 @@ class MailboxDashBoardController extends ReloadableController { _handleRestoreDeletedMessageFailed(); } else if (failure is GetRestoredDeletedMessageFailure) { _handleRestoreDeletedMessageFailed(); + } else if (failure is GetComposedEmailFromLocalStorageBrowserFailure) { + _deleteComposedEmailOnLocalStorageBrowser(); } } @@ -2557,6 +2563,10 @@ class MailboxDashBoardController extends ReloadableController { consumeState(_getComposedEmailFromLocalStorageBrowserInteractor.execute()); } + void _deleteComposedEmailOnLocalStorageBrowser() { + consumeState(_deleteComposedEmailOnLocalStorageBrowserInteractor.execute()); + } + @override void onClose() { _emailReceiveManager.closeEmailReceiveManagerStream(); diff --git a/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_test.dart b/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_test.dart index 0d10a61690..c8805d4652 100644 --- a/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_test.dart +++ b/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_test.dart @@ -46,6 +46,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/usecases/subscribe_multipl import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_controller.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart'; import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/delete_composed_email_on_local_storage_browser_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_all_recent_search_latest_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_composer_cache_on_web_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/quick_search_email_interactor.dart'; @@ -154,6 +155,7 @@ const fallbackGenerators = { MockSpec(), MockSpec(), MockSpec(), + MockSpec(), ]) void main() { // mock mailbox dashboard controller direct dependencies @@ -236,6 +238,7 @@ void main() { final removeComposerCacheOnWebInteractor = MockRemoveComposerCacheOnWebInteractor(); final getAllIdentitiesInteractor = MockGetAllIdentitiesInteractor(); final getComposedEmailFromLocalStorageBrowserInteractor = MockGetComposedEmailFromLocalStorageBrowserInteractor(); + final deleteComposedEmailOnLocalStorageBrowserInteractor = MockDeleteComposedEmailOnLocalStorageBrowserInteractor(); late MailboxController mailboxController; // mock thread controller direct dependencies @@ -289,6 +292,7 @@ void main() { Get.put(getAllIdentitiesInteractor); Get.put(removeComposerCacheOnWebInteractor); Get.put(getComposedEmailFromLocalStorageBrowserInteractor); + Get.put(deleteComposedEmailOnLocalStorageBrowserInteractor); Get.testMode = true; PackageInfo.setMockInitialValues( @@ -334,6 +338,7 @@ void main() { removeComposerCacheOnWebInteractor, getAllIdentitiesInteractor, getComposedEmailFromLocalStorageBrowserInteractor, + deleteComposedEmailOnLocalStorageBrowserInteractor, ); Get.put(mailboxDashboardController); mailboxDashboardController.onReady();