Skip to content

Commit

Permalink
TF-2316 Find unsubscribed children and add to mapDescendent
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui committed Jan 26, 2024
1 parent a91ffa4 commit 9177f27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 20 additions & 3 deletions lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -758,6 +761,20 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
popBack();
}

List<MailboxId> _findUnsubScribedChildMailboxes(MailboxId mailboxId) {
List<MailboxId> listUnsubscribedChildMailboxes = <MailboxId>[];
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<MailboxId> listMailboxIdDeleted,
jmap.State? currentMailboxState
Expand Down
8 changes: 7 additions & 1 deletion lib/features/mailbox/presentation/utils/mailbox_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MailboxUtils {
List<PresentationMailbox> selectedMailboxList,
MailboxTree defaultMailboxTree,
MailboxTree folderMailboxTree,
{List<MailboxId>? unSubscribedChildrenMailboxIds}
) {
Map<MailboxId, List<MailboxId>> mapDescendantIds = {};
List<MailboxId> allMailboxIds = [];
Expand All @@ -27,7 +28,12 @@ class MailboxUtils {
?? folderMailboxTree.findNode((node) => node.item.id == currentMailboxId);

if (matchedNode != null) {
final descendantIds = matchedNode.descendantsAsList().mailboxIds;
List<MailboxId> descendantIds;
if (unSubscribedChildrenMailboxIds != null) {
descendantIds = matchedNode.descendantsAsList().mailboxIds + unSubscribedChildrenMailboxIds;
} else {
descendantIds = matchedNode.descendantsAsList().mailboxIds;
}
final descendantIdsReversed = descendantIds.reversed.toList();

mapDescendantIds[currentMailboxId] = descendantIdsReversed;
Expand Down

0 comments on commit 9177f27

Please sign in to comment.