TF-4392 [Team Mailbox] Hide Recover deleted messages and Archive message in team mailbox
This commit is contained in:
@@ -778,6 +778,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final emailId = email.id;
|
||||||
|
if (emailId == null) {
|
||||||
|
mailboxDashBoardController.emitMoveToTrashFailure(
|
||||||
|
NotFoundEmailIdException(),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final moveActionRequest = emailActionReactor.buildMoveToTrashRequest(
|
final moveActionRequest = emailActionReactor.buildMoveToTrashRequest(
|
||||||
email,
|
email,
|
||||||
trashMailboxId: trashId,
|
trashMailboxId: trashId,
|
||||||
|
|||||||
@@ -40,4 +40,11 @@ class NotFoundTrashMailboxException extends AppBaseException {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get exceptionName => 'NotFoundTrashMailboxException';
|
String get exceptionName => 'NotFoundTrashMailboxException';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NotFoundEmailIdException extends AppBaseException {
|
||||||
|
NotFoundEmailIdException([super.message]);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get exceptionName => 'NotFoundEmailIdException';
|
||||||
|
}
|
||||||
|
|||||||
@@ -87,20 +87,20 @@ mixin MailboxWidgetMixin {
|
|||||||
return [
|
return [
|
||||||
if (PlatformInfo.isWeb && mailbox.isSubscribedMailbox)
|
if (PlatformInfo.isWeb && mailbox.isSubscribedMailbox)
|
||||||
MailboxActions.openInNewTab,
|
MailboxActions.openInNewTab,
|
||||||
if (mailbox.myRights?.mayCreateChild == true)
|
if (mailbox.myRights?.mayCreateChild != false)
|
||||||
MailboxActions.newSubfolder,
|
MailboxActions.newSubfolder,
|
||||||
if (mailbox.countUnReadEmailsAsString.isNotEmpty)
|
if (mailbox.countUnReadEmailsAsString.isNotEmpty)
|
||||||
MailboxActions.markAsRead,
|
MailboxActions.markAsRead,
|
||||||
if (mailbox.myRights?.mayRename == true)
|
if (mailbox.myRights?.mayRename != false)
|
||||||
MailboxActions.rename,
|
MailboxActions.rename,
|
||||||
if (mailbox.isTeamMailboxes)
|
if (mailbox.isTeamMailboxes)
|
||||||
if (mailbox.isSubscribedMailbox)
|
if (mailbox.isSubscribedMailbox)
|
||||||
MailboxActions.disableMailbox
|
MailboxActions.disableMailbox
|
||||||
else
|
else
|
||||||
MailboxActions.enableMailbox,
|
MailboxActions.enableMailbox,
|
||||||
if (mailbox.isTrash && mailbox.myRights?.mayRemoveItems == true)
|
if (mailbox.isTrash && mailbox.myRights?.mayRemoveItems != false)
|
||||||
MailboxActions.emptyTrash,
|
MailboxActions.emptyTrash,
|
||||||
if (mailbox.myRights?.mayDelete == true)
|
if (mailbox.myRights?.mayDelete != false)
|
||||||
MailboxActions.delete,
|
MailboxActions.delete,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -1864,7 +1864,7 @@ class MailboxDashBoardController extends ReloadableController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CapabilityIdentifier.jmapMailboxClear.isSupported(session, accountId) &&
|
if (CapabilityIdentifier.jmapMailboxClear.isSupported(session, accountId) &&
|
||||||
trashFolder.isTrashTeamMailbox != true) {
|
!trashFolder.isFirstLevelTeamSystemFolder(mapMailboxById, PresentationMailbox.trashRole)) {
|
||||||
clearMailbox(
|
clearMailbox(
|
||||||
session,
|
session,
|
||||||
accountId,
|
accountId,
|
||||||
@@ -2406,8 +2406,7 @@ class MailboxDashBoardController extends ReloadableController
|
|||||||
PresentationMailbox? mailbox
|
PresentationMailbox? mailbox
|
||||||
) {
|
) {
|
||||||
return mailbox != null &&
|
return mailbox != null &&
|
||||||
mailbox.isTrash &&
|
(mailbox.isTrash || (mailbox.isTrashTeamMailbox && mailbox.myRights?.mayRemoveItems != false)) &&
|
||||||
mailbox.myRights?.mayRemoveItems == true &&
|
|
||||||
mailbox.countTotalEmails > 0 &&
|
mailbox.countTotalEmails > 0 &&
|
||||||
!searchController.isSearchActive() &&
|
!searchController.isSearchActive() &&
|
||||||
responsiveUtils.isWebDesktop(context);
|
responsiveUtils.isWebDesktop(context);
|
||||||
@@ -2418,8 +2417,7 @@ class MailboxDashBoardController extends ReloadableController
|
|||||||
PresentationMailbox? mailbox
|
PresentationMailbox? mailbox
|
||||||
) {
|
) {
|
||||||
return mailbox != null &&
|
return mailbox != null &&
|
||||||
mailbox.isTrash &&
|
(mailbox.isTrash || (mailbox.isTrashTeamMailbox && mailbox.myRights?.mayRemoveItems != false)) &&
|
||||||
mailbox.myRights?.mayRemoveItems == true &&
|
|
||||||
mailbox.countTotalEmails > 0 &&
|
mailbox.countTotalEmails > 0 &&
|
||||||
!searchController.isSearchActive() &&
|
!searchController.isSearchActive() &&
|
||||||
!responsiveUtils.isWebDesktop(context);
|
!responsiveUtils.isWebDesktop(context);
|
||||||
|
|||||||
+82
-2
@@ -23,6 +23,17 @@ extension HandleActionTypeForEmailSelection on MailboxDashBoardController {
|
|||||||
EmailActionType actionType,
|
EmailActionType actionType,
|
||||||
{MailboxId? selectedMailboxId, String? destinationFolderPath}
|
{MailboxId? selectedMailboxId, String? destinationFolderPath}
|
||||||
) {
|
) {
|
||||||
|
final isInSearchOrVirtualFolder =
|
||||||
|
searchController.isSearchEmailRunning ||
|
||||||
|
selectedMailbox.value?.isVirtualFolder == true;
|
||||||
|
|
||||||
|
// In search / virtual-folder mode the selected mailbox does not represent
|
||||||
|
// the emails' actual home namespace, so trash must be resolved per email.
|
||||||
|
if (actionType == EmailActionType.moveToTrash && isInSearchOrVirtualFolder) {
|
||||||
|
_moveEmailsToTrashAcrossNamespaces(emails);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MailboxId? destinationMailboxId;
|
MailboxId? destinationMailboxId;
|
||||||
|
|
||||||
if (actionType == EmailActionType.moveToMailbox) {
|
if (actionType == EmailActionType.moveToMailbox) {
|
||||||
@@ -58,8 +69,7 @@ extension HandleActionTypeForEmailSelection on MailboxDashBoardController {
|
|||||||
|
|
||||||
final mapEmailIdsByMailboxId = <MailboxId, List<EmailId>>{};
|
final mapEmailIdsByMailboxId = <MailboxId, List<EmailId>>{};
|
||||||
|
|
||||||
if (searchController.isSearchEmailRunning ||
|
if (isInSearchOrVirtualFolder) {
|
||||||
selectedMailbox.value?.isVirtualFolder == true) {
|
|
||||||
for (final email in emails) {
|
for (final email in emails) {
|
||||||
final mailboxId = email.firstMailboxIdAvailable;
|
final mailboxId = email.firstMailboxIdAvailable;
|
||||||
final emailId = email.id;
|
final emailId = email.id;
|
||||||
@@ -115,4 +125,74 @@ extension HandleActionTypeForEmailSelection on MailboxDashBoardController {
|
|||||||
emailIdsWithReadStatus,
|
emailIdsWithReadStatus,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _moveEmailsToTrashAcrossNamespaces(List<PresentationEmail> emails) {
|
||||||
|
if (accountId.value == null || sessionCurrent == null) {
|
||||||
|
consumeState(Stream.value(Left(MoveMultipleEmailToMailboxFailure(
|
||||||
|
EmailActionType.moveToTrash,
|
||||||
|
MoveAction.moving,
|
||||||
|
ParametersIsNullException(),
|
||||||
|
))));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group emails by resolved trash destination: trashId → (path, sourceId → [emailIds])
|
||||||
|
final groups = <MailboxId,
|
||||||
|
({String? trashPath, Map<MailboxId, List<EmailId>> sourceToEmails})>{};
|
||||||
|
|
||||||
|
for (final email in emails) {
|
||||||
|
final sourceMailboxId = email.firstMailboxIdAvailable;
|
||||||
|
final emailId = email.id;
|
||||||
|
if (sourceMailboxId == null || emailId == null) continue;
|
||||||
|
|
||||||
|
final sourceMailbox = mapMailboxById[sourceMailboxId];
|
||||||
|
if (sourceMailbox == null) continue;
|
||||||
|
|
||||||
|
final (:trashId, :trashPath) = getTrashMailboxIdAndPath(sourceMailbox);
|
||||||
|
if (trashId == null || sourceMailboxId == trashId) continue;
|
||||||
|
|
||||||
|
groups
|
||||||
|
.putIfAbsent(trashId, () => (trashPath: trashPath, sourceToEmails: {}))
|
||||||
|
.sourceToEmails
|
||||||
|
.putIfAbsent(sourceMailboxId, () => [])
|
||||||
|
.add(emailId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groups.isEmpty) {
|
||||||
|
consumeState(Stream.value(Left(MoveMultipleEmailToMailboxFailure(
|
||||||
|
EmailActionType.moveToTrash,
|
||||||
|
MoveAction.moving,
|
||||||
|
ParametersIsNullException(),
|
||||||
|
))));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final emailIdsWithReadStatus = Map.fromEntries(
|
||||||
|
emails
|
||||||
|
.where((e) => e.id != null)
|
||||||
|
.map((e) => MapEntry(e.id!, e.hasRead)),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (final entry in groups.entries) {
|
||||||
|
final trashId = entry.key;
|
||||||
|
final resolvedPath = entry.value.trashPath ??
|
||||||
|
(currentContext != null
|
||||||
|
? mapMailboxById[trashId]?.getDisplayName(currentContext!)
|
||||||
|
: null);
|
||||||
|
|
||||||
|
log('$runtimeType::_moveEmailsToTrashAcrossNamespaces: trashId=$trashId sources=${entry.value.sourceToEmails.keys}');
|
||||||
|
moveSelectedEmailMultipleToMailboxAction(
|
||||||
|
sessionCurrent!,
|
||||||
|
accountId.value!,
|
||||||
|
MoveToMailboxRequest(
|
||||||
|
entry.value.sourceToEmails,
|
||||||
|
trashId,
|
||||||
|
MoveAction.moving,
|
||||||
|
EmailActionType.moveToTrash,
|
||||||
|
destinationPath: resolvedPath,
|
||||||
|
),
|
||||||
|
emailIdsWithReadStatus,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -506,7 +506,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Obx(() {
|
Obx(() {
|
||||||
if (controller.selectedMailbox.value?.isTrash == true) {
|
if (controller.selectedMailbox.value?.isTrashPersonal == true) {
|
||||||
return TMailButtonWidget.fromIcon(
|
return TMailButtonWidget.fromIcon(
|
||||||
key: const Key('recover_deleted_messages_button'),
|
key: const Key('recover_deleted_messages_button'),
|
||||||
icon: controller.imagePaths.icRecoverDeletedMessages,
|
icon: controller.imagePaths.icRecoverDeletedMessages,
|
||||||
|
|||||||
+2
-1
@@ -48,7 +48,8 @@ extension HandlePressEmailSelectionActionExtension on ThreadController {
|
|||||||
EmailSelectionActionType.markAsNotSpam
|
EmailSelectionActionType.markAsNotSpam
|
||||||
else
|
else
|
||||||
EmailSelectionActionType.markAsSpam,
|
EmailSelectionActionType.markAsSpam,
|
||||||
if (selectedMailbox?.isArchive != true)
|
if (selectedMailbox?.isArchive != true &&
|
||||||
|
selectedMailbox?.isChildOfTeamMailboxes != true)
|
||||||
EmailSelectionActionType.archiveMessage,
|
EmailSelectionActionType.archiveMessage,
|
||||||
if (selectedMailbox?.isDeletePermanentlyEnabled == true)
|
if (selectedMailbox?.isDeletePermanentlyEnabled == true)
|
||||||
EmailSelectionActionType.deletePermanently,
|
EmailSelectionActionType.deletePermanently,
|
||||||
|
|||||||
@@ -107,17 +107,25 @@ mixin EmailActionController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final emailId = email.id;
|
||||||
|
if (emailId == null) {
|
||||||
|
mailboxDashBoardController.emitMoveToTrashFailure(
|
||||||
|
NotFoundEmailIdException(),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_moveToTrashAction(
|
_moveToTrashAction(
|
||||||
session,
|
session,
|
||||||
accountId,
|
accountId,
|
||||||
MoveToMailboxRequest(
|
MoveToMailboxRequest(
|
||||||
{mailboxContain.id: email.id != null ? [email.id!] : []},
|
{mailboxContain.id: [emailId]},
|
||||||
trashId,
|
trashId,
|
||||||
MoveAction.moving,
|
MoveAction.moving,
|
||||||
EmailActionType.moveToTrash,
|
EmailActionType.moveToTrash,
|
||||||
destinationPath: trashPath,
|
destinationPath: trashPath,
|
||||||
),
|
),
|
||||||
email.id != null ? {email.id!: email.hasRead} : {},
|
{emailId: email.hasRead},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ mixin EmailMoreActionContextMenu on LabelSubMenuMixin {
|
|||||||
if (PlatformInfo.isWeb) EmailActionType.openInNewTab,
|
if (PlatformInfo.isWeb) EmailActionType.openInNewTab,
|
||||||
if (!isDrafts && !isChildOfTeam)
|
if (!isDrafts && !isChildOfTeam)
|
||||||
isSpam ? EmailActionType.unSpam : EmailActionType.moveToSpam,
|
isSpam ? EmailActionType.unSpam : EmailActionType.moveToSpam,
|
||||||
if (!isArchive) EmailActionType.archiveMessage,
|
if (!isArchive && !isChildOfTeam) EmailActionType.archiveMessage,
|
||||||
if (!isDrafts && !isTemplates) EmailActionType.editAsNewEmail,
|
if (!isDrafts && !isTemplates) EmailActionType.editAsNewEmail,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1563,9 +1563,11 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
return DismissDirection.none;
|
return DismissDirection.none;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isInArchiveMailbox(email) || !hasArchiveMailbox()
|
return isInArchiveMailbox(email) ||
|
||||||
? DismissDirection.startToEnd
|
!hasArchiveMailbox() ||
|
||||||
: DismissDirection.horizontal;
|
email.mailboxContain?.isChildOfTeamMailboxes == true
|
||||||
|
? DismissDirection.startToEnd
|
||||||
|
: DismissDirection.horizontal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInArchiveMailbox(PresentationEmail email) => email.mailboxContain?.isArchive == true;
|
bool isInArchiveMailbox(PresentationEmail email) => email.mailboxContain?.isArchive == true;
|
||||||
|
|||||||
+13
-6
@@ -1,5 +1,6 @@
|
|||||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||||
|
import 'package:model/extensions/presentation_mailbox_extension.dart';
|
||||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||||
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
||||||
|
|
||||||
@@ -26,16 +27,22 @@ extension GetThreadDetailActionStatus on ThreadDetailController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool get threadDetailIsArchived {
|
bool get threadDetailIsArchived {
|
||||||
final archiveMailboxId = getMailboxIdByRole(
|
final archiveMailboxId = getMailboxIdByRole(PresentationMailbox.roleArchive);
|
||||||
PresentationMailbox.roleArchive,
|
|
||||||
);
|
|
||||||
return emailsInThreadDetailInfo.every(
|
return emailsInThreadDetailInfo.every(
|
||||||
(email) {
|
(email) => email.mailboxIds?[archiveMailboxId] == true,
|
||||||
return email.mailboxIds?[archiveMailboxId] == true;
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get threadDetailIsTeamMailbox {
|
||||||
|
return emailsInThreadDetailInfo.any((email) {
|
||||||
|
final mailboxId = email.mailboxIdContain;
|
||||||
|
if (mailboxId == null) return false;
|
||||||
|
return mailboxDashBoardController.mapMailboxById[mailboxId]
|
||||||
|
?.isChildOfTeamMailboxes ==
|
||||||
|
true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool get threadDetailIsSpam {
|
bool get threadDetailIsSpam {
|
||||||
final spamMailboxId =
|
final spamMailboxId =
|
||||||
getMailboxIdByRole(PresentationMailbox.roleJunk) ??
|
getMailboxIdByRole(PresentationMailbox.roleJunk) ??
|
||||||
|
|||||||
+1
-1
@@ -147,7 +147,7 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
|||||||
if (mailboxDashBoardController.isLabelAvailable &&
|
if (mailboxDashBoardController.isLabelAvailable &&
|
||||||
mailboxDashBoardController.labelController.labels.isNotEmpty)
|
mailboxDashBoardController.labelController.labels.isNotEmpty)
|
||||||
EmailActionType.labelAs,
|
EmailActionType.labelAs,
|
||||||
if (!threadDetailIsArchived) EmailActionType.archiveMessage,
|
if (!threadDetailIsArchived && !threadDetailIsTeamMailbox) EmailActionType.archiveMessage,
|
||||||
threadDetailIsSpam ? EmailActionType.unSpam : EmailActionType.moveToSpam,
|
threadDetailIsSpam ? EmailActionType.unSpam : EmailActionType.moveToSpam,
|
||||||
threadDetailIsTrashed
|
threadDetailIsTrashed
|
||||||
? EmailActionType.deletePermanently
|
? EmailActionType.deletePermanently
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ extension ListPresentationEmailExtension on List<PresentationEmail> {
|
|||||||
) {
|
) {
|
||||||
return any((email) {
|
return any((email) {
|
||||||
final mailboxContain = email.findMailboxContain(mapMailbox);
|
final mailboxContain = email.findMailboxContain(mapMailbox);
|
||||||
return mailboxContain?.isArchive != true;
|
return mailboxContain?.isArchive != true &&
|
||||||
|
mailboxContain?.isChildOfTeamMailboxes != true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,18 +40,29 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
|||||||
|
|
||||||
bool get isVirtualFolder => isFavorite || isActionRequired;
|
bool get isVirtualFolder => isFavorite || isActionRequired;
|
||||||
|
|
||||||
bool get isTrash {
|
bool get isTrash => isTrashPersonal || isTrashTeamMailbox;
|
||||||
if (isPersonal) {
|
|
||||||
return role == PresentationMailbox.roleTrash;
|
bool get isTrashPersonal =>
|
||||||
} else {
|
isPersonal && role == PresentationMailbox.roleTrash;
|
||||||
return isTrashTeamMailbox;
|
|
||||||
}
|
bool _isTeamMailboxWithRole(String role) =>
|
||||||
|
isChildOfTeamMailboxes &&
|
||||||
|
name?.name.toLowerCase() == role.toLowerCase();
|
||||||
|
|
||||||
|
/// Stricter version of [_isTeamMailboxWithRole] that additionally checks
|
||||||
|
/// the parent is a team-root node (no parentId), ensuring only first-level
|
||||||
|
/// system folders match — not nested user subfolders like Team/Project/Trash.
|
||||||
|
bool isFirstLevelTeamSystemFolder(
|
||||||
|
Map<MailboxId, PresentationMailbox> mailboxMap,
|
||||||
|
String role,
|
||||||
|
) {
|
||||||
|
if (!_isTeamMailboxWithRole(role)) return false;
|
||||||
|
final parent = parentId != null ? mailboxMap[parentId] : null;
|
||||||
|
return parent?.isTeamMailboxes == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isTrashTeamMailbox {
|
bool get isTrashTeamMailbox =>
|
||||||
return isChildOfTeamMailboxes &&
|
_isTeamMailboxWithRole(PresentationMailbox.trashRole);
|
||||||
name?.name.toLowerCase() == PresentationMailbox.trashRole.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get isDrafts {
|
bool get isDrafts {
|
||||||
if (isPersonal) {
|
if (isPersonal) {
|
||||||
@@ -61,11 +72,8 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isDraftsTeamMailbox {
|
bool get isDraftsTeamMailbox =>
|
||||||
return isChildOfTeamMailboxes &&
|
_isTeamMailboxWithRole(PresentationMailbox.draftsRole);
|
||||||
name?.name.toLowerCase() ==
|
|
||||||
PresentationMailbox.draftsRole.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get isTemplates {
|
bool get isTemplates {
|
||||||
if (isPersonal) {
|
if (isPersonal) {
|
||||||
@@ -75,11 +83,8 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isTemplatesTeamMailbox {
|
bool get isTemplatesTeamMailbox =>
|
||||||
return isChildOfTeamMailboxes &&
|
_isTeamMailboxWithRole(PresentationMailbox.templatesRole);
|
||||||
name?.name.toLowerCase() ==
|
|
||||||
PresentationMailbox.templatesRole.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get isSent => role == PresentationMailbox.roleSent;
|
bool get isSent => role == PresentationMailbox.roleSent;
|
||||||
|
|
||||||
|
|||||||
-301
@@ -1,301 +0,0 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/namespace.dart';
|
|
||||||
import 'package:mockito/annotations.dart';
|
|
||||||
import 'package:mockito/mockito.dart';
|
|
||||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_controller.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/presentation/mixin/handle_team_mailbox_mixin.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 'handle_team_mailbox_extension_test.mocks.dart';
|
|
||||||
|
|
||||||
class TestHandleTeamMailboxMixin with HandleTeamMailboxMixin {}
|
|
||||||
|
|
||||||
@GenerateNiceMocks([
|
|
||||||
MockSpec<MailboxController>(),
|
|
||||||
])
|
|
||||||
void main() {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
late TestHandleTeamMailboxMixin testMixin;
|
|
||||||
late MockMailboxController mockMailboxController;
|
|
||||||
|
|
||||||
final teamNamespace = Namespace('#TeamMailbox');
|
|
||||||
final teamMailboxId = MailboxId(Id('team-root'));
|
|
||||||
final teamTrashId = MailboxId(Id('team-trash'));
|
|
||||||
final teamInboxId = MailboxId(Id('team-inbox'));
|
|
||||||
final teamSentId = MailboxId(Id('team-sent'));
|
|
||||||
|
|
||||||
MailboxTree buildTeamMailboxTree({
|
|
||||||
List<MailboxNode>? teamChildren,
|
|
||||||
}) {
|
|
||||||
return MailboxTree(
|
|
||||||
MailboxNode(
|
|
||||||
MailboxNode.rootItem(),
|
|
||||||
childrenItems: [
|
|
||||||
MailboxNode(
|
|
||||||
PresentationMailbox(
|
|
||||||
teamMailboxId,
|
|
||||||
name: MailboxName('Team'),
|
|
||||||
namespace: teamNamespace,
|
|
||||||
),
|
|
||||||
childrenItems: teamChildren ??
|
|
||||||
[
|
|
||||||
MailboxNode(
|
|
||||||
PresentationMailbox(
|
|
||||||
teamTrashId,
|
|
||||||
name: MailboxName('Trash'),
|
|
||||||
namespace: teamNamespace,
|
|
||||||
parentId: teamMailboxId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MailboxNode(
|
|
||||||
PresentationMailbox(
|
|
||||||
teamInboxId,
|
|
||||||
name: MailboxName('Inbox'),
|
|
||||||
namespace: teamNamespace,
|
|
||||||
parentId: teamMailboxId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MailboxNode(
|
|
||||||
PresentationMailbox(
|
|
||||||
teamSentId,
|
|
||||||
name: MailboxName('Sent'),
|
|
||||||
namespace: teamNamespace,
|
|
||||||
parentId: teamMailboxId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
Get.testMode = true;
|
|
||||||
|
|
||||||
mockMailboxController = MockMailboxController();
|
|
||||||
when(mockMailboxController.onStart)
|
|
||||||
.thenReturn(InternalFinalCallback(callback: () {}));
|
|
||||||
when(mockMailboxController.onDelete)
|
|
||||||
.thenReturn(InternalFinalCallback(callback: () {}));
|
|
||||||
|
|
||||||
Get.put<MailboxController>(mockMailboxController);
|
|
||||||
|
|
||||||
testMixin = TestHandleTeamMailboxMixin();
|
|
||||||
});
|
|
||||||
|
|
||||||
tearDown(() {
|
|
||||||
Get.reset();
|
|
||||||
});
|
|
||||||
|
|
||||||
group('HandleTeamMailboxMixin::findDefaultMailboxIdInTeamMailbox', () {
|
|
||||||
test(
|
|
||||||
'SHOULD return trash mailbox id '
|
|
||||||
'WHEN namespace matches and trash mailbox exists',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals(teamTrashId));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN namespace does not match any team mailbox',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: Namespace('#UnknownTeam'),
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN mailbox name does not match any child',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: 'archive',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD match mailbox name case-insensitively',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: 'TRASH',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals(teamTrashId));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN team mailbox tree is empty',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(MailboxTree(MailboxNode.root()).obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN team mailbox has no children',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree(teamChildren: []).obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return correct mailbox id '
|
|
||||||
'WHEN searching for inbox in team mailbox',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.inboxRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals(teamInboxId));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN MailboxController is not registered',
|
|
||||||
() {
|
|
||||||
Get.delete<MailboxController>();
|
|
||||||
|
|
||||||
final result = testMixin.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('HandleTeamMailboxMixin::getTeamMailboxNodePathWithSeparator', () {
|
|
||||||
test(
|
|
||||||
'SHOULD return path with parent separator '
|
|
||||||
'WHEN mailbox has a parent',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamTrashId,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals('Team/Trash'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return path with custom separator '
|
|
||||||
'WHEN custom pathSeparator is provided',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamTrashId,
|
|
||||||
pathSeparator: '.',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals('Team.Trash'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN mailbox id does not exist in tree',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: MailboxId(Id('non-existent')),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return mailbox name only '
|
|
||||||
'WHEN mailbox has no parent',
|
|
||||||
() {
|
|
||||||
when(mockMailboxController.teamMailboxesTree)
|
|
||||||
.thenReturn(buildTeamMailboxTree().obs);
|
|
||||||
|
|
||||||
final result = testMixin.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamMailboxId,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals('Team'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null '
|
|
||||||
'WHEN MailboxController is not registered',
|
|
||||||
() {
|
|
||||||
Get.delete<MailboxController>();
|
|
||||||
|
|
||||||
final result = testMixin.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamTrashId,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/namespace.dart';
|
|
||||||
import 'package:mockito/annotations.dart';
|
|
||||||
import 'package:mockito/mockito.dart';
|
|
||||||
import 'package:model/mailbox/presentation_mailbox.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/get_trash_mailbox_id_and_path_extension.dart';
|
|
||||||
|
|
||||||
import 'get_trash_mailbox_id_and_path_test.mocks.dart';
|
|
||||||
|
|
||||||
@GenerateNiceMocks([
|
|
||||||
MockSpec<MailboxDashBoardController>(),
|
|
||||||
])
|
|
||||||
void main() {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
final defaultTrashId = MailboxId(Id('default-trash'));
|
|
||||||
final teamNamespace = Namespace('#TeamMailbox');
|
|
||||||
final teamMailboxId = MailboxId(Id('team-root'));
|
|
||||||
final teamTrashId = MailboxId(Id('team-trash'));
|
|
||||||
|
|
||||||
final personalMailbox = PresentationMailbox(
|
|
||||||
MailboxId(Id('personal-inbox')),
|
|
||||||
name: MailboxName('Inbox'),
|
|
||||||
);
|
|
||||||
|
|
||||||
final teamMailbox = PresentationMailbox(
|
|
||||||
teamMailboxId,
|
|
||||||
name: MailboxName('Team'),
|
|
||||||
namespace: teamNamespace,
|
|
||||||
);
|
|
||||||
|
|
||||||
final teamMailboxWithNullNamespace = PresentationMailbox(
|
|
||||||
MailboxId(Id('team-no-ns')),
|
|
||||||
name: MailboxName('Team No NS'),
|
|
||||||
);
|
|
||||||
|
|
||||||
late MockMailboxDashBoardController mockDashBoardController;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
Get.testMode = true;
|
|
||||||
|
|
||||||
mockDashBoardController = MockMailboxDashBoardController();
|
|
||||||
|
|
||||||
when(mockDashBoardController.mapDefaultMailboxIdByRole)
|
|
||||||
.thenReturn({PresentationMailbox.roleTrash: defaultTrashId});
|
|
||||||
when(mockDashBoardController.selectedMailbox)
|
|
||||||
.thenReturn(Rxn<PresentationMailbox>());
|
|
||||||
});
|
|
||||||
|
|
||||||
group('GetTrashMailboxIdAndPathExtension::getTrashMailboxIdAndPath', () {
|
|
||||||
test(
|
|
||||||
'SHOULD return default trash id with null path '
|
|
||||||
'WHEN emailMailbox is personal (no namespace)',
|
|
||||||
() {
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
personalMailbox,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, equals(defaultTrashId));
|
|
||||||
expect(result.trashPath, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return team trash id '
|
|
||||||
'WHEN emailMailbox is team mailbox even if selectedMailbox is personal',
|
|
||||||
() {
|
|
||||||
when(mockDashBoardController.selectedMailbox)
|
|
||||||
.thenReturn(Rxn(personalMailbox));
|
|
||||||
when(mockDashBoardController.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
)).thenReturn(teamTrashId);
|
|
||||||
when(mockDashBoardController.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamTrashId,
|
|
||||||
)).thenReturn('Team/Trash');
|
|
||||||
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
teamMailbox,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, equals(teamTrashId));
|
|
||||||
expect(result.trashPath, equals('Team/Trash'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return default trash id with null path '
|
|
||||||
'WHEN mailbox namespace is null',
|
|
||||||
() {
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
teamMailboxWithNullNamespace,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, equals(defaultTrashId));
|
|
||||||
expect(result.trashPath, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return default trash id with null path '
|
|
||||||
'WHEN findDefaultMailboxIdInTeamMailbox returns null',
|
|
||||||
() {
|
|
||||||
when(mockDashBoardController.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
)).thenReturn(null);
|
|
||||||
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
teamMailbox,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, equals(defaultTrashId));
|
|
||||||
expect(result.trashPath, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return team trash id with path '
|
|
||||||
'WHEN team mailbox has trash folder',
|
|
||||||
() {
|
|
||||||
when(mockDashBoardController.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
)).thenReturn(teamTrashId);
|
|
||||||
when(mockDashBoardController.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamTrashId,
|
|
||||||
)).thenReturn('Team/Trash');
|
|
||||||
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
teamMailbox,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, equals(teamTrashId));
|
|
||||||
expect(result.trashPath, equals('Team/Trash'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return team trash id with null path '
|
|
||||||
'WHEN getTeamMailboxNodePathWithSeparator returns null',
|
|
||||||
() {
|
|
||||||
when(mockDashBoardController.findDefaultMailboxIdInTeamMailbox(
|
|
||||||
namespace: teamNamespace,
|
|
||||||
mailboxName: PresentationMailbox.trashRole,
|
|
||||||
)).thenReturn(teamTrashId);
|
|
||||||
when(mockDashBoardController.getTeamMailboxNodePathWithSeparator(
|
|
||||||
mailboxId: teamTrashId,
|
|
||||||
)).thenReturn(null);
|
|
||||||
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
teamMailbox,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, equals(teamTrashId));
|
|
||||||
expect(result.trashPath, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'SHOULD return null trash id with null path '
|
|
||||||
'WHEN mapDefaultMailboxIdByRole has no trash entry '
|
|
||||||
'AND mailbox is personal',
|
|
||||||
() {
|
|
||||||
when(mockDashBoardController.mapDefaultMailboxIdByRole).thenReturn({});
|
|
||||||
|
|
||||||
final result = mockDashBoardController.getTrashMailboxIdAndPath(
|
|
||||||
personalMailbox,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.trashId, isNull);
|
|
||||||
expect(result.trashPath, isNull);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user