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;
|
||||
}
|
||||
|
||||
final emailId = email.id;
|
||||
if (emailId == null) {
|
||||
mailboxDashBoardController.emitMoveToTrashFailure(
|
||||
NotFoundEmailIdException(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final moveActionRequest = emailActionReactor.buildMoveToTrashRequest(
|
||||
email,
|
||||
trashMailboxId: trashId,
|
||||
|
||||
@@ -40,4 +40,11 @@ class NotFoundTrashMailboxException extends AppBaseException {
|
||||
|
||||
@override
|
||||
String get exceptionName => 'NotFoundTrashMailboxException';
|
||||
}
|
||||
}
|
||||
|
||||
class NotFoundEmailIdException extends AppBaseException {
|
||||
NotFoundEmailIdException([super.message]);
|
||||
|
||||
@override
|
||||
String get exceptionName => 'NotFoundEmailIdException';
|
||||
}
|
||||
|
||||
@@ -87,20 +87,20 @@ mixin MailboxWidgetMixin {
|
||||
return [
|
||||
if (PlatformInfo.isWeb && mailbox.isSubscribedMailbox)
|
||||
MailboxActions.openInNewTab,
|
||||
if (mailbox.myRights?.mayCreateChild == true)
|
||||
if (mailbox.myRights?.mayCreateChild != false)
|
||||
MailboxActions.newSubfolder,
|
||||
if (mailbox.countUnReadEmailsAsString.isNotEmpty)
|
||||
MailboxActions.markAsRead,
|
||||
if (mailbox.myRights?.mayRename == true)
|
||||
if (mailbox.myRights?.mayRename != false)
|
||||
MailboxActions.rename,
|
||||
if (mailbox.isTeamMailboxes)
|
||||
if (mailbox.isSubscribedMailbox)
|
||||
MailboxActions.disableMailbox
|
||||
else
|
||||
MailboxActions.enableMailbox,
|
||||
if (mailbox.isTrash && mailbox.myRights?.mayRemoveItems == true)
|
||||
if (mailbox.isTrash && mailbox.myRights?.mayRemoveItems != false)
|
||||
MailboxActions.emptyTrash,
|
||||
if (mailbox.myRights?.mayDelete == true)
|
||||
if (mailbox.myRights?.mayDelete != false)
|
||||
MailboxActions.delete,
|
||||
];
|
||||
}
|
||||
|
||||
+3
-5
@@ -1864,7 +1864,7 @@ class MailboxDashBoardController extends ReloadableController
|
||||
}
|
||||
|
||||
if (CapabilityIdentifier.jmapMailboxClear.isSupported(session, accountId) &&
|
||||
trashFolder.isTrashTeamMailbox != true) {
|
||||
!trashFolder.isFirstLevelTeamSystemFolder(mapMailboxById, PresentationMailbox.trashRole)) {
|
||||
clearMailbox(
|
||||
session,
|
||||
accountId,
|
||||
@@ -2406,8 +2406,7 @@ class MailboxDashBoardController extends ReloadableController
|
||||
PresentationMailbox? mailbox
|
||||
) {
|
||||
return mailbox != null &&
|
||||
mailbox.isTrash &&
|
||||
mailbox.myRights?.mayRemoveItems == true &&
|
||||
(mailbox.isTrash || (mailbox.isTrashTeamMailbox && mailbox.myRights?.mayRemoveItems != false)) &&
|
||||
mailbox.countTotalEmails > 0 &&
|
||||
!searchController.isSearchActive() &&
|
||||
responsiveUtils.isWebDesktop(context);
|
||||
@@ -2418,8 +2417,7 @@ class MailboxDashBoardController extends ReloadableController
|
||||
PresentationMailbox? mailbox
|
||||
) {
|
||||
return mailbox != null &&
|
||||
mailbox.isTrash &&
|
||||
mailbox.myRights?.mayRemoveItems == true &&
|
||||
(mailbox.isTrash || (mailbox.isTrashTeamMailbox && mailbox.myRights?.mayRemoveItems != false)) &&
|
||||
mailbox.countTotalEmails > 0 &&
|
||||
!searchController.isSearchActive() &&
|
||||
!responsiveUtils.isWebDesktop(context);
|
||||
|
||||
+82
-2
@@ -23,6 +23,17 @@ extension HandleActionTypeForEmailSelection on MailboxDashBoardController {
|
||||
EmailActionType actionType,
|
||||
{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;
|
||||
|
||||
if (actionType == EmailActionType.moveToMailbox) {
|
||||
@@ -58,8 +69,7 @@ extension HandleActionTypeForEmailSelection on MailboxDashBoardController {
|
||||
|
||||
final mapEmailIdsByMailboxId = <MailboxId, List<EmailId>>{};
|
||||
|
||||
if (searchController.isSearchEmailRunning ||
|
||||
selectedMailbox.value?.isVirtualFolder == true) {
|
||||
if (isInSearchOrVirtualFolder) {
|
||||
for (final email in emails) {
|
||||
final mailboxId = email.firstMailboxIdAvailable;
|
||||
final emailId = email.id;
|
||||
@@ -115,4 +125,74 @@ extension HandleActionTypeForEmailSelection on MailboxDashBoardController {
|
||||
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(() {
|
||||
if (controller.selectedMailbox.value?.isTrash == true) {
|
||||
if (controller.selectedMailbox.value?.isTrashPersonal == true) {
|
||||
return TMailButtonWidget.fromIcon(
|
||||
key: const Key('recover_deleted_messages_button'),
|
||||
icon: controller.imagePaths.icRecoverDeletedMessages,
|
||||
|
||||
+2
-1
@@ -48,7 +48,8 @@ extension HandlePressEmailSelectionActionExtension on ThreadController {
|
||||
EmailSelectionActionType.markAsNotSpam
|
||||
else
|
||||
EmailSelectionActionType.markAsSpam,
|
||||
if (selectedMailbox?.isArchive != true)
|
||||
if (selectedMailbox?.isArchive != true &&
|
||||
selectedMailbox?.isChildOfTeamMailboxes != true)
|
||||
EmailSelectionActionType.archiveMessage,
|
||||
if (selectedMailbox?.isDeletePermanentlyEnabled == true)
|
||||
EmailSelectionActionType.deletePermanently,
|
||||
|
||||
@@ -107,17 +107,25 @@ mixin EmailActionController {
|
||||
return;
|
||||
}
|
||||
|
||||
final emailId = email.id;
|
||||
if (emailId == null) {
|
||||
mailboxDashBoardController.emitMoveToTrashFailure(
|
||||
NotFoundEmailIdException(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
_moveToTrashAction(
|
||||
session,
|
||||
accountId,
|
||||
MoveToMailboxRequest(
|
||||
{mailboxContain.id: email.id != null ? [email.id!] : []},
|
||||
{mailboxContain.id: [emailId]},
|
||||
trashId,
|
||||
MoveAction.moving,
|
||||
EmailActionType.moveToTrash,
|
||||
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 (!isDrafts && !isChildOfTeam)
|
||||
isSpam ? EmailActionType.unSpam : EmailActionType.moveToSpam,
|
||||
if (!isArchive) EmailActionType.archiveMessage,
|
||||
if (!isArchive && !isChildOfTeam) EmailActionType.archiveMessage,
|
||||
if (!isDrafts && !isTemplates) EmailActionType.editAsNewEmail,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1563,9 +1563,11 @@ class ThreadController extends BaseController with EmailActionController {
|
||||
return DismissDirection.none;
|
||||
}
|
||||
|
||||
return isInArchiveMailbox(email) || !hasArchiveMailbox()
|
||||
? DismissDirection.startToEnd
|
||||
: DismissDirection.horizontal;
|
||||
return isInArchiveMailbox(email) ||
|
||||
!hasArchiveMailbox() ||
|
||||
email.mailboxContain?.isChildOfTeamMailboxes == true
|
||||
? DismissDirection.startToEnd
|
||||
: DismissDirection.horizontal;
|
||||
}
|
||||
|
||||
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/mailbox/mailbox.dart';
|
||||
import 'package:model/extensions/presentation_mailbox_extension.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.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 {
|
||||
final archiveMailboxId = getMailboxIdByRole(
|
||||
PresentationMailbox.roleArchive,
|
||||
);
|
||||
final archiveMailboxId = getMailboxIdByRole(PresentationMailbox.roleArchive);
|
||||
return emailsInThreadDetailInfo.every(
|
||||
(email) {
|
||||
return email.mailboxIds?[archiveMailboxId] == true;
|
||||
},
|
||||
(email) => 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 {
|
||||
final spamMailboxId =
|
||||
getMailboxIdByRole(PresentationMailbox.roleJunk) ??
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
if (mailboxDashBoardController.isLabelAvailable &&
|
||||
mailboxDashBoardController.labelController.labels.isNotEmpty)
|
||||
EmailActionType.labelAs,
|
||||
if (!threadDetailIsArchived) EmailActionType.archiveMessage,
|
||||
if (!threadDetailIsArchived && !threadDetailIsTeamMailbox) EmailActionType.archiveMessage,
|
||||
threadDetailIsSpam ? EmailActionType.unSpam : EmailActionType.moveToSpam,
|
||||
threadDetailIsTrashed
|
||||
? EmailActionType.deletePermanently
|
||||
|
||||
Reference in New Issue
Block a user