diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index ba0af56ec9..f7c1d79241 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -736,12 +736,15 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM void _deleteMailboxAction(PresentationMailbox presentationMailbox) { final accountId = mailboxDashBoardController.accountId.value; final session = mailboxDashBoardController.sessionCurrent; + final unSubscribedChildrenMailboxes = _findUnsubScribedChildMailboxes(presentationMailbox.id); if (session != null && accountId != null) { final tupleMap = MailboxUtils.generateMapDescendantIdsAndMailboxIdList( - [presentationMailbox], - defaultMailboxTree.value, - personalMailboxTree.value); + [presentationMailbox], + defaultMailboxTree.value, + personalMailboxTree.value, + unSubscribedChildrenMailboxIds: unSubscribedChildrenMailboxes + ); final mapDescendantIds = tupleMap.value1; final listMailboxId = tupleMap.value2; @@ -758,6 +761,20 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM popBack(); } + List _findUnsubScribedChildMailboxes(MailboxId mailboxId) { + List listUnsubscribedChildMailboxes = []; + for (var mailbox in listUnsubscribedMailboxes) { + if (mailbox.parentId == mailboxId) { + listUnsubscribedChildMailboxes.add(mailbox.id); + final lowerChildren = _findUnsubScribedChildMailboxes(mailbox.id); + if (lowerChildren.isNotEmpty) { + listUnsubscribedChildMailboxes.addAll(lowerChildren); + } + } + } + return listUnsubscribedChildMailboxes.toList(); + } + void _deleteMultipleMailboxSuccess( List listMailboxIdDeleted, jmap.State? currentMailboxState diff --git a/lib/features/mailbox/presentation/utils/mailbox_utils.dart b/lib/features/mailbox/presentation/utils/mailbox_utils.dart index dd12ca7d09..4c2cec930c 100644 --- a/lib/features/mailbox/presentation/utils/mailbox_utils.dart +++ b/lib/features/mailbox/presentation/utils/mailbox_utils.dart @@ -13,6 +13,7 @@ class MailboxUtils { List selectedMailboxList, MailboxTree defaultMailboxTree, MailboxTree folderMailboxTree, + {List? unSubscribedChildrenMailboxIds} ) { Map> mapDescendantIds = {}; List allMailboxIds = []; @@ -27,7 +28,12 @@ class MailboxUtils { ?? folderMailboxTree.findNode((node) => node.item.id == currentMailboxId); if (matchedNode != null) { - final descendantIds = matchedNode.descendantsAsList().mailboxIds; + List descendantIds; + if (unSubscribedChildrenMailboxIds != null) { + descendantIds = matchedNode.descendantsAsList().mailboxIds + unSubscribedChildrenMailboxIds; + } else { + descendantIds = matchedNode.descendantsAsList().mailboxIds; + } final descendantIdsReversed = descendantIds.reversed.toList(); mapDescendantIds[currentMailboxId] = descendantIdsReversed;