TF-4141 Remove counter of action required folder
This commit is contained in:
+9
-58
@@ -1,4 +1,3 @@
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_mailbox_controller.dart';
|
||||
@@ -6,60 +5,33 @@ import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mail
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/presentation_mailbox_extension.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_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/handle_ai_action_extension.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
extension HandleActionRequiredTabExtension on BaseMailboxController {
|
||||
void setUpActionRequiredFolder(
|
||||
MailboxDashBoardController dashboardController,
|
||||
) {
|
||||
if (!dashboardController.isAiCapabilitySupported) return;
|
||||
|
||||
dashboardController.actionRequiredFolderController.getCountEmails(
|
||||
session: dashboardController.sessionCurrent,
|
||||
accountId: dashboardController.accountId.value,
|
||||
);
|
||||
}
|
||||
|
||||
void onActionRequiredFolderCountChanged(int count) {
|
||||
if (count > 0) {
|
||||
_addActionRequiredFolder(count);
|
||||
} else {
|
||||
_removeActionRequiredFolder();
|
||||
}
|
||||
}
|
||||
|
||||
void _addActionRequiredFolder(int count) {
|
||||
final folder = _buildActionRequiredFolder(count);
|
||||
|
||||
_addToDefaultMailboxTree(folder, count);
|
||||
void addActionRequiredFolder() {
|
||||
final folder = _buildActionRequiredFolder();
|
||||
_addToDefaultMailboxTree(folder);
|
||||
_addToAllMailboxes(folder);
|
||||
}
|
||||
|
||||
PresentationMailbox _buildActionRequiredFolder(int count) {
|
||||
PresentationMailbox _buildActionRequiredFolder() {
|
||||
final base = PresentationMailbox.actionRequiredFolder;
|
||||
|
||||
return base.copyWith(
|
||||
displayName:
|
||||
currentContext != null ? base.getDisplayName(currentContext!) : null,
|
||||
unreadEmails: UnreadEmails(UnsignedInt(count)),
|
||||
);
|
||||
}
|
||||
|
||||
void _addToDefaultMailboxTree(PresentationMailbox folder, int count) {
|
||||
void _addToDefaultMailboxTree(PresentationMailbox folder) {
|
||||
final root = defaultMailboxTree.value.root;
|
||||
final children = List<MailboxNode>.from(root.childrenItems ?? []);
|
||||
|
||||
final result = children.insertAfterStarredOrInbox(MailboxNode(folder));
|
||||
children.insertAfterStarredOrInbox(MailboxNode(folder));
|
||||
|
||||
if (result) {
|
||||
defaultMailboxTree.value = MailboxTree(
|
||||
root.copyWith(children: children),
|
||||
);
|
||||
} else {
|
||||
defaultMailboxTree.value.updateMailboxUnreadCountById(folder.id, count);
|
||||
}
|
||||
defaultMailboxTree.value = MailboxTree(
|
||||
root.copyWith(children: children),
|
||||
);
|
||||
}
|
||||
|
||||
void _addToAllMailboxes(PresentationMailbox folder) {
|
||||
@@ -67,27 +39,6 @@ extension HandleActionRequiredTabExtension on BaseMailboxController {
|
||||
allMailboxes.add(folder);
|
||||
}
|
||||
|
||||
void _removeActionRequiredFolder() {
|
||||
final folder = PresentationMailbox.actionRequiredFolder;
|
||||
|
||||
_removeFromDefaultMailboxTree(folder.id);
|
||||
_removeFromAllMailboxes(folder.id);
|
||||
}
|
||||
|
||||
void _removeFromDefaultMailboxTree(MailboxId folderId) {
|
||||
final root = defaultMailboxTree.value.root;
|
||||
final children = List<MailboxNode>.from(root.childrenItems ?? [])
|
||||
..removeWhere((node) => node.item.id == folderId);
|
||||
|
||||
defaultMailboxTree.value = MailboxTree(
|
||||
root.copyWith(children: children),
|
||||
);
|
||||
}
|
||||
|
||||
void _removeFromAllMailboxes(MailboxId folderId) {
|
||||
allMailboxes.removeWhere((mailbox) => mailbox.id == folderId);
|
||||
}
|
||||
|
||||
bool _allMailboxesContains(MailboxId id) {
|
||||
return allMailboxes.any((mailbox) => mailbox.id == id);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ extension ListMailboxNodeExtension on List<MailboxNode> {
|
||||
|
||||
/// Insert [newNode] after Starred if present,
|
||||
/// otherwise after Inbox, otherwise at the beginning.
|
||||
bool insertAfterStarredOrInbox(MailboxNode newNode) {
|
||||
return insertAfterByPriority(
|
||||
void insertAfterStarredOrInbox(MailboxNode newNode) {
|
||||
insertAfterByPriority(
|
||||
newNode,
|
||||
[
|
||||
_isStarred,
|
||||
@@ -27,22 +27,21 @@ extension ListMailboxNodeExtension on List<MailboxNode> {
|
||||
|
||||
/// Insert [newNode] after the first mailbox matching [priorities].
|
||||
/// If none match, inserts at the beginning.
|
||||
bool insertAfterByPriority(
|
||||
void insertAfterByPriority(
|
||||
MailboxNode newNode,
|
||||
List<bool Function(MailboxNode)> priorities,
|
||||
) {
|
||||
if (_containsMailbox(newNode)) return false;
|
||||
if (_containsMailbox(newNode)) return;
|
||||
|
||||
for (final predicate in priorities) {
|
||||
final index = indexWhere(predicate);
|
||||
if (index != -1) {
|
||||
insert(index + 1, newNode);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
insert(0, newNode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _isInbox(MailboxNode node) {
|
||||
|
||||
Reference in New Issue
Block a user