From 664d1825c0e5af18a0f7347407458f9d9dc69932 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 10 May 2023 16:57:05 +0700 Subject: [PATCH] TF-1810 Implement get detailed email from notification (cherry picked from commit 2bb972e9598d42758d7f1ab50c5e1d973c6fcd01) --- ...receive_email_from_notification_state.dart | 8 ++--- ...ve_email_from_notification_interactor.dart | 2 +- .../bindings/fcm_interactor_bindings.dart | 2 ++ .../listener/email_change_listener.dart | 36 +++++++++++++++++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/lib/features/push_notification/domain/state/get_new_receive_email_from_notification_state.dart b/lib/features/push_notification/domain/state/get_new_receive_email_from_notification_state.dart index edd04e2c7..10d1f6e6c 100644 --- a/lib/features/push_notification/domain/state/get_new_receive_email_from_notification_state.dart +++ b/lib/features/push_notification/domain/state/get_new_receive_email_from_notification_state.dart @@ -2,7 +2,7 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; -import 'package:jmap_dart_client/jmap/core/user_name.dart'; +import 'package:jmap_dart_client/jmap/core/session/session.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart'; class GetNewReceiveEmailFromNotificationLoading extends UIState {} @@ -11,12 +11,12 @@ class GetNewReceiveEmailFromNotificationSuccess extends UIState { final List emailIds; final AccountId accountId; - final UserName userName; + final Session? session; - GetNewReceiveEmailFromNotificationSuccess(this.accountId, this.userName, this.emailIds); + GetNewReceiveEmailFromNotificationSuccess(this.accountId, this.session, this.emailIds); @override - List get props => [accountId, userName, emailIds]; + List get props => [accountId, session, emailIds]; } class GetNewReceiveEmailFromNotificationFailure extends FeatureFailure { diff --git a/lib/features/push_notification/domain/usecases/get_new_receive_email_from_notification_interactor.dart b/lib/features/push_notification/domain/usecases/get_new_receive_email_from_notification_interactor.dart index 53d79c068..2c0ae2370 100644 --- a/lib/features/push_notification/domain/usecases/get_new_receive_email_from_notification_interactor.dart +++ b/lib/features/push_notification/domain/usecases/get_new_receive_email_from_notification_interactor.dart @@ -32,7 +32,7 @@ class GetNewReceiveEmailFromNotificationInteractor { accountId, currentState); - yield Right(GetNewReceiveEmailFromNotificationSuccess(accountId, userName, listEmailIds)); + yield Right(GetNewReceiveEmailFromNotificationSuccess(accountId, session, listEmailIds)); } else { yield Left(GetNewReceiveEmailFromNotificationFailure(EmailStateNoChangeException())); } diff --git a/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart b/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart index 458dcb7d0..95c486974 100644 --- a/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart +++ b/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart @@ -13,6 +13,7 @@ import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart'; import 'package:tmail_ui_user/features/email/data/network/email_api.dart'; import 'package:tmail_ui_user/features/email/data/repository/email_repository_impl.dart'; import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/get_detailed_email_by_id_interator.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart'; @@ -126,6 +127,7 @@ class FcmInteractorBindings extends InteractorsBindings { Get.lazyPut(() => GetNewReceiveEmailFromNotificationInteractor( Get.find(), Get.find())); + Get.lazyPut(() => GetDetailedEmailByIdInteractor(Get.find())); } @override diff --git a/lib/features/push_notification/presentation/listener/email_change_listener.dart b/lib/features/push_notification/presentation/listener/email_change_listener.dart index 410bce864..46133c819 100644 --- a/lib/features/push_notification/presentation/listener/email_change_listener.dart +++ b/lib/features/push_notification/presentation/listener/email_change_listener.dart @@ -1,6 +1,7 @@ import 'dart:io'; +import 'package:core/data/network/config/dynamic_url_interceptors.dart'; import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; import 'package:core/utils/app_logger.dart'; @@ -15,9 +16,13 @@ import 'package:model/email/email_property.dart'; import 'package:model/email/presentation_email.dart'; import 'package:model/extensions/list_presentation_email_extension.dart'; import 'package:model/extensions/list_presentation_mailbox_extension.dart'; +import 'package:model/extensions/session_extension.dart'; import 'package:model/notification/notification_payload.dart'; import 'package:tmail_ui_user/features/base/action/ui_action.dart'; +import 'package:tmail_ui_user/features/email/domain/model/detailed_email.dart'; +import 'package:tmail_ui_user/features/email/domain/state/get_detailed_email_by_id_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/get_stored_state_email_state.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/get_detailed_email_by_id_interator.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/get_stored_email_state_interactor.dart'; import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart'; @@ -54,6 +59,8 @@ class EmailChangeListener extends ChangeListener { GetMailboxesNotPutNotificationsInteractor? _getMailboxesNotPutNotificationsInteractor; GetEmailChangesToRemoveNotificationInteractor? _getEmailChangesToRemoveNotificationInteractor; GetNewReceiveEmailFromNotificationInteractor? _getNewReceiveEmailFromNotificationInteractor; + GetDetailedEmailByIdInteractor? _getDetailedEmailByIdInteractor; + DynamicUrlInterceptors? _dynamicUrlInterceptors; jmap.State? _newStateEmailDelivery; AccountId? _accountId; @@ -72,6 +79,8 @@ class EmailChangeListener extends ChangeListener { _getMailboxesNotPutNotificationsInteractor = getBinding(); _getEmailChangesToRemoveNotificationInteractor = getBinding(); _getNewReceiveEmailFromNotificationInteractor = getBinding(); + _getDetailedEmailByIdInteractor = getBinding(); + _dynamicUrlInterceptors = getBinding(); } catch (e) { logError('EmailChangeListener::_internal(): IS NOT REGISTERED: ${e.toString()}'); } @@ -229,7 +238,9 @@ class EmailChangeListener extends ChangeListener { } else if (success is GetEmailChangesToRemoveNotificationSuccess) { _handleRemoveLocalNotification(success.emailIds); } else if (success is GetNewReceiveEmailFromNotificationSuccess) { - _handleGetNewReceiveEmailFromNotificationSuccess(success.emailIds); + _handleGetNewReceiveEmailFromNotificationSuccess(success.session, success.accountId, success.emailIds); + } else if (success is GetDetailedEmailByIdSuccess) { + _handleGetDetailedEmailByIdActionSuccess(success.presentationEmail, success.detailedEmail); } } @@ -296,7 +307,28 @@ class EmailChangeListener extends ChangeListener { } } - void _handleGetNewReceiveEmailFromNotificationSuccess(List emailIds) async { + void _handleGetNewReceiveEmailFromNotificationSuccess(Session? session, AccountId accountId, List emailIds) { log('EmailChangeListener::_handleGetNewReceiveEmailFromNotificationSuccess():emailIds: $emailIds'); + for (var emailId in emailIds) { + _getDetailedEmailByIdAction(session, accountId, emailId); + } + } + + void _getDetailedEmailByIdAction(Session? session, AccountId accountId, EmailId emailId) { + if (_getDetailedEmailByIdInteractor != null && + _dynamicUrlInterceptors != null && + session != null) { + final baseDownloadUrl = session.getDownloadUrl(jmapUrl: _dynamicUrlInterceptors!.jmapUrl); + consumeState(_getDetailedEmailByIdInteractor!.execute( + session, + accountId, + emailId, + baseDownloadUrl + )); + } + } + + void _handleGetDetailedEmailByIdActionSuccess(PresentationEmail presentationEmail, DetailedEmail detailedEmail) { + log('EmailChangeListener::_handleGetDetailedEmailByIdActionSuccess():emailID: ${presentationEmail.id} | Content: ${detailedEmail.htmlEmailContent}'); } } \ No newline at end of file