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: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/restore_email_inline_images_state.dart';
import 'package:tmail_ui_user/features/upload/domain/state/attachment_upload_state.dart';
class InsertImageLoadingBarWidget extends StatelessWidget {
@@ -22,32 +23,27 @@ class InsertImageLoadingBarWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return uploadInlineViewState.fold(
(failure) {
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is DownloadingImageAsBase64) {
return CircleLoadingWidget(padding: padding);
} else {
return const SizedBox.shrink();
}
}
);
},
(failure) => _viewStateToUI(viewState),
(success) {
if (success is UploadingAttachmentUploadState) {
return CircleLoadingWidget(padding: padding);
} else {
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is DownloadingImageAsBase64) {
return CircleLoadingWidget(padding: padding);
} else {
return const SizedBox.shrink();
}
}
);
return _viewStateToUI(viewState);
}
}
);
}
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/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/file_utils.dart';
import 'package:core/utils/print_utils.dart';
@@ -232,7 +233,9 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => SessionStorageComposerDatasourceImpl());
Get.lazyPut(() => SessionStorageComposerDatasourceImpl(
Get.find<HtmlTransform>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => SpamReportDataSourceImpl(
Get.find<SpamReportApi>(),
Get.find<RemoteExceptionThrower>(),
@@ -291,14 +291,12 @@ class MailboxDashBoardController extends ReloadableController {
}
void _handleComposerCache() async {
_getEmailCacheOnWebInteractor.execute().fold(
(failure) {},
(success) {
if (success is GetComposerCacheSuccess) {
goToComposer(ComposerArguments.fromSessionStorageBrowser(success.composerCache));
}
},
);
if (accountId.value == null || sessionCurrent == null) return;
consumeState(
_getEmailCacheOnWebInteractor.execute(
accountId.value!,
sessionCurrent!.username));
}
@override
@@ -373,6 +371,8 @@ class MailboxDashBoardController extends ReloadableController {
_handleGetRestoredDeletedMessageSuccess(success);
} else if (success is GetAllIdentitiesSuccess) {
_handleGetAllIdentitiesSuccess(success);
} else if (success is GetComposerCacheSuccess) {
goToComposer(ComposerArguments.fromSessionStorageBrowser(success.composerCache));
}
}
@@ -466,7 +466,7 @@ class MailboxDashBoardController extends ReloadableController {
final arguments = Get.arguments;
log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments');
if (arguments is Session) {
_handleSession(arguments);
_handleSessionFromArguments(arguments);
} else if (arguments is MailtoArguments) {
_handleMailtoURL(arguments);
} else if (arguments is PreviewEmailArguments) {
@@ -499,7 +499,7 @@ class MailboxDashBoardController extends ReloadableController {
}
}
void _handleSession(Session session) {
void _handleSessionFromArguments(Session session) {
log('MailboxDashBoardController::_handleSession:');
updateAuthenticationAccount(
session,
@@ -509,6 +509,10 @@ class MailboxDashBoardController extends ReloadableController {
_setUpComponentsFromSession(session);
if (PlatformInfo.isWeb) {
_handleComposerCache();
}
if (PlatformInfo.isMobile && !_notificationManager.isNotificationClickedOnTerminate) {
_handleClickLocalNotificationOnTerminated();
} else {
@@ -539,13 +543,13 @@ class MailboxDashBoardController extends ReloadableController {
void _handleMailtoURL(MailtoArguments arguments) {
log('MailboxDashBoardController::_handleMailtoURL:');
routerParameters.value = arguments.toMapRouter();
_handleSession(arguments.session);
_handleSessionFromArguments(arguments.session);
}
void _handleOpenEmailAction(PreviewEmailArguments arguments) {
log('MailboxDashBoardController::_handleOpenEmailAction:arguments: $arguments');
dispatchRoute(DashboardRoutes.waiting);
_handleSession(arguments.session);
_handleSessionFromArguments(arguments.session);
_handleNotificationMessageFromEmailId(arguments.emailId);
}
@@ -1398,7 +1402,9 @@ class MailboxDashBoardController extends ReloadableController {
}
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 (composerOverlayState.value == ComposerOverlayState.inActive) {