TF-3189 new option to copy a folder's subaddress
This commit is contained in:
committed by
Dat H. Pham
parent
89d80fe142
commit
f1ec1d7324
@@ -216,14 +216,18 @@ abstract class BaseMailboxController extends BaseController {
|
||||
return teamMailboxesTree.value.findNode((node) => node.item.id == mailboxId);
|
||||
}
|
||||
|
||||
String? findNodePath(MailboxId mailboxId) {
|
||||
var mailboxNodePath = defaultMailboxTree.value.getNodePath(mailboxId)
|
||||
?? personalMailboxTree.value.getNodePath(mailboxId)
|
||||
?? teamMailboxesTree.value.getNodePath(mailboxId);
|
||||
String? findNodePathWithSeparator(MailboxId mailboxId, String pathSeparator) {
|
||||
var mailboxNodePath = defaultMailboxTree.value.getNodePath(mailboxId, pathSeparator)
|
||||
?? personalMailboxTree.value.getNodePath(mailboxId, pathSeparator)
|
||||
?? teamMailboxesTree.value.getNodePath(mailboxId, pathSeparator);
|
||||
log('BaseMailboxController::findNodePath():mailboxNodePath: $mailboxNodePath');
|
||||
return mailboxNodePath;
|
||||
}
|
||||
|
||||
String? findNodePath(MailboxId mailboxId) {
|
||||
return findNodePathWithSeparator(mailboxId, '/');
|
||||
}
|
||||
|
||||
MailboxNode? findMailboxNodeByRole(Role role) {
|
||||
final mailboxNode = defaultMailboxTree.value.findNode((node) => node.item.role == role);
|
||||
return mailboxNode;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
class EmptyFolderNameException implements Exception {
|
||||
final String folderName;
|
||||
|
||||
EmptyFolderNameException(this.folderName);
|
||||
|
||||
@override
|
||||
String toString() => 'EmptyFolderNameException: Folder name should not be empty: $folderName';
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
class InvalidMailFormatException implements Exception {
|
||||
final String mail;
|
||||
|
||||
InvalidMailFormatException(this.mail);
|
||||
|
||||
@override
|
||||
String toString() => 'InvalidMailFormatException: $mail';
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
@@ -30,6 +31,8 @@ import 'package:tmail_ui_user/features/email/presentation/model/composer_argumen
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/extensions/session_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/constants/mailbox_constants.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/empty_folder_name_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/invalid_mail_format_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/set_mailbox_name_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/null_session_or_accountid_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
@@ -1248,6 +1251,14 @@ class MailboxController extends BaseMailboxController
|
||||
case MailboxActions.openInNewTab:
|
||||
openMailboxInNewTabAction(mailbox);
|
||||
break;
|
||||
case MailboxActions.copySubaddress:
|
||||
try{
|
||||
final subaddress = getSubaddress(mailboxDashBoardController.userEmail, findNodePathWithSeparator(mailbox.id, '.')!);
|
||||
copySubaddressAction(context, subaddress);
|
||||
} catch (error) {
|
||||
appToast.showToastErrorMessage(context, AppLocalizations.of(context).errorWhileFetchingSubaddress);
|
||||
}
|
||||
break;
|
||||
case MailboxActions.disableSpamReport:
|
||||
case MailboxActions.enableSpamReport:
|
||||
mailboxDashBoardController.storeSpamReportStateAction();
|
||||
@@ -1632,4 +1643,22 @@ class MailboxController extends BaseMailboxController
|
||||
|
||||
return session.getContactSupportCapability(accountId);
|
||||
}
|
||||
|
||||
void copySubaddressAction(BuildContext context, String subaddress) {
|
||||
Clipboard.setData(ClipboardData(text: subaddress));
|
||||
appToast.showToastSuccessMessage(context, AppLocalizations.of(context).emailSubaddressCopiedToClipboard);
|
||||
}
|
||||
|
||||
String getSubaddress(String userEmail, String folderName) {
|
||||
if (folderName.isEmpty) {
|
||||
throw EmptyFolderNameException(folderName);
|
||||
}
|
||||
|
||||
final atIndex = userEmail.indexOf('@');
|
||||
if (atIndex <= 0 || atIndex == userEmail.length - 1) {
|
||||
throw InvalidMailFormatException(userEmail);
|
||||
}
|
||||
|
||||
return '${userEmail.substring(0, atIndex)}+$folderName@${userEmail.substring(atIndex + 1)}';
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,8 @@ mixin MailboxWidgetMixin {
|
||||
MailboxActions.disallowSubaddressing
|
||||
else
|
||||
MailboxActions.allowSubaddressing,
|
||||
if (mailbox.isSubaddressingAllowed)
|
||||
MailboxActions.copySubaddress,
|
||||
if (mailbox.isSubscribedMailbox)
|
||||
MailboxActions.disableMailbox
|
||||
else
|
||||
|
||||
@@ -16,6 +16,7 @@ enum MailboxActions {
|
||||
markAsRead,
|
||||
selectForRuleAction,
|
||||
openInNewTab,
|
||||
copySubaddress,
|
||||
disableSpamReport,
|
||||
enableSpamReport,
|
||||
disableMailbox,
|
||||
@@ -50,6 +51,8 @@ extension MailboxActionsExtension on MailboxActions {
|
||||
switch(this) {
|
||||
case MailboxActions.openInNewTab:
|
||||
return AppLocalizations.of(context).openInNewTab;
|
||||
case MailboxActions.copySubaddress:
|
||||
return AppLocalizations.of(context).copySubaddress;
|
||||
case MailboxActions.newSubfolder:
|
||||
return AppLocalizations.of(context).newSubfolder;
|
||||
case MailboxActions.disableSpamReport:
|
||||
@@ -89,6 +92,8 @@ extension MailboxActionsExtension on MailboxActions {
|
||||
switch(this) {
|
||||
case MailboxActions.openInNewTab:
|
||||
return imagePaths.icOpenInNewTab;
|
||||
case MailboxActions.copySubaddress:
|
||||
return imagePaths.icCopy;
|
||||
case MailboxActions.newSubfolder:
|
||||
return imagePaths.icAddNewFolder;
|
||||
case MailboxActions.disableSpamReport:
|
||||
@@ -181,6 +186,7 @@ extension MailboxActionsExtension on MailboxActions {
|
||||
ContextMenuItemState getContextMenuItemState(PresentationMailbox mailbox) {
|
||||
switch(this) {
|
||||
case MailboxActions.openInNewTab:
|
||||
case MailboxActions.copySubaddress:
|
||||
case MailboxActions.newSubfolder:
|
||||
case MailboxActions.disableSpamReport:
|
||||
case MailboxActions.enableSpamReport:
|
||||
|
||||
@@ -121,7 +121,7 @@ class MailboxTree with EquatableMixin {
|
||||
return false;
|
||||
}
|
||||
|
||||
String? getNodePath(MailboxId mailboxId) {
|
||||
String? getNodePath(MailboxId mailboxId, String pathSeparator) {
|
||||
final matchedNode = findNode((node) => node.item.id == mailboxId);
|
||||
if (matchedNode == null) {
|
||||
return null;
|
||||
@@ -141,9 +141,9 @@ class MailboxTree with EquatableMixin {
|
||||
break;
|
||||
}
|
||||
if (currentContext != null) {
|
||||
path = '${parentNode.item.getDisplayName(currentContext!)}/$path';
|
||||
path = '${parentNode.item.getDisplayName(currentContext!)}$pathSeparator$path';
|
||||
} else {
|
||||
path = '${parentNode.item.name?.name}/$path';
|
||||
path = '${parentNode.item.name?.name}$pathSeparator$path';
|
||||
}
|
||||
parentId = parentNode.item.parentId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user