TF-2901 Implement getting cache composer on log in

This commit is contained in:
DatDang
2024-06-18 15:24:20 +07:00
committed by Dat H. Pham
parent b2c92388f2
commit fc25194b02
3 changed files with 41 additions and 36 deletions
@@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:tmail_ui_user/features/base/widget/circle_loading_widget.dart'; import 'package:tmail_ui_user/features/base/widget/circle_loading_widget.dart';
import 'package:tmail_ui_user/features/composer/domain/state/download_image_as_base64_state.dart'; import 'package:tmail_ui_user/features/composer/domain/state/download_image_as_base64_state.dart';
import 'package:tmail_ui_user/features/composer/domain/state/restore_email_inline_images_state.dart';
import 'package:tmail_ui_user/features/upload/domain/state/attachment_upload_state.dart'; import 'package:tmail_ui_user/features/upload/domain/state/attachment_upload_state.dart';
class InsertImageLoadingBarWidget extends StatelessWidget { class InsertImageLoadingBarWidget extends StatelessWidget {
@@ -22,32 +23,27 @@ class InsertImageLoadingBarWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return uploadInlineViewState.fold( return uploadInlineViewState.fold(
(failure) { (failure) => _viewStateToUI(viewState),
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is DownloadingImageAsBase64) {
return CircleLoadingWidget(padding: padding);
} else {
return const SizedBox.shrink();
}
}
);
},
(success) { (success) {
if (success is UploadingAttachmentUploadState) { if (success is UploadingAttachmentUploadState) {
return CircleLoadingWidget(padding: padding); return CircleLoadingWidget(padding: padding);
} else { } else {
return viewState.fold( return _viewStateToUI(viewState);
(failure) => const SizedBox.shrink(), }
(success) { }
if (success is DownloadingImageAsBase64) { );
return CircleLoadingWidget(padding: padding); }
} else {
return const SizedBox.shrink(); Widget _viewStateToUI(Either<Failure, Success> viewState) {
} return viewState.fold(
} (failure) => const SizedBox.shrink(),
); (success) {
if (success is DownloadingImageAsBase64 ||
success is RestoringEmailInlineImages
) {
return CircleLoadingWidget(padding: padding);
} else {
return const SizedBox.shrink();
} }
} }
); );
@@ -1,5 +1,6 @@
import 'package:core/data/model/source_type/data_source_type.dart'; import 'package:core/data/model/source_type/data_source_type.dart';
import 'package:core/presentation/resources/image_paths.dart'; import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
import 'package:core/utils/config/app_config_loader.dart'; import 'package:core/utils/config/app_config_loader.dart';
import 'package:core/utils/file_utils.dart'; import 'package:core/utils/file_utils.dart';
import 'package:core/utils/print_utils.dart'; import 'package:core/utils/print_utils.dart';
@@ -232,7 +233,9 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.lazyPut(() => MailboxCacheDataSourceImpl( Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(), Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>())); Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => SessionStorageComposerDatasourceImpl()); Get.lazyPut(() => SessionStorageComposerDatasourceImpl(
Get.find<HtmlTransform>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => SpamReportDataSourceImpl( Get.lazyPut(() => SpamReportDataSourceImpl(
Get.find<SpamReportApi>(), Get.find<SpamReportApi>(),
Get.find<RemoteExceptionThrower>(), Get.find<RemoteExceptionThrower>(),
@@ -291,14 +291,12 @@ class MailboxDashBoardController extends ReloadableController {
} }
void _handleComposerCache() async { void _handleComposerCache() async {
_getEmailCacheOnWebInteractor.execute().fold( if (accountId.value == null || sessionCurrent == null) return;
(failure) {},
(success) { consumeState(
if (success is GetComposerCacheSuccess) { _getEmailCacheOnWebInteractor.execute(
goToComposer(ComposerArguments.fromSessionStorageBrowser(success.composerCache)); accountId.value!,
} sessionCurrent!.username));
},
);
} }
@override @override
@@ -373,6 +371,8 @@ class MailboxDashBoardController extends ReloadableController {
_handleGetRestoredDeletedMessageSuccess(success); _handleGetRestoredDeletedMessageSuccess(success);
} else if (success is GetAllIdentitiesSuccess) { } else if (success is GetAllIdentitiesSuccess) {
_handleGetAllIdentitiesSuccess(success); _handleGetAllIdentitiesSuccess(success);
} else if (success is GetComposerCacheSuccess) {
goToComposer(ComposerArguments.fromSessionStorageBrowser(success.composerCache));
} }
} }
@@ -466,7 +466,7 @@ class MailboxDashBoardController extends ReloadableController {
final arguments = Get.arguments; final arguments = Get.arguments;
log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments'); log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments');
if (arguments is Session) { if (arguments is Session) {
_handleSession(arguments); _handleSessionFromArguments(arguments);
} else if (arguments is MailtoArguments) { } else if (arguments is MailtoArguments) {
_handleMailtoURL(arguments); _handleMailtoURL(arguments);
} else if (arguments is PreviewEmailArguments) { } else if (arguments is PreviewEmailArguments) {
@@ -499,7 +499,7 @@ class MailboxDashBoardController extends ReloadableController {
} }
} }
void _handleSession(Session session) { void _handleSessionFromArguments(Session session) {
log('MailboxDashBoardController::_handleSession:'); log('MailboxDashBoardController::_handleSession:');
updateAuthenticationAccount( updateAuthenticationAccount(
session, session,
@@ -509,6 +509,10 @@ class MailboxDashBoardController extends ReloadableController {
_setUpComponentsFromSession(session); _setUpComponentsFromSession(session);
if (PlatformInfo.isWeb) {
_handleComposerCache();
}
if (PlatformInfo.isMobile && !_notificationManager.isNotificationClickedOnTerminate) { if (PlatformInfo.isMobile && !_notificationManager.isNotificationClickedOnTerminate) {
_handleClickLocalNotificationOnTerminated(); _handleClickLocalNotificationOnTerminated();
} else { } else {
@@ -539,13 +543,13 @@ class MailboxDashBoardController extends ReloadableController {
void _handleMailtoURL(MailtoArguments arguments) { void _handleMailtoURL(MailtoArguments arguments) {
log('MailboxDashBoardController::_handleMailtoURL:'); log('MailboxDashBoardController::_handleMailtoURL:');
routerParameters.value = arguments.toMapRouter(); routerParameters.value = arguments.toMapRouter();
_handleSession(arguments.session); _handleSessionFromArguments(arguments.session);
} }
void _handleOpenEmailAction(PreviewEmailArguments arguments) { void _handleOpenEmailAction(PreviewEmailArguments arguments) {
log('MailboxDashBoardController::_handleOpenEmailAction:arguments: $arguments'); log('MailboxDashBoardController::_handleOpenEmailAction:arguments: $arguments');
dispatchRoute(DashboardRoutes.waiting); dispatchRoute(DashboardRoutes.waiting);
_handleSession(arguments.session); _handleSessionFromArguments(arguments.session);
_handleNotificationMessageFromEmailId(arguments.emailId); _handleNotificationMessageFromEmailId(arguments.emailId);
} }
@@ -1398,7 +1402,9 @@ class MailboxDashBoardController extends ReloadableController {
} }
void goToComposer(ComposerArguments arguments) async { void goToComposer(ComposerArguments arguments) async {
final argumentsWithIdentity = arguments.withIdentity(identities: List.from(_identities ?? [])); final argumentsWithIdentity = arguments.withIdentity(
identities: List.from(_identities ?? []),
selectedIdentity: arguments.selectedIdentity);
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
if (composerOverlayState.value == ComposerOverlayState.inActive) { if (composerOverlayState.value == ComposerOverlayState.inActive) {