mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-05 16:08:46 +00:00
652 lines
25 KiB
Dart
652 lines
25 KiB
Dart
import 'package:core/presentation/utils/responsive_utils.dart';
|
|
import 'package:core/presentation/views/bottom_popup/confirmation_dialog_action_sheet_builder.dart';
|
|
import 'package:core/presentation/views/modal_sheets/edit_text_modal_sheet_builder.dart';
|
|
import 'package:core/utils/app_logger.dart';
|
|
import 'package:dartz/dartz.dart';
|
|
import 'package:core/utils/platform_info.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
|
import 'package:jmap_dart_client/jmap/core/properties/properties.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/mail/mailbox/mailbox.dart';
|
|
import 'package:model/extensions/presentation_mailbox_extension.dart';
|
|
import 'package:model/mailbox/expand_mode.dart';
|
|
import 'package:model/mailbox/presentation_mailbox.dart';
|
|
import 'package:model/mailbox/select_mode.dart';
|
|
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_name_action.dart';
|
|
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_total_emails_count_action.dart';
|
|
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_unread_count_action.dart';
|
|
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
|
import 'package:tmail_ui_user/features/base/mixin/expand_folder_trigger_scrollable_mixin.dart';
|
|
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_manager.dart';
|
|
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
|
|
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_state.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_request.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/domain/state/move_mailbox_state.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/expand_mode_extension.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/handle_action_required_tab_extension.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/handle_favorite_tab_extension.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/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_categories.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories_expand_mode.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_collection.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/duplicate_name_validator.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/empty_name_validator.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/name_with_space_only_validator.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/special_character_validator.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/domain/state/verify_name_view_state.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_creator/presentation/extensions/validator_failure_extension.dart';
|
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
|
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
|
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
|
import 'package:tmail_ui_user/main/routes/dialog_router.dart';
|
|
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
|
|
|
typedef RenameMailboxActionCallback = void Function(PresentationMailbox mailbox, MailboxName newMailboxName);
|
|
typedef MovingMailboxActionCallback = void Function(PresentationMailbox mailboxSelected, PresentationMailbox? destinationMailbox);
|
|
typedef OnMoveFolderContentActionCallback = void Function(
|
|
PresentationMailbox currentMailbox,
|
|
PresentationMailbox destinationMailbox,
|
|
);
|
|
typedef DeleteMailboxActionCallback = void Function(PresentationMailbox mailbox);
|
|
typedef AllowSubaddressingActionCallback = void Function(MailboxId, Map<String, List<String>?>?, MailboxActions);
|
|
typedef OnUpdateMailboxCollectionCallback = MailboxCollection Function(MailboxCollection);
|
|
|
|
abstract class BaseMailboxController extends BaseController
|
|
with ExpandFolderTriggerScrollableMixin {
|
|
final TreeBuilder _treeBuilder;
|
|
final VerifyNameInteractor verifyNameInteractor;
|
|
final GetAllMailboxInteractor? getAllMailboxInteractor;
|
|
final RefreshAllMailboxInteractor? refreshAllMailboxInteractor;
|
|
jmap.State? currentMailboxState;
|
|
final mailboxCategoriesExpandMode = MailboxCategoriesExpandMode.initial().obs;
|
|
|
|
BaseMailboxController(
|
|
this._treeBuilder,
|
|
this.verifyNameInteractor,
|
|
{
|
|
this.getAllMailboxInteractor,
|
|
this.refreshAllMailboxInteractor
|
|
}
|
|
);
|
|
|
|
final personalMailboxTree = MailboxTree(MailboxNode.root()).obs;
|
|
final defaultMailboxTree = MailboxTree(MailboxNode.root()).obs;
|
|
final teamMailboxesTree = MailboxTree(MailboxNode.root()).obs;
|
|
|
|
List<PresentationMailbox> allMailboxes = <PresentationMailbox>[];
|
|
|
|
List<Rx<MailboxTree>> get mailboxTrees => [
|
|
defaultMailboxTree,
|
|
personalMailboxTree,
|
|
teamMailboxesTree,
|
|
];
|
|
|
|
MailboxCollection get currentMailboxCollection => MailboxCollection(
|
|
allMailboxes: allMailboxes,
|
|
defaultTree: defaultMailboxTree.value,
|
|
personalTree: personalMailboxTree.value,
|
|
teamMailboxTree: teamMailboxesTree.value,
|
|
);
|
|
|
|
Future<void> buildTree(
|
|
List<PresentationMailbox> allMailbox, {
|
|
MailboxId? mailboxIdSelected,
|
|
OnUpdateMailboxCollectionCallback? onUpdateMailboxCollectionCallback,
|
|
}) async {
|
|
MailboxCollection mailboxCollection =
|
|
await _treeBuilder.generateMailboxTreeInUI(
|
|
allMailboxes: allMailbox,
|
|
currentCollection: currentMailboxCollection,
|
|
mailboxIdSelected: mailboxIdSelected,
|
|
);
|
|
|
|
if (onUpdateMailboxCollectionCallback != null) {
|
|
mailboxCollection = onUpdateMailboxCollectionCallback(mailboxCollection);
|
|
}
|
|
|
|
updateMailboxTree(mailboxCollection: mailboxCollection);
|
|
}
|
|
|
|
Future<void> refreshTree(
|
|
List<PresentationMailbox> allMailbox, {
|
|
OnUpdateMailboxCollectionCallback? onUpdateMailboxCollectionCallback,
|
|
}) async {
|
|
MailboxCollection mailboxCollection =
|
|
await _treeBuilder.generateMailboxTreeInUIAfterRefreshChanges(
|
|
allMailboxes: allMailbox,
|
|
currentCollection: currentMailboxCollection,
|
|
);
|
|
|
|
if (onUpdateMailboxCollectionCallback != null) {
|
|
mailboxCollection = onUpdateMailboxCollectionCallback(mailboxCollection);
|
|
}
|
|
|
|
updateMailboxTree(mailboxCollection: mailboxCollection);
|
|
}
|
|
|
|
void updateMailboxTree({
|
|
required MailboxCollection mailboxCollection,
|
|
bool isRefreshTrigger = true,
|
|
}) {
|
|
if (isRefreshTrigger) {
|
|
defaultMailboxTree.firstRebuild = true;
|
|
personalMailboxTree.firstRebuild = true;
|
|
teamMailboxesTree.firstRebuild = true;
|
|
}
|
|
defaultMailboxTree.value = mailboxCollection.defaultTree;
|
|
personalMailboxTree.value = mailboxCollection.personalTree;
|
|
teamMailboxesTree.value = mailboxCollection.teamMailboxTree;
|
|
allMailboxes = mailboxCollection.allMailboxes;
|
|
}
|
|
|
|
void syncAllMailboxWithDisplayName(BuildContext context) {
|
|
final syncedMailbox = allMailboxes
|
|
.map((mailbox) => mailbox.withDisplayName(mailbox.getDisplayName(context)))
|
|
.toList();
|
|
allMailboxes = syncedMailbox;
|
|
}
|
|
|
|
/// Expands or collapses [selectedMailboxNode] in the tree holding it.
|
|
///
|
|
/// Returns the applied [ExpandMode], or `null` when the node belongs to no
|
|
/// tree. Scrolling the node into view is a view concern, see
|
|
/// [ToggleMailboxExpandWithScrollExtension].
|
|
ExpandMode? toggleMailboxFolder(MailboxNode selectedMailboxNode) {
|
|
final newExpandMode = selectedMailboxNode.expandMode.toggle();
|
|
var isNodeUpdated = false;
|
|
|
|
for (final mailboxTree in mailboxTrees) {
|
|
final updatedNode = mailboxTree.value.updateExpandedNode(
|
|
selectedMailboxNode,
|
|
newExpandMode,
|
|
);
|
|
if (updatedNode == null) continue;
|
|
|
|
mailboxTree.refresh();
|
|
isNodeUpdated = true;
|
|
break;
|
|
}
|
|
|
|
log('BaseMailboxController::toggleMailboxFolder(): isNodeUpdated: $isNodeUpdated');
|
|
return isNodeUpdated ? newExpandMode : null;
|
|
}
|
|
|
|
void selectMailboxNode(MailboxNode mailboxNodeSelected) {
|
|
final newSelectMode = mailboxNodeSelected.selectMode == SelectMode.INACTIVE
|
|
? SelectMode.ACTIVE
|
|
: SelectMode.INACTIVE;
|
|
|
|
for (final mailboxTree in mailboxTrees) {
|
|
final updatedNode = mailboxTree.value.updateSelectedNode(
|
|
mailboxNodeSelected,
|
|
newSelectMode,
|
|
);
|
|
if (updatedNode == null) continue;
|
|
|
|
mailboxTree.refresh();
|
|
break;
|
|
}
|
|
}
|
|
|
|
void unAllSelectedMailboxNode() {
|
|
for (final mailboxTree in mailboxTrees) {
|
|
mailboxTree.value.updateNodesUIMode(selectMode: SelectMode.INACTIVE);
|
|
mailboxTree.refresh();
|
|
}
|
|
}
|
|
|
|
MailboxNode? findMailboxNodeById(MailboxId mailboxId) {
|
|
final mailboxNode = defaultMailboxTree.value.findNode((node) => node.item.id == mailboxId);
|
|
if (mailboxNode != null) {
|
|
return mailboxNode;
|
|
}
|
|
|
|
final mailboxPersonal = personalMailboxTree.value.findNode((node) => node.item.id == mailboxId);
|
|
if (mailboxPersonal != null) {
|
|
return mailboxPersonal;
|
|
}
|
|
return teamMailboxesTree.value.findNode((node) => node.item.id == mailboxId);
|
|
}
|
|
|
|
String? findNodePathWithSeparator(MailboxId mailboxId, String pathSeparator) {
|
|
var mailboxNodePath = defaultMailboxTree.value.getNodePath(mailboxId, pathSeparator)
|
|
?? personalMailboxTree.value.getNodePath(mailboxId, pathSeparator)
|
|
?? teamMailboxesTree.value.getNodePath(mailboxId, pathSeparator);
|
|
log('BaseMailboxController::findNodePath():mailboxNodePath: $mailboxNodePath');
|
|
return mailboxNodePath;
|
|
}
|
|
|
|
String? findNodePath(MailboxId mailboxId) {
|
|
return findNodePathWithSeparator(mailboxId, '/');
|
|
}
|
|
|
|
MailboxNode? findMailboxNodeByRole(Role role) {
|
|
final mailboxNode = defaultMailboxTree.value.findNode((node) => node.item.role == role);
|
|
return mailboxNode;
|
|
}
|
|
|
|
List<PresentationMailbox> findMailboxPath(List<PresentationMailbox> mailboxes) {
|
|
return mailboxes.map((presentationMailbox) {
|
|
if (!presentationMailbox.hasParentId()) {
|
|
return presentationMailbox;
|
|
} else {
|
|
final mailboxNodePath = findNodePath(presentationMailbox.id);
|
|
if (mailboxNodePath != null) {
|
|
return presentationMailbox.toPresentationMailboxWithMailboxPath(mailboxNodePath);
|
|
} else {
|
|
return presentationMailbox;
|
|
}
|
|
}
|
|
}).toList();
|
|
}
|
|
|
|
bool get defaultMailboxIsNotEmpty =>
|
|
defaultMailboxTree.value.root.childrenItems?.isNotEmpty ?? false;
|
|
|
|
bool get personalMailboxIsNotEmpty =>
|
|
personalMailboxTree.value.root.childrenItems?.isNotEmpty ?? false;
|
|
|
|
bool get teamMailboxesIsNotEmpty {
|
|
return (teamMailboxesTree.value.root.childrenItems?.isNotEmpty ?? false)
|
|
&& !teamMailboxesTree.value.root.item.isTeamMailboxes;
|
|
}
|
|
|
|
MailboxNode get defaultRootNode => defaultMailboxTree.value.root;
|
|
|
|
MailboxNode get personalRootNode => personalMailboxTree.value.root;
|
|
|
|
MailboxNode get teamMailboxesRootNode => teamMailboxesTree.value.root;
|
|
|
|
List<String> getListMailboxNameInParentMailbox(PresentationMailbox parentMailbox) {
|
|
final parentId = parentMailbox.parentId;
|
|
final mailboxNodesAtSameLocation = parentId == null
|
|
? rootChildrenNodes
|
|
: findMailboxNodeById(parentId)?.childrenItems;
|
|
|
|
return mailboxNodesAtSameLocation?.mailboxNames ?? [];
|
|
}
|
|
|
|
List<MailboxNode> get rootChildrenNodes => [
|
|
for (final mailboxTree in mailboxTrees)
|
|
...?mailboxTree.value.root.childrenItems,
|
|
];
|
|
|
|
String? verifyMailboxNameAction(
|
|
BuildContext context,
|
|
String newName,
|
|
List<String> listMailboxName,
|
|
MailboxActions mailboxActions
|
|
) {
|
|
return verifyNameInteractor.execute(newName, [
|
|
EmptyNameValidator(),
|
|
NameWithSpaceOnlyValidator(),
|
|
DuplicateNameValidator(listMailboxName),
|
|
SpecialCharacterValidator()
|
|
]).fold((failure) {
|
|
if (failure is VerifyNameFailure) {
|
|
return failure.getMessage(context, actions: mailboxActions);
|
|
} else {
|
|
return null;
|
|
}
|
|
}, (success) => null);
|
|
}
|
|
|
|
void openDialogRenameMailboxAction(
|
|
BuildContext context,
|
|
PresentationMailbox presentationMailbox,
|
|
ResponsiveUtils responsiveUtils, {
|
|
required RenameMailboxActionCallback onRenameMailboxAction
|
|
}) {
|
|
final listMailboxName = getListMailboxNameInParentMailbox(presentationMailbox);
|
|
|
|
if (responsiveUtils.isMobile(context)) {
|
|
(EditTextModalSheetBuilder()
|
|
..key(const Key('rename_mailbox_dialog'))
|
|
..title(AppLocalizations.of(context).renameFolder)
|
|
..cancelText(AppLocalizations.of(context).cancel)
|
|
..boxConstraints(responsiveUtils.isLandscapeMobile(context)
|
|
? const BoxConstraints(maxWidth: 400)
|
|
: null)
|
|
..onConfirmAction(
|
|
AppLocalizations.of(context).rename,
|
|
(value) => onRenameMailboxAction(presentationMailbox, MailboxName(value))
|
|
)
|
|
..setErrorString((value) {
|
|
return verifyMailboxNameAction(
|
|
context,
|
|
value,
|
|
listMailboxName,
|
|
MailboxActions.rename
|
|
);
|
|
})
|
|
..setTextController(TextEditingController.fromValue(
|
|
TextEditingValue(
|
|
text: presentationMailbox.name?.name ?? '',
|
|
selection: TextSelection(
|
|
baseOffset: 0,
|
|
extentOffset: presentationMailbox.name?.name.length ?? 0
|
|
)
|
|
)))
|
|
).show(context);
|
|
} else {
|
|
MessageDialogActionManager().showInputDialogAction(
|
|
key: const Key('rename_mailbox_dialog'),
|
|
context: context,
|
|
outsideDismissible: true,
|
|
title: AppLocalizations.of(context).renameFolder,
|
|
value: presentationMailbox.name?.name ?? '',
|
|
negativeText: AppLocalizations.of(context).cancel,
|
|
positiveText: AppLocalizations.of(context).rename,
|
|
closeIcon: imagePaths.icComposerClose,
|
|
onPositiveButtonAction: (value) {
|
|
onRenameMailboxAction(presentationMailbox, MailboxName(value));
|
|
popBack();
|
|
},
|
|
onNegativeButtonAction: popBack,
|
|
onInputErrorChanged: (value) {
|
|
return verifyMailboxNameAction(
|
|
context,
|
|
value,
|
|
listMailboxName,
|
|
MailboxActions.rename,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> moveMailboxAction(
|
|
PresentationMailbox mailboxSelected,
|
|
MailboxDashBoardController dashBoardController, {
|
|
required MovingMailboxActionCallback onMovingMailboxAction
|
|
}) async {
|
|
final accountId = dashBoardController.accountId.value;
|
|
final session = dashBoardController.sessionCurrent;
|
|
if (accountId == null || session == null) {
|
|
consumeState(Stream.value(Left(MoveMailboxFailure(
|
|
accountId == null
|
|
? NotFoundAccountIdException()
|
|
: NotFoundSessionException(),
|
|
))));
|
|
return;
|
|
}
|
|
|
|
final destinationMailbox = await pickDestinationMailbox(
|
|
accountId: accountId,
|
|
session: session,
|
|
mailboxActions: MailboxActions.move,
|
|
mailboxIdSelected: mailboxSelected.id,
|
|
);
|
|
if (destinationMailbox == null) return;
|
|
|
|
onMovingMailboxAction(
|
|
mailboxSelected,
|
|
destinationMailbox == PresentationMailbox.unifiedMailbox
|
|
? null
|
|
: destinationMailbox
|
|
);
|
|
}
|
|
|
|
void openConfirmationDialogDeleteMailboxAction(
|
|
BuildContext context,
|
|
PresentationMailbox presentationMailbox, {
|
|
required DeleteMailboxActionCallback onDeleteMailboxAction
|
|
}) {
|
|
if (responsiveUtils.isLandscapeMobile(context) || responsiveUtils.isPortraitMobile(context)) {
|
|
(ConfirmationDialogActionSheetBuilder(context)
|
|
..messageText(AppLocalizations.of(context).message_confirmation_dialog_delete_folder(presentationMailbox.getDisplayName(context)))
|
|
..onCancelAction(AppLocalizations.of(context).cancel, () => popBack())
|
|
..onConfirmAction(AppLocalizations.of(context).delete, () => onDeleteMailboxAction(presentationMailbox))
|
|
).show();
|
|
} else {
|
|
MessageDialogActionManager().showConfirmDialogAction(
|
|
context,
|
|
AppLocalizations.of(context).message_confirmation_dialog_delete_folder(presentationMailbox.getDisplayName(context)),
|
|
AppLocalizations.of(context).delete,
|
|
key: const Key('confirm_dialog_delete_mailbox'),
|
|
title: AppLocalizations.of(context).deleteFolders,
|
|
cancelTitle: AppLocalizations.of(context).cancel,
|
|
onConfirmAction: () => onDeleteMailboxAction(presentationMailbox),
|
|
onCloseButtonAction: popBack,
|
|
);
|
|
}
|
|
}
|
|
|
|
List<MailboxNode> getAncestorOfMailboxNode(MailboxNode mailboxNode) {
|
|
final listAncestor = defaultMailboxTree.value.getAncestorList(mailboxNode)
|
|
?? personalMailboxTree.value.getAncestorList(mailboxNode)
|
|
?? teamMailboxesTree.value.getAncestorList(mailboxNode);
|
|
return listAncestor ?? [];
|
|
}
|
|
|
|
SubscribeRequest? generateSubscribeRequest(
|
|
MailboxId mailboxId,
|
|
MailboxSubscribeState subscribeState,
|
|
MailboxSubscribeAction subscribeAction
|
|
) {
|
|
switch(subscribeState) {
|
|
case MailboxSubscribeState.enabled:
|
|
return _generateSubscribeRequestWhenSubscribeEnabled(mailboxId, subscribeAction);
|
|
case MailboxSubscribeState.disabled:
|
|
return _generateSubscribeRequestWhenSubscribeDisabled(mailboxId, subscribeAction);
|
|
}
|
|
}
|
|
|
|
SubscribeRequest? _generateSubscribeRequestWhenSubscribeDisabled(
|
|
MailboxId mailboxId,
|
|
MailboxSubscribeAction subscribeAction
|
|
) {
|
|
final mailboxNode = findMailboxNodeById(mailboxId);
|
|
|
|
if (mailboxNode == null) return null;
|
|
|
|
if (mailboxNode.hasChildren()) {
|
|
final listDescendantMailboxIds = mailboxNode.descendantsAsList().mailboxIds;
|
|
log("BaseMailboxController::_generateSubscribeRequestWhenSubscribeDisabled:listDescendantMailboxIds $listDescendantMailboxIds");
|
|
return SubscribeMultipleMailboxRequest(
|
|
mailboxId,
|
|
listDescendantMailboxIds,
|
|
MailboxSubscribeState.disabled,
|
|
subscribeAction
|
|
);
|
|
} else {
|
|
return SubscribeMailboxRequest(
|
|
mailboxId,
|
|
MailboxSubscribeState.disabled,
|
|
subscribeAction
|
|
);
|
|
}
|
|
}
|
|
|
|
SubscribeRequest? _generateSubscribeRequestWhenSubscribeEnabled(
|
|
MailboxId mailboxId,
|
|
MailboxSubscribeAction subscribeAction
|
|
) {
|
|
final mailboxNode = findMailboxNodeById(mailboxId);
|
|
|
|
if (mailboxNode == null) return null;
|
|
|
|
if (mailboxNode.hasParents()) {
|
|
final listAncestorMailboxIds = getAncestorOfMailboxNode(mailboxNode).mailboxIds;
|
|
listAncestorMailboxIds.add(mailboxId);
|
|
log("BaseMailboxController::_generateSubscribeRequestWhenSubscribeEnabled:listAncestorMailboxIds $listAncestorMailboxIds");
|
|
if (listAncestorMailboxIds.isNotEmpty) {
|
|
return SubscribeMultipleMailboxRequest(
|
|
mailboxId,
|
|
listAncestorMailboxIds,
|
|
MailboxSubscribeState.enabled,
|
|
subscribeAction
|
|
);
|
|
} else {
|
|
return SubscribeMailboxRequest(
|
|
mailboxId,
|
|
MailboxSubscribeState.enabled,
|
|
subscribeAction
|
|
);
|
|
}
|
|
} else {
|
|
return SubscribeMailboxRequest(
|
|
mailboxId,
|
|
MailboxSubscribeState.enabled,
|
|
subscribeAction
|
|
);
|
|
}
|
|
}
|
|
|
|
void getAllMailbox(Session session, AccountId accountId) async {
|
|
if (getAllMailboxInteractor != null) {
|
|
consumeState(getAllMailboxInteractor!.execute(session, accountId));
|
|
}
|
|
}
|
|
|
|
void refreshMailboxChanges(
|
|
Session session,
|
|
AccountId accountId,
|
|
jmap.State currentMailboxState,
|
|
{Properties? properties}
|
|
) {
|
|
if (refreshAllMailboxInteractor != null) {
|
|
log('BaseMailboxController::refreshMailboxChanges(): currentMailboxState: $currentMailboxState');
|
|
consumeState(refreshAllMailboxInteractor!.execute(
|
|
session,
|
|
accountId,
|
|
currentMailboxState,
|
|
properties: properties
|
|
));
|
|
}
|
|
}
|
|
|
|
MailboxNode? findNodeByNameOnFirstLevel(String name) {
|
|
MailboxNode? mailboxNode = defaultMailboxTree.value.findNodeOnFirstLevel((node) => node.item.name?.name.toLowerCase() == name);
|
|
if (mailboxNode != null) {
|
|
return mailboxNode;
|
|
}
|
|
mailboxNode = personalMailboxTree.value.findNodeOnFirstLevel((node) => node.item.name?.name.toLowerCase() == name);
|
|
return mailboxNode;
|
|
}
|
|
|
|
void updateMailboxNameById(MailboxId mailboxId, MailboxName mailboxName) {
|
|
UpdateMailboxNameAction(
|
|
mailboxTrees: mailboxTrees,
|
|
mailboxId: mailboxId,
|
|
mailboxName: mailboxName,
|
|
).execute();
|
|
}
|
|
|
|
void updateUnreadCountOfMailboxById(
|
|
MailboxId mailboxId, {
|
|
required int unreadChanges,
|
|
}) {
|
|
UpdateMailboxUnreadCountAction(
|
|
mailboxTrees: mailboxTrees,
|
|
mailboxId: mailboxId,
|
|
unreadChanges: unreadChanges,
|
|
).execute();
|
|
}
|
|
|
|
void clearUnreadCount(MailboxId mailboxId) {
|
|
for (var mailboxTree in mailboxTrees) {
|
|
final selectedNode = mailboxTree.value.findNode((node) => node.item.id == mailboxId);
|
|
if (selectedNode == null) continue;
|
|
final currentUnreadCount = selectedNode.item.unreadEmails?.value.value.toInt();
|
|
mailboxTree.value.updateMailboxUnreadCountById(
|
|
mailboxId,
|
|
-(currentUnreadCount ?? 0));
|
|
mailboxTree.refresh();
|
|
break;
|
|
}
|
|
}
|
|
|
|
void updateMailboxTotalEmailsCountById(MailboxId mailboxId, int totalEmails) {
|
|
UpdateMailboxTotalEmailsCountAction(
|
|
mailboxTrees: mailboxTrees,
|
|
mailboxId: mailboxId,
|
|
totalEmailsCountChanged: totalEmails,
|
|
).execute();
|
|
}
|
|
|
|
/// Expands or collapses [category] and returns the applied [ExpandMode].
|
|
///
|
|
/// Scrolling the category into view is a view concern, see
|
|
/// [ToggleMailboxExpandWithScrollExtension].
|
|
ExpandMode toggleMailboxCategories(MailboxCategories category) {
|
|
final categoriesExpandMode = mailboxCategoriesExpandMode.value;
|
|
final newExpandMode = category.getExpandMode(categoriesExpandMode).toggle();
|
|
|
|
mailboxCategoriesExpandMode.value = category.withExpandMode(
|
|
categoriesExpandMode,
|
|
newExpandMode,
|
|
);
|
|
|
|
return newExpandMode;
|
|
}
|
|
|
|
Future<void> moveFolderContentAction({
|
|
required AccountId accountId,
|
|
required Session session,
|
|
required PresentationMailbox mailboxSelected,
|
|
required OnMoveFolderContentActionCallback onMoveFolderContentAction,
|
|
}) async {
|
|
final destinationMailbox = await pickDestinationMailbox(
|
|
accountId: accountId,
|
|
session: session,
|
|
mailboxActions: MailboxActions.moveFolderContent,
|
|
mailboxIdSelected: mailboxSelected.id,
|
|
);
|
|
if (destinationMailbox == null) return;
|
|
|
|
log('$runtimeType::moveFolderContentAction: DestinationMailbox is selected');
|
|
onMoveFolderContentAction(mailboxSelected, destinationMailbox);
|
|
}
|
|
|
|
Future<PresentationMailbox?> pickDestinationMailbox({
|
|
required AccountId accountId,
|
|
required Session session,
|
|
required MailboxActions mailboxActions,
|
|
required MailboxId mailboxIdSelected,
|
|
}) async {
|
|
final arguments = DestinationPickerArguments(
|
|
accountId,
|
|
mailboxActions,
|
|
session,
|
|
mailboxIdSelected: mailboxIdSelected,
|
|
);
|
|
|
|
final destinationMailbox = PlatformInfo.isWeb
|
|
? await DialogRouter().pushGeneralDialog(
|
|
routeName: AppRoutes.destinationPicker,
|
|
arguments: arguments,
|
|
)
|
|
: await push(AppRoutes.destinationPicker, arguments: arguments);
|
|
|
|
return destinationMailbox is PresentationMailbox ? destinationMailbox : null;
|
|
}
|
|
|
|
bool get isAINeedsActionEnabled => false;
|
|
|
|
MailboxCollection updateMailboxCollection(MailboxCollection mailboxCollection) {
|
|
MailboxCollection updated = addFavoriteFolderToMailboxList(
|
|
mailboxCollection: mailboxCollection,
|
|
);
|
|
if (isAINeedsActionEnabled) {
|
|
updated = addActionRequiredFolder(mailboxCollection: updated);
|
|
}
|
|
return updated;
|
|
}
|
|
}
|