TF-4141 Auto refresh count emails in Action required folder when email changed
This commit is contained in:
+10
-7
@@ -33,7 +33,7 @@ extension HandleActionRequiredTabExtension on BaseMailboxController {
|
||||
void _addActionRequiredFolder(int count) {
|
||||
final folder = _buildActionRequiredFolder(count);
|
||||
|
||||
_addToDefaultMailboxTree(folder);
|
||||
_addToDefaultMailboxTree(folder, count);
|
||||
_addToAllMailboxes(folder);
|
||||
}
|
||||
|
||||
@@ -43,20 +43,23 @@ extension HandleActionRequiredTabExtension on BaseMailboxController {
|
||||
return base.copyWith(
|
||||
displayName:
|
||||
currentContext != null ? base.getDisplayName(currentContext!) : null,
|
||||
totalEmails: TotalEmails(UnsignedInt(count)),
|
||||
unreadEmails: UnreadEmails(UnsignedInt(count)),
|
||||
);
|
||||
}
|
||||
|
||||
void _addToDefaultMailboxTree(PresentationMailbox folder) {
|
||||
void _addToDefaultMailboxTree(PresentationMailbox folder, int count) {
|
||||
final root = defaultMailboxTree.value.root;
|
||||
final children = List<MailboxNode>.from(root.childrenItems ?? []);
|
||||
|
||||
children.insertAfterStarredOrInbox(MailboxNode(folder));
|
||||
final result = children.insertAfterStarredOrInbox(MailboxNode(folder));
|
||||
|
||||
defaultMailboxTree.value = MailboxTree(
|
||||
root.copyWith(children: children),
|
||||
);
|
||||
if (result) {
|
||||
defaultMailboxTree.value = MailboxTree(
|
||||
root.copyWith(children: children),
|
||||
);
|
||||
} else {
|
||||
defaultMailboxTree.value.updateMailboxUnreadCountById(folder.id, count);
|
||||
}
|
||||
}
|
||||
|
||||
void _addToAllMailboxes(PresentationMailbox folder) {
|
||||
|
||||
@@ -15,8 +15,8 @@ extension ListMailboxNodeExtension on List<MailboxNode> {
|
||||
|
||||
/// Insert [newNode] after Starred if present,
|
||||
/// otherwise after Inbox, otherwise at the beginning.
|
||||
void insertAfterStarredOrInbox(MailboxNode newNode) {
|
||||
insertAfterByPriority(
|
||||
bool insertAfterStarredOrInbox(MailboxNode newNode) {
|
||||
return insertAfterByPriority(
|
||||
newNode,
|
||||
[
|
||||
_isStarred,
|
||||
@@ -27,21 +27,22 @@ extension ListMailboxNodeExtension on List<MailboxNode> {
|
||||
|
||||
/// Insert [newNode] after the first mailbox matching [priorities].
|
||||
/// If none match, inserts at the beginning.
|
||||
void insertAfterByPriority(
|
||||
bool insertAfterByPriority(
|
||||
MailboxNode newNode,
|
||||
List<bool Function(MailboxNode)> priorities,
|
||||
) {
|
||||
if (_containsMailbox(newNode)) return;
|
||||
if (_containsMailbox(newNode)) return false;
|
||||
|
||||
for (final predicate in priorities) {
|
||||
final index = indexWhere(predicate);
|
||||
if (index != -1) {
|
||||
insert(index + 1, newNode);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
insert(0, newNode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _isInbox(MailboxNode node) {
|
||||
|
||||
@@ -611,6 +611,7 @@ class MailboxController extends BaseMailboxController
|
||||
syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
addFavoriteFolderToMailboxList();
|
||||
setUpActionRequiredFolder(mailboxDashBoardController);
|
||||
_setMapMailbox();
|
||||
_setOutboxMailbox();
|
||||
_selectSelectedMailboxDefault();
|
||||
|
||||
@@ -16,4 +16,13 @@ extension HandleAiActionExtension on MailboxDashBoardController {
|
||||
currentAccountId,
|
||||
);
|
||||
}
|
||||
|
||||
void autoRefreshCountEmailsInActionRequiredFolder() {
|
||||
if (isAiCapabilitySupported) {
|
||||
actionRequiredFolderController.getCountEmails(
|
||||
session: sessionCurrent,
|
||||
accountId: accountId.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.d
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/mark_as_mailbox_read_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/action/dashboard_action.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/search_controller.dart' as search;
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/handle_ai_action_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/move_emails_to_mailbox_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/open_and_close_composer_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart';
|
||||
@@ -788,6 +789,7 @@ class ThreadController extends BaseController with EmailActionController {
|
||||
} else {
|
||||
await _refreshChangeListEmail();
|
||||
}
|
||||
mailboxDashBoardController.autoRefreshCountEmailsInActionRequiredFolder();
|
||||
} catch (e, stackTrace) {
|
||||
logWarning('ThreadController::_handleWebSocketMessage:Error processing state: $e');
|
||||
onError(e, stackTrace);
|
||||
|
||||
Reference in New Issue
Block a user