Add GetAll and Refresh mailbox interactor to BaseMailboxController

This commit is contained in:
HuyNguyen
2023-02-14 13:04:12 +07:00
committed by Dat Vu
parent 969a36c080
commit 7703db7f5a
13 changed files with 189 additions and 135 deletions
+30 -1
View File
@@ -9,6 +9,8 @@ import 'package:core/utils/build_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/extensions/presentation_mailbox_extension.dart'; import 'package:model/extensions/presentation_mailbox_extension.dart';
import 'package:model/mailbox/expand_mode.dart'; import 'package:model/mailbox/expand_mode.dart';
@@ -22,6 +24,8 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_st
import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_mailbox_request.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_mailbox_request.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_request.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
@@ -42,11 +46,17 @@ import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
abstract class BaseMailboxController extends BaseController { abstract class BaseMailboxController extends BaseController {
final TreeBuilder _treeBuilder; final TreeBuilder _treeBuilder;
final VerifyNameInteractor verifyNameInteractor; final VerifyNameInteractor verifyNameInteractor;
final GetAllMailboxInteractor? getAllMailboxInteractor;
final RefreshAllMailboxInteractor? refreshAllMailboxInteractor;
jmap.State? currentMailboxState; jmap.State? currentMailboxState;
BaseMailboxController( BaseMailboxController(
this._treeBuilder, this._treeBuilder,
this.verifyNameInteractor this.verifyNameInteractor,
{
this.getAllMailboxInteractor,
this.refreshAllMailboxInteractor
}
); );
final personalMailboxTree = MailboxTree(MailboxNode.root()).obs; final personalMailboxTree = MailboxTree(MailboxNode.root()).obs;
@@ -416,4 +426,23 @@ abstract class BaseMailboxController extends BaseController {
} }
return null; return null;
} }
void getAllMailbox(Session session, AccountId accountId) async {
if (getAllMailboxInteractor != null) {
consumeState(getAllMailboxInteractor!.execute(session, accountId));
}
}
void refreshMailboxChanges(
Session session,
AccountId accountId,
jmap.State currentMailboxState
) {
if (refreshAllMailboxInteractor != null) {
log('BaseMailboxController::refreshMailboxChanges(): currentMailboxState: $currentMailboxState');
final newMailboxState = currentMailboxState;
log('BaseMailboxController::refreshMailboxChanges(): newMailboxState: $newMailboxState');
consumeState(refreshAllMailboxInteractor!.execute(session, accountId, newMailboxState));
}
}
} }
@@ -44,12 +44,12 @@ class DestinationPickerBindings extends BaseBindings {
@override @override
void bindingsController() { void bindingsController() {
Get.lazyPut(() => DestinationPickerController( Get.lazyPut(() => DestinationPickerController(
Get.find<GetAllMailboxInteractor>(),
Get.find<SearchMailboxInteractor>(), Get.find<SearchMailboxInteractor>(),
Get.find<CreateNewMailboxInteractor>(), Get.find<CreateNewMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>(),
Get.find<TreeBuilder>(), Get.find<TreeBuilder>(),
Get.find<VerifyNameInteractor>(), Get.find<VerifyNameInteractor>(),
Get.find<GetAllMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>(),
)); ));
} }
@@ -56,10 +56,8 @@ class DestinationPickerController extends BaseMailboxController {
final _imagePaths = Get.find<ImagePaths>(); final _imagePaths = Get.find<ImagePaths>();
final _responsiveUtils = Get.find<ResponsiveUtils>(); final _responsiveUtils = Get.find<ResponsiveUtils>();
final GetAllMailboxInteractor _getAllMailboxInteractor;
final SearchMailboxInteractor _searchMailboxInteractor; final SearchMailboxInteractor _searchMailboxInteractor;
final CreateNewMailboxInteractor _createNewMailboxInteractor; final CreateNewMailboxInteractor _createNewMailboxInteractor;
final RefreshAllMailboxInteractor _refreshAllMailboxInteractor;
final mailboxAction = Rxn<MailboxActions>(); final mailboxAction = Rxn<MailboxActions>();
final listMailboxSearched = <PresentationMailbox>[].obs; final listMailboxSearched = <PresentationMailbox>[].obs;
@@ -84,13 +82,18 @@ class DestinationPickerController extends BaseMailboxController {
List<String> listMailboxNameAsStringExist = <String>[]; List<String> listMailboxNameAsStringExist = <String>[];
DestinationPickerController( DestinationPickerController(
this._getAllMailboxInteractor,
this._searchMailboxInteractor, this._searchMailboxInteractor,
this._createNewMailboxInteractor, this._createNewMailboxInteractor,
this._refreshAllMailboxInteractor,
TreeBuilder treeBuilder, TreeBuilder treeBuilder,
VerifyNameInteractor verifyNameInteractor, VerifyNameInteractor verifyNameInteractor,
) : super(treeBuilder, verifyNameInteractor); GetAllMailboxInteractor getAllMailboxInteractor,
RefreshAllMailboxInteractor refreshAllMailboxInteractor
) : super(
treeBuilder,
verifyNameInteractor,
getAllMailboxInteractor : getAllMailboxInteractor,
refreshAllMailboxInteractor : refreshAllMailboxInteractor
);
@override @override
void onInit() { void onInit() {
@@ -159,13 +162,13 @@ class DestinationPickerController extends BaseMailboxController {
void getAllMailboxAction() { void getAllMailboxAction() {
if (accountId != null && _session != null) { if (accountId != null && _session != null) {
consumeState(_getAllMailboxInteractor.execute(_session!, accountId!)); getAllMailbox(_session!, accountId!);
} }
} }
void _refreshMailboxChanges(jmap.State currentMailboxState) { void _refreshMailboxChanges(jmap.State currentMailboxState) {
if (accountId != null && _session != null) { if (accountId != null && _session != null) {
consumeState(_refreshAllMailboxInteractor.execute(_session!, accountId!, currentMailboxState)); refreshMailboxChanges(_session!, accountId!, currentMailboxState);
} }
} }
@@ -48,8 +48,6 @@ class MailboxBindings extends BaseBindings {
@override @override
void bindingsController() { void bindingsController() {
Get.put(MailboxController( Get.put(MailboxController(
Get.find<GetAllMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>(),
Get.find<CreateNewMailboxInteractor>(), Get.find<CreateNewMailboxInteractor>(),
Get.find<DeleteMultipleMailboxInteractor>(), Get.find<DeleteMultipleMailboxInteractor>(),
Get.find<RenameMailboxInteractor>(), Get.find<RenameMailboxInteractor>(),
@@ -57,7 +55,9 @@ class MailboxBindings extends BaseBindings {
Get.find<SubscribeMailboxInteractor>(), Get.find<SubscribeMailboxInteractor>(),
Get.find<SubscribeMultipleMailboxInteractor>(), Get.find<SubscribeMultipleMailboxInteractor>(),
Get.find<TreeBuilder>(), Get.find<TreeBuilder>(),
Get.find<VerifyNameInteractor>() Get.find<VerifyNameInteractor>(),
Get.find<GetAllMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>()
)); ));
} }
@@ -9,7 +9,6 @@ import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart';
import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
@@ -86,8 +85,6 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
final _responsiveUtils = Get.find<ResponsiveUtils>(); final _responsiveUtils = Get.find<ResponsiveUtils>();
final _uuid = Get.find<Uuid>(); final _uuid = Get.find<Uuid>();
final isMailboxListScrollable = false.obs; final isMailboxListScrollable = false.obs;
final GetAllMailboxInteractor _getAllMailboxInteractor;
final RefreshAllMailboxInteractor _refreshAllMailboxInteractor;
final CreateNewMailboxInteractor _createNewMailboxInteractor; final CreateNewMailboxInteractor _createNewMailboxInteractor;
final DeleteMultipleMailboxInteractor _deleteMultipleMailboxInteractor; final DeleteMultipleMailboxInteractor _deleteMultipleMailboxInteractor;
final RenameMailboxInteractor _renameMailboxInteractor; final RenameMailboxInteractor _renameMailboxInteractor;
@@ -106,8 +103,6 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
PresentationEmail? get selectedEmail => mailboxDashBoardController.selectedEmail.value; PresentationEmail? get selectedEmail => mailboxDashBoardController.selectedEmail.value;
MailboxController( MailboxController(
this._getAllMailboxInteractor,
this._refreshAllMailboxInteractor,
this._createNewMailboxInteractor, this._createNewMailboxInteractor,
this._deleteMultipleMailboxInteractor, this._deleteMultipleMailboxInteractor,
this._renameMailboxInteractor, this._renameMailboxInteractor,
@@ -116,7 +111,14 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
this._subscribeMultipleMailboxInteractor, this._subscribeMultipleMailboxInteractor,
TreeBuilder treeBuilder, TreeBuilder treeBuilder,
VerifyNameInteractor verifyNameInteractor, VerifyNameInteractor verifyNameInteractor,
) : super(treeBuilder, verifyNameInteractor); GetAllMailboxInteractor getAllMailboxInteractor,
RefreshAllMailboxInteractor refreshAllMailboxInteractor,
) : super(
treeBuilder,
verifyNameInteractor,
getAllMailboxInteractor: getAllMailboxInteractor,
refreshAllMailboxInteractor: refreshAllMailboxInteractor
);
@override @override
void onInit() { void onInit() {
@@ -177,7 +179,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
} else if (success is DeleteMultipleMailboxHasSomeSuccess) { } else if (success is DeleteMultipleMailboxHasSomeSuccess) {
_deleteMultipleMailboxSuccess(success.listMailboxIdDeleted, success.currentMailboxState); _deleteMultipleMailboxSuccess(success.listMailboxIdDeleted, success.currentMailboxState);
} else if (success is RenameMailboxSuccess) { } else if (success is RenameMailboxSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MoveMailboxSuccess) { } else if (success is MoveMailboxSuccess) {
_moveMailboxSuccess(success); _moveMailboxSuccess(success);
} else if (success is SubscribeMailboxSuccess) { } else if (success is SubscribeMailboxSuccess) {
@@ -198,7 +200,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
void _registerObxStreamListener() { void _registerObxStreamListener() {
ever(mailboxDashBoardController.accountId, (accountId) { ever(mailboxDashBoardController.accountId, (accountId) {
if (accountId is AccountId) { if (accountId is AccountId) {
getAllMailboxAction(mailboxDashBoardController.sessionCurrent!, accountId); getAllMailbox(mailboxDashBoardController.sessionCurrent!, accountId);
} }
}); });
@@ -211,37 +213,37 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
if (state is Either) { if (state is Either) {
state.fold((failure) => null, (success) { state.fold((failure) => null, (success) {
if (success is MarkAsMultipleEmailReadAllSuccess) { if (success is MarkAsMultipleEmailReadAllSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MarkAsMultipleEmailReadHasSomeEmailFailure) { } else if (success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MoveMultipleEmailToMailboxAllSuccess) { } else if (success is MoveMultipleEmailToMailboxAllSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MoveMultipleEmailToMailboxHasSomeEmailFailure) { } else if (success is MoveMultipleEmailToMailboxHasSomeEmailFailure) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is DeleteMultipleEmailsPermanentlyAllSuccess) { } else if (success is DeleteMultipleEmailsPermanentlyAllSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) { } else if (success is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is EmptyTrashFolderSuccess) { } else if (success is EmptyTrashFolderSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MarkAsEmailReadSuccess) { } else if (success is MarkAsEmailReadSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MoveToMailboxSuccess) { } else if (success is MoveToMailboxSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is DeleteEmailPermanentlySuccess) { } else if (success is DeleteEmailPermanentlySuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is SaveEmailAsDraftsSuccess) { } else if (success is SaveEmailAsDraftsSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is RemoveEmailDraftsSuccess) { } else if (success is RemoveEmailDraftsSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is SendEmailSuccess) { } else if (success is SendEmailSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MarkAsMailboxReadAllSuccess) { } else if (success is MarkAsMailboxReadAllSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MarkAsMailboxReadHasSomeEmailFailure) { } else if (success is MarkAsMailboxReadHasSomeEmailFailure) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is UpdateEmailDraftsSuccess) { } else if (success is UpdateEmailDraftsSuccess) {
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} }
}); });
} }
@@ -263,7 +265,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
mailboxDashBoardController.clearMailboxUIAction(); mailboxDashBoardController.clearMailboxUIAction();
} else if (action is RefreshChangeMailboxAction) { } else if (action is RefreshChangeMailboxAction) {
if (action.newState != currentMailboxState) { if (action.newState != currentMailboxState) {
refreshMailboxChanges(); _refreshMailboxChanges();
} }
mailboxDashBoardController.clearMailboxUIAction(); mailboxDashBoardController.clearMailboxUIAction();
} }
@@ -282,27 +284,23 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
} }
} }
void getAllMailboxAction(Session session, AccountId accountId) async {
consumeState(_getAllMailboxInteractor.execute(session, accountId));
}
void refreshAllMailbox() { void refreshAllMailbox() {
final session = mailboxDashBoardController.sessionCurrent; final session = mailboxDashBoardController.sessionCurrent;
final accountId = mailboxDashBoardController.accountId.value; final accountId = mailboxDashBoardController.accountId.value;
if (session != null && accountId != null) { if (session != null && accountId != null) {
consumeState(_getAllMailboxInteractor.execute(session, accountId)); consumeState(getAllMailboxInteractor!.execute(session, accountId));
} }
} }
void refreshMailboxChanges({jmap.State? currentMailboxState}) { void _refreshMailboxChanges({jmap.State? currentMailboxState}) {
mailboxDashBoardController.showSpamReportBanner(); mailboxDashBoardController.showSpamReportBanner();
log('MailboxController::refreshMailboxChanges(): currentMailboxState: $currentMailboxState'); log('MailboxController::_refreshMailboxChanges(): currentMailboxState: $currentMailboxState');
final newMailboxState = currentMailboxState ?? this.currentMailboxState; final newMailboxState = currentMailboxState ?? this.currentMailboxState;
log('MailboxController::refreshMailboxChanges(): newMailboxState: $newMailboxState'); log('MailboxController::_refreshMailboxChanges(): newMailboxState: $newMailboxState');
final accountId = mailboxDashBoardController.accountId.value; final accountId = mailboxDashBoardController.accountId.value;
final session = mailboxDashBoardController.sessionCurrent; final session = mailboxDashBoardController.sessionCurrent;
if (accountId != null && session != null && newMailboxState != null) { if (accountId != null && session != null && newMailboxState != null) {
consumeState(_refreshAllMailboxInteractor.execute(session, accountId, newMailboxState)); refreshMailboxChanges(session, accountId, newMailboxState);
} }
} }
@@ -531,7 +529,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
maxWidth: _responsiveUtils.getMaxWidthToast(currentContext!)); maxWidth: _responsiveUtils.getMaxWidthToast(currentContext!));
} }
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} }
void _createNewMailboxFailure(CreateNewMailboxFailure failure) { void _createNewMailboxFailure(CreateNewMailboxFailure failure) {
@@ -676,7 +674,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
_switchBackToMailboxDefault(); _switchBackToMailboxDefault();
_closeEmailViewIfMailboxDisabledOrNotExist(listMailboxIdDeleted); _closeEmailViewIfMailboxDisabledOrNotExist(listMailboxIdDeleted);
} }
refreshMailboxChanges(currentMailboxState: currentMailboxState); _refreshMailboxChanges(currentMailboxState: currentMailboxState);
} }
void _openConfirmationDialogDeleteMultipleMailboxAction( void _openConfirmationDialogDeleteMultipleMailboxAction(
@@ -817,7 +815,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
maxWidth: _responsiveUtils.getMaxWidthToast(currentContext!)); maxWidth: _responsiveUtils.getMaxWidthToast(currentContext!));
} }
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} }
void _undoMovingMailbox(MoveMailboxRequest newMoveRequest) { void _undoMovingMailbox(MoveMailboxRequest newMoveRequest) {
@@ -1020,7 +1018,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
} }
} }
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} }
void _handleUnsubscribeMultipleMailboxAllSuccess(SubscribeMultipleMailboxAllSuccess success) { void _handleUnsubscribeMultipleMailboxAllSuccess(SubscribeMultipleMailboxAllSuccess success) {
@@ -1036,7 +1034,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
} }
} }
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} }
void _handleUnsubscribeMultipleMailboxHasSomeSuccess(SubscribeMultipleMailboxHasSomeSuccess success) { void _handleUnsubscribeMultipleMailboxHasSomeSuccess(SubscribeMultipleMailboxHasSomeSuccess success) {
@@ -1052,7 +1050,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
} }
} }
refreshMailboxChanges(currentMailboxState: success.currentMailboxState); _refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} }
void _closeEmailViewIfMailboxDisabledOrNotExist(List<MailboxId> mailboxIdsDisabled) { void _closeEmailViewIfMailboxDisabledOrNotExist(List<MailboxId> mailboxIdsDisabled) {
@@ -15,3 +15,4 @@ typedef OnClickOpenMailboxNodeAction = void Function(MailboxNode);
typedef OnSelectMailboxNodeAction = void Function(MailboxNode); typedef OnSelectMailboxNodeAction = void Function(MailboxNode);
typedef OnClickOpenMenuMailboxNodeAction = void Function(RelativeRect, MailboxNode); typedef OnClickOpenMenuMailboxNodeAction = void Function(RelativeRect, MailboxNode);
typedef OnLongPressMailboxNodeAction = void Function(MailboxNode); typedef OnLongPressMailboxNodeAction = void Function(MailboxNode);
typedef OnClickSubscribeMailboxAction = void Function(MailboxNode);
@@ -1,4 +1,6 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.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_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart';
@@ -9,7 +11,9 @@ class MailboxVisibilityBindings extends Bindings {
void dependencies() { void dependencies() {
Get.lazyPut(() => MailboxVisibilityController( Get.lazyPut(() => MailboxVisibilityController(
Get.find<TreeBuilder>(), Get.find<TreeBuilder>(),
Get.find<VerifyNameInteractor>() Get.find<VerifyNameInteractor>(),
Get.find<GetAllMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>(),
)); ));
_bindingsUtils(); _bindingsUtils();
} }
@@ -3,11 +3,10 @@ import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/presentation/utils/app_toast.dart';
import 'package:core/presentation/utils/responsive_utils.dart'; import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/utils/app_logger.dart'; import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/mailbox/expand_mode.dart'; import 'package:model/mailbox/expand_mode.dart';
@@ -30,13 +29,12 @@ import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_catego
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.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_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/state/mailbox_visibility_state.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class MailboxVisibilityController extends BaseMailboxController { class MailboxVisibilityController extends BaseMailboxController {
GetAllMailboxInteractor? _getAllMailboxInteractor;
RefreshAllMailboxInteractor? _refreshAllMailboxInteractor;
SubscribeMailboxInteractor? _subscribeMailboxInteractor; SubscribeMailboxInteractor? _subscribeMailboxInteractor;
SubscribeMultipleMailboxInteractor? _subscribeMultipleMailboxInteractor; SubscribeMultipleMailboxInteractor? _subscribeMultipleMailboxInteractor;
final _accountDashBoardController = Get.find<ManageAccountDashBoardController>(); final _accountDashBoardController = Get.find<ManageAccountDashBoardController>();
@@ -55,14 +53,19 @@ class MailboxVisibilityController extends BaseMailboxController {
MailboxVisibilityController( MailboxVisibilityController(
TreeBuilder treeBuilder, TreeBuilder treeBuilder,
VerifyNameInteractor verifyNameInteractor, VerifyNameInteractor verifyNameInteractor,
) : super(treeBuilder, verifyNameInteractor); GetAllMailboxInteractor getAllMailboxInteractor,
RefreshAllMailboxInteractor refreshAllMailboxInteractor
) : super(
treeBuilder,
verifyNameInteractor,
getAllMailboxInteractor: getAllMailboxInteractor,
refreshAllMailboxInteractor: refreshAllMailboxInteractor
);
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
try { try {
_getAllMailboxInteractor = Get.find<GetAllMailboxInteractor>();
_refreshAllMailboxInteractor = Get.find<RefreshAllMailboxInteractor>();
_subscribeMailboxInteractor = Get.find<SubscribeMailboxInteractor>(); _subscribeMailboxInteractor = Get.find<SubscribeMailboxInteractor>();
_subscribeMultipleMailboxInteractor = Get.find<SubscribeMultipleMailboxInteractor>(); _subscribeMultipleMailboxInteractor = Get.find<SubscribeMultipleMailboxInteractor>();
} catch (e) { } catch (e) {
@@ -87,7 +90,6 @@ class MailboxVisibilityController extends BaseMailboxController {
_handleUnsubscribeMultipleMailboxHasSomeSuccess(success); _handleUnsubscribeMultipleMailboxHasSomeSuccess(success);
} }
}); });
} }
@override @override
@@ -95,31 +97,16 @@ class MailboxVisibilityController extends BaseMailboxController {
final _session = _accountDashBoardController.sessionCurrent.value; final _session = _accountDashBoardController.sessionCurrent.value;
final _accountId = _accountDashBoardController.accountId.value; final _accountId = _accountDashBoardController.accountId.value;
if(_session != null && _accountId != null) { if(_session != null && _accountId != null) {
getAllMailboxAction(_session, _accountId); getAllMailbox(_session, _accountId);
} }
super.onReady(); super.onReady();
} }
void getAllMailboxAction(Session session, AccountId accountId) async {
if(_getAllMailboxInteractor != null){
consumeState(_getAllMailboxInteractor!.execute(session, accountId));
}
}
void refreshMailboxChanges({jmap.State? currentMailboxState}) {
log('MailboxVisibilityController::refreshMailboxChanges(): currentMailboxState: $currentMailboxState');
final newMailboxState = currentMailboxState ?? _currentMailboxState;
log('MailboxVisibilityController::refreshMailboxChanges(): newMailboxState: $newMailboxState');
final session = _accountDashBoardController.sessionCurrent.value;
final accountId = _accountDashBoardController.accountId.value;
if (accountId != null && session != null && newMailboxState != null) {
consumeState(_refreshAllMailboxInteractor!.execute(session, accountId, newMailboxState));
}
}
void _buildMailboxTreeHasSubscribed(List<PresentationMailbox> mailboxList) async { void _buildMailboxTreeHasSubscribed(List<PresentationMailbox> mailboxList) async {
dispatchState(Right(LoadingBuildTreeMailboxVisibility()));
final _mailboxList = mailboxList; final _mailboxList = mailboxList;
await buildTree(_mailboxList); await buildTree(_mailboxList);
dispatchState(Right(BuildTreeMailboxVisibilitySuccess()));
} }
void _refreshMailboxTreeHasSubscribed(List<PresentationMailbox> mailboxList) async { void _refreshMailboxTreeHasSubscribed(List<PresentationMailbox> mailboxList) async {
@@ -187,7 +174,7 @@ class MailboxVisibilityController extends BaseMailboxController {
_showToastSubscribeMailboxSuccess(subscribeMailboxSuccess.mailboxId); _showToastSubscribeMailboxSuccess(subscribeMailboxSuccess.mailboxId);
} }
refreshMailboxChanges(currentMailboxState: subscribeMailboxSuccess.currentMailboxState); _refreshMailboxChanges(subscribeMailboxSuccess.currentEmailState);
} }
void _handleUnsubscribeMultipleMailboxHasSomeSuccess(SubscribeMultipleMailboxHasSomeSuccess subscribeMailboxSuccess) { void _handleUnsubscribeMultipleMailboxHasSomeSuccess(SubscribeMultipleMailboxHasSomeSuccess subscribeMailboxSuccess) {
@@ -198,7 +185,7 @@ class MailboxVisibilityController extends BaseMailboxController {
); );
} }
refreshMailboxChanges(currentMailboxState: subscribeMailboxSuccess.currentMailboxState); _refreshMailboxChanges(subscribeMailboxSuccess.currentEmailState);
} }
void _handleUnsubscribeMultipleMailboxAllSuccess(SubscribeMultipleMailboxAllSuccess subscribeMailboxSuccess) { void _handleUnsubscribeMultipleMailboxAllSuccess(SubscribeMultipleMailboxAllSuccess subscribeMailboxSuccess) {
@@ -209,7 +196,16 @@ class MailboxVisibilityController extends BaseMailboxController {
); );
} }
refreshMailboxChanges(currentMailboxState: subscribeMailboxSuccess.currentMailboxState); _refreshMailboxChanges(subscribeMailboxSuccess.currentEmailState);
}
void _refreshMailboxChanges(jmap.State? currentEmailState) {
final _session = _accountDashBoardController.sessionCurrent.value;
final _accountId = _accountDashBoardController.accountId.value;
final currentMailboxState = currentEmailState ?? _currentMailboxState;
if (_session != null && _accountId != null && currentMailboxState != null) {
refreshMailboxChanges(_session, _accountId, currentMailboxState);
}
} }
void _showToastSubscribeMailboxSuccess( void _showToastSubscribeMailboxSuccess(
@@ -1,3 +1,4 @@
import 'package:core/core.dart';
import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart'; import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
@@ -13,6 +14,7 @@ import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/mailbox_visibility_controller.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/state/mailbox_visibility_state.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/widgets/mailbox_visibility_folder_tile_builder.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/widgets/mailbox_visibility_folder_tile_builder.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/widgets/mailbox_visibility_header_widget.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/mailbox_visibility/widgets/mailbox_visibility_header_widget.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/menu/settings_utils.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/menu/settings_utils.dart';
@@ -51,12 +53,12 @@ class MailboxVisibilityView extends GetWidget<MailboxVisibilityController> with
children: [ children: [
if (_responsiveUtils.isWebDesktop(context))...[ if (_responsiveUtils.isWebDesktop(context))...[
const MailboxVisibilityHeaderWidget(), const MailboxVisibilityHeaderWidget(),
_buildLoadingView(),
const Padding( const Padding(
padding: EdgeInsets.symmetric(vertical: 16), padding: EdgeInsets.symmetric(vertical: 16),
child: Divider(color: AppColor.colorDividerMailbox, height: 0.5, thickness: 0.2), child: Divider(color: AppColor.colorDividerMailbox, height: 0.5, thickness: 0.2),
), ),
], ],
_buildLoadingView(),
Expanded(child: _buildListMailbox(context)), Expanded(child: _buildListMailbox(context)),
] ]
), ),
@@ -69,19 +71,34 @@ class MailboxVisibilityView extends GetWidget<MailboxVisibilityController> with
Widget _buildLoadingView() { Widget _buildLoadingView() {
return Obx(() => controller.viewState.value.fold( return Obx(() => controller.viewState.value.fold(
(failure) => const SizedBox.shrink(), (failure) => const SizedBox.shrink(),
(success) => success is LoadingState (success) {
? const Center( if (success is LoadingState) {
child: Padding( return const Center(
padding: EdgeInsets.only(top: 16), child: Padding(
child: SizedBox( padding: EdgeInsets.only(top: 16),
height: 24, child: SizedBox(
width: 24, height: 24,
child: CupertinoActivityIndicator( width: 24,
color: AppColor.colorTextButton, child: CupertinoActivityIndicator(
), color: AppColor.colorTextButton,
)), ),
) )),
: const SizedBox.shrink())); );
} else if (success is LoadingBuildTreeMailboxVisibility) {
return const Center(
child: Padding(
padding: EdgeInsets.only(top: 16),
child: SizedBox(
height: 24,
width: 24,
child: CupertinoActivityIndicator(
color: AppColor.colorTextButton,
),
)),
);
}
return const SizedBox.shrink();
}));
} }
Widget _buildListMailbox(BuildContext context) { Widget _buildListMailbox(BuildContext context) {
@@ -182,15 +199,15 @@ class MailboxVisibilityView extends GetWidget<MailboxVisibilityController> with
context, context,
key: const Key('children_tree_mailbox_child'), key: const Key('children_tree_mailbox_child'),
isExpanded: mailboxNode.expandMode == ExpandMode.EXPAND, isExpanded: mailboxNode.expandMode == ExpandMode.EXPAND,
parent: Obx(() => controller.defaultMailboxIsNotEmpty ? (MailBoxVisibilityFolderTileBuilder(context, _imagePaths, mailboxNode, lastNode: lastNode) parent: (MailBoxVisibilityFolderTileBuilder(context, _imagePaths, mailboxNode, lastNode: lastNode)
..addOnExpandFolderActionClick((mailboxNode) => controller.toggleMailboxFolder(mailboxNode)) ..addOnExpandFolderActionClick((mailboxNode) => controller.toggleMailboxFolder(mailboxNode))
..addOnSubscribeMailboxActionClick((mailboxNode) => controller.subscribeMailbox(mailboxNode))) ..addOnSubscribeMailboxActionClick((mailboxNode) => controller.subscribeMailbox(mailboxNode)))
.build(context) : const SizedBox.shrink()) , .build(context),
children: _buildListChildTileWidget(context, mailboxNode) children: _buildListChildTileWidget(context, mailboxNode)
).build() ).build()
: Obx(() => controller.defaultMailboxIsNotEmpty ? (MailBoxVisibilityFolderTileBuilder(context, _imagePaths, mailboxNode, lastNode: lastNode) : (MailBoxVisibilityFolderTileBuilder(context, _imagePaths, mailboxNode, lastNode: lastNode)
..addOnExpandFolderActionClick((mailboxNode) => controller.toggleMailboxFolder(mailboxNode)) ..addOnExpandFolderActionClick((mailboxNode) => controller.toggleMailboxFolder(mailboxNode))
..addOnSubscribeMailboxActionClick((mailboxNode) => controller.subscribeMailbox(mailboxNode))) ..addOnSubscribeMailboxActionClick((mailboxNode) => controller.subscribeMailbox(mailboxNode)))
.build(context) : const SizedBox.shrink())).toList() ?? <Widget>[]; .build(context)).toList() ?? <Widget>[];
} }
} }
@@ -0,0 +1,5 @@
import 'package:core/presentation/state/success.dart';
class LoadingBuildTreeMailboxVisibility extends LoadingState {}
class BuildTreeMailboxVisibilitySuccess extends UIState {}
@@ -5,11 +5,9 @@ import 'package:model/mailbox/expand_mode.dart';
import 'package:tmail_ui_user/features/mailbox/domain/extensions/presentation_mailbox_extension.dart'; import 'package:tmail_ui_user/features/mailbox/domain/extensions/presentation_mailbox_extension.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/utils/mailbox_method_action_define.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
typedef OnExpandFolderActionClick = void Function(MailboxNode);
typedef OnSubscribeMailboxActionClick = void Function(MailboxNode);
class MailBoxVisibilityFolderTileBuilder { class MailBoxVisibilityFolderTileBuilder {
final MailboxNode _mailboxNode; final MailboxNode _mailboxNode;
final BuildContext _context; final BuildContext _context;
@@ -17,8 +15,8 @@ class MailBoxVisibilityFolderTileBuilder {
final MailboxNode? lastNode; final MailboxNode? lastNode;
final MailboxActions? mailboxActions; final MailboxActions? mailboxActions;
OnSubscribeMailboxActionClick? _onSubscribeMailboxActionClick; OnClickExpandMailboxNodeAction? _onClickExpandMailboxNodeAction;
OnExpandFolderActionClick? _onExpandFolderActionClick; OnClickSubscribeMailboxAction? _onClickSubscribeMailboxAction;
bool isHoverItem = false; bool isHoverItem = false;
MailBoxVisibilityFolderTileBuilder( MailBoxVisibilityFolderTileBuilder(
@@ -29,12 +27,12 @@ class MailBoxVisibilityFolderTileBuilder {
this.mailboxActions, this.mailboxActions,
}); });
void addOnExpandFolderActionClick(OnExpandFolderActionClick onExpandFolderActionClick) { void addOnExpandFolderActionClick(OnClickExpandMailboxNodeAction onClickExpandMailboxNodeAction) {
_onExpandFolderActionClick = onExpandFolderActionClick; _onClickExpandMailboxNodeAction = onClickExpandMailboxNodeAction;
} }
void addOnSubscribeMailboxActionClick(OnSubscribeMailboxActionClick onSubscribeMailboxActionClick) { void addOnSubscribeMailboxActionClick(OnClickSubscribeMailboxAction onClickSubscribeMailboxAction) {
_onSubscribeMailboxActionClick = onSubscribeMailboxActionClick; _onClickSubscribeMailboxAction = onClickSubscribeMailboxAction;
} }
Widget build(BuildContext context) => _buildMailboxItem(context); Widget build(BuildContext context) => _buildMailboxItem(context);
@@ -124,7 +122,7 @@ class MailBoxVisibilityFolderTileBuilder {
tooltip: _mailboxNode.expandMode == ExpandMode.EXPAND tooltip: _mailboxNode.expandMode == ExpandMode.EXPAND
? AppLocalizations.of(_context).collapse ? AppLocalizations.of(_context).collapse
: AppLocalizations.of(_context).expand, : AppLocalizations.of(_context).expand,
onTap: () => _onExpandFolderActionClick?.call(_mailboxNode)), onTap: () => _onClickExpandMailboxNodeAction?.call(_mailboxNode)),
], ],
) )
else else
@@ -155,7 +153,7 @@ class MailBoxVisibilityFolderTileBuilder {
tooltip: _mailboxNode.expandMode == ExpandMode.EXPAND tooltip: _mailboxNode.expandMode == ExpandMode.EXPAND
? AppLocalizations.of(_context).collapse ? AppLocalizations.of(_context).collapse
: AppLocalizations.of(_context).expand, : AppLocalizations.of(_context).expand,
onTap: () => _onExpandFolderActionClick?.call(_mailboxNode)), onTap: () => _onClickExpandMailboxNodeAction?.call(_mailboxNode)),
], ],
) )
else else
@@ -242,7 +240,7 @@ class MailBoxVisibilityFolderTileBuilder {
Widget _buildSubscribeMailboxItem(BuildContext context, MailboxNode _mailboxNode) { Widget _buildSubscribeMailboxItem(BuildContext context, MailboxNode _mailboxNode) {
return InkWell( return InkWell(
onTap: () => _onSubscribeMailboxActionClick?.call(_mailboxNode), onTap: () => _onClickSubscribeMailboxAction?.call(_mailboxNode),
child: Text( child: Text(
_mailboxNode.item.isSubscribedMailbox _mailboxNode.item.isSubscribedMailbox
? AppLocalizations.of(context).hide ? AppLocalizations.of(context).hide
@@ -32,8 +32,6 @@ class SearchMailboxBindings extends BaseBindings {
@override @override
void bindingsController() { void bindingsController() {
Get.lazyPut(() => SearchMailboxController( Get.lazyPut(() => SearchMailboxController(
Get.find<GetAllMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>(),
Get.find<SearchMailboxInteractor>(), Get.find<SearchMailboxInteractor>(),
Get.find<RenameMailboxInteractor>(), Get.find<RenameMailboxInteractor>(),
Get.find<MoveMailboxInteractor>(), Get.find<MoveMailboxInteractor>(),
@@ -41,7 +39,9 @@ class SearchMailboxBindings extends BaseBindings {
Get.find<SubscribeMailboxInteractor>(), Get.find<SubscribeMailboxInteractor>(),
Get.find<SubscribeMultipleMailboxInteractor>(), Get.find<SubscribeMultipleMailboxInteractor>(),
Get.find<TreeBuilder>(), Get.find<TreeBuilder>(),
Get.find<VerifyNameInteractor>() Get.find<VerifyNameInteractor>(),
Get.find<GetAllMailboxInteractor>(),
Get.find<RefreshAllMailboxInteractor>(),
)); ));
} }
@@ -59,8 +59,6 @@ import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
class SearchMailboxController extends BaseMailboxController with MailboxActionHandlerMixin { class SearchMailboxController extends BaseMailboxController with MailboxActionHandlerMixin {
final GetAllMailboxInteractor _getAllMailboxInteractor;
final RefreshAllMailboxInteractor _refreshAllMailboxInteractor;
final SearchMailboxInteractor _searchMailboxInteractor; final SearchMailboxInteractor _searchMailboxInteractor;
final RenameMailboxInteractor _renameMailboxInteractor; final RenameMailboxInteractor _renameMailboxInteractor;
final MoveMailboxInteractor _moveMailboxInteractor; final MoveMailboxInteractor _moveMailboxInteractor;
@@ -83,8 +81,6 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
PresentationEmail? get selectedEmail => dashboardController.selectedEmail.value; PresentationEmail? get selectedEmail => dashboardController.selectedEmail.value;
SearchMailboxController( SearchMailboxController(
this._getAllMailboxInteractor,
this._refreshAllMailboxInteractor,
this._searchMailboxInteractor, this._searchMailboxInteractor,
this._renameMailboxInteractor, this._renameMailboxInteractor,
this._moveMailboxInteractor, this._moveMailboxInteractor,
@@ -92,8 +88,15 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
this._subscribeMailboxInteractor, this._subscribeMailboxInteractor,
this._subscribeMultipleMailboxInteractor, this._subscribeMultipleMailboxInteractor,
TreeBuilder treeBuilder, TreeBuilder treeBuilder,
VerifyNameInteractor verifyNameInteractor VerifyNameInteractor verifyNameInteractor,
) : super(treeBuilder, verifyNameInteractor); GetAllMailboxInteractor getAllMailboxInteractor,
RefreshAllMailboxInteractor refreshAllMailboxInteractor
) : super(
treeBuilder,
verifyNameInteractor,
getAllMailboxInteractor: getAllMailboxInteractor,
refreshAllMailboxInteractor: refreshAllMailboxInteractor
);
@override @override
void onInit() { void onInit() {
@@ -132,11 +135,11 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
if (success is SearchMailboxSuccess) { if (success is SearchMailboxSuccess) {
_handleSearchMailboxSuccess(success); _handleSearchMailboxSuccess(success);
} else if (success is MarkAsMailboxReadAllSuccess) { } else if (success is MarkAsMailboxReadAllSuccess) {
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} else if (success is MarkAsMailboxReadHasSomeEmailFailure) { } else if (success is MarkAsMailboxReadHasSomeEmailFailure) {
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} else if (success is RenameMailboxSuccess) { } else if (success is RenameMailboxSuccess) {
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} else if (success is MoveMailboxSuccess) { } else if (success is MoveMailboxSuccess) {
_moveMailboxSuccess(success); _moveMailboxSuccess(success);
} else if (success is DeleteMultipleMailboxAllSuccess) { } else if (success is DeleteMultipleMailboxAllSuccess) {
@@ -169,17 +172,17 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
final session = dashboardController.sessionCurrent; final session = dashboardController.sessionCurrent;
final accountId = dashboardController.accountId.value; final accountId = dashboardController.accountId.value;
if (session != null && accountId != null) { if (session != null && accountId != null) {
consumeState(_getAllMailboxInteractor.execute(session, accountId)); getAllMailbox(session, accountId);
} }
} }
void refreshMailboxChanges({jmap.State? mailboxState}) { void _refreshMailboxChanges({jmap.State? mailboxState}) {
dashboardController.dispatchMailboxUIAction(RefreshChangeMailboxAction(null)); dashboardController.dispatchMailboxUIAction(RefreshChangeMailboxAction(null));
final newMailboxState = mailboxState ?? currentMailboxState; final newMailboxState = mailboxState ?? currentMailboxState;
final accountId = dashboardController.accountId.value; final accountId = dashboardController.accountId.value;
final session = dashboardController.sessionCurrent; final session = dashboardController.sessionCurrent;
if (session != null && accountId != null && newMailboxState != null) { if (session != null && accountId != null && newMailboxState != null) {
consumeState(_refreshAllMailboxInteractor.execute(session, accountId, newMailboxState)); refreshMailboxChanges(session, accountId, newMailboxState);
} }
} }
@@ -355,7 +358,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
); );
} }
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} }
void _undoMovingMailbox(MoveMailboxRequest newMoveRequest) { void _undoMovingMailbox(MoveMailboxRequest newMoveRequest) {
@@ -405,7 +408,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
dashboardController.dispatchMailboxUIAction(SelectMailboxDefaultAction()); dashboardController.dispatchMailboxUIAction(SelectMailboxDefaultAction());
} }
refreshMailboxChanges(mailboxState: currentMailboxState); _refreshMailboxChanges(mailboxState: currentMailboxState);
} }
void _deleteMailboxFailure(DeleteMultipleMailboxFailure failure) { void _deleteMailboxFailure(DeleteMultipleMailboxFailure failure) {
@@ -455,7 +458,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
} }
} }
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} }
void _handleSubscribeMultipleMailboxAllSuccess(SubscribeMultipleMailboxAllSuccess success) { void _handleSubscribeMultipleMailboxAllSuccess(SubscribeMultipleMailboxAllSuccess success) {
@@ -473,7 +476,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
} }
} }
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} }
void _handleSubscribeMultipleMailboxHasSomeSuccess(SubscribeMultipleMailboxHasSomeSuccess success) { void _handleSubscribeMultipleMailboxHasSomeSuccess(SubscribeMultipleMailboxHasSomeSuccess success) {
@@ -491,7 +494,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
} }
} }
refreshMailboxChanges(mailboxState: success.currentMailboxState); _refreshMailboxChanges(mailboxState: success.currentMailboxState);
} }
void _showToastSubscribeMailboxSuccess( void _showToastSubscribeMailboxSuccess(