TF-4195 Add Label to Thread
This commit is contained in:
@@ -68,9 +68,9 @@ class PopupSubmenuController {
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
||||
),
|
||||
child: SizedBox(
|
||||
child: Container(
|
||||
width: submenuWidth,
|
||||
height: finalHeight,
|
||||
constraints: BoxConstraints(maxHeight: finalHeight),
|
||||
child: submenu,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -211,4 +211,11 @@ abstract class EmailDataSource {
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
}
|
||||
@@ -570,4 +570,21 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.addLabelToThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -580,4 +580,9 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -356,4 +356,9 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -270,4 +270,9 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -964,4 +964,36 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
throw parseErrorForSetResponse(response, emailId.id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) async {
|
||||
final method = SetEmailMethod(accountId)
|
||||
..addUpdates(emailIds.generateMapUpdateObjectLabel(labelKeyword));
|
||||
|
||||
final builder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
final invocation = builder.invocation(method);
|
||||
|
||||
final capabilities = method.requiredCapabilities
|
||||
.toCapabilitiesSupportTeamMailboxes(session, accountId);
|
||||
final result = await (builder..usings(capabilities)).build().execute();
|
||||
|
||||
final response = result.parse<SetEmailResponse>(
|
||||
invocation.methodCallId,
|
||||
SetEmailResponse.deserialize,
|
||||
);
|
||||
|
||||
final emailIdsUpdated = response?.updated?.keys ?? <Id>[];
|
||||
final ids = emailIds.map((emailId) => emailId.id);
|
||||
final isUpdated = emailIdsUpdated.every(ids.contains);
|
||||
|
||||
if (emailIdsUpdated.isEmpty || !isUpdated) {
|
||||
for (var id in emailIds) {
|
||||
throw parseErrorForSetResponse(response, id.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -495,4 +495,19 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return emailDataSource[DataSourceType.network]!.addLabelToThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -168,4 +168,11 @@ abstract class EmailRepository {
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
|
||||
class AddingALabelToAThread extends LoadingState {}
|
||||
|
||||
class AddALabelToAThreadSuccess extends UIState {
|
||||
final List<EmailId> emailIds;
|
||||
final KeyWordIdentifier labelKeyword;
|
||||
final String labelDisplay;
|
||||
|
||||
AddALabelToAThreadSuccess(this.emailIds, this.labelKeyword, this.labelDisplay);
|
||||
|
||||
@override
|
||||
List<Object> get props => [emailIds, labelKeyword, labelDisplay];
|
||||
}
|
||||
|
||||
class AddALabelToAThreadFailure extends FeatureFailure {
|
||||
final String labelDisplay;
|
||||
|
||||
AddALabelToAThreadFailure({
|
||||
dynamic exception,
|
||||
required this.labelDisplay,
|
||||
}) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [...super.props, labelDisplay];
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_thread_state.dart';
|
||||
|
||||
class AddALabelToAThreadInteractor {
|
||||
final EmailRepository _emailRepository;
|
||||
|
||||
AddALabelToAThreadInteractor(this._emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
String labelDisplay,
|
||||
) async* {
|
||||
try {
|
||||
yield Right(AddingALabelToAThread());
|
||||
await _emailRepository.addLabelToThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
yield Right(AddALabelToAThreadSuccess(
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
} catch (e) {
|
||||
yield Left(AddALabelToAThreadFailure(
|
||||
exception: e,
|
||||
labelDisplay: labelDisplay,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
@@ -15,6 +14,7 @@ import 'package:tmail_ui_user/features/email/presentation/extensions/presentatio
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/exceptions/label_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/add_label_to_email_modal.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/labels/check_label_available_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/extensions/map_keywords_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/extensions/presentation_email_map_extension.dart';
|
||||
@@ -23,8 +23,7 @@ import 'package:tmail_ui_user/main/routes/dialog_router.dart';
|
||||
|
||||
extension HandleLabelForEmailExtension on SingleEmailController {
|
||||
bool get isLabelFeatureEnabled {
|
||||
return mailboxDashBoardController.isLabelCapabilitySupported &&
|
||||
mailboxDashBoardController.labelController.isLabelSettingEnabled.isTrue;
|
||||
return mailboxDashBoardController.isLabelFeatureEnabled;
|
||||
}
|
||||
|
||||
void toggleLabelToEmail(EmailId emailId, Label label, bool isSelected) {
|
||||
@@ -180,8 +179,12 @@ extension HandleLabelForEmailExtension on SingleEmailController {
|
||||
child: AddLabelToEmailModal(
|
||||
labels: labels,
|
||||
emailLabels: emailLabels,
|
||||
emailId: emailId,
|
||||
onAddLabelToEmailCallback: toggleLabelToEmail,
|
||||
emailIds: [emailId],
|
||||
onAddLabelToEmailsCallback: (emailIds, label, isSelected) {
|
||||
if (emailIds.length == 1) {
|
||||
toggleLabelToEmail(emailIds.first, label, isSelected);
|
||||
}
|
||||
},
|
||||
),
|
||||
dialogLabel: 'add-label-to-email-modal',
|
||||
);
|
||||
|
||||
+6
-3
@@ -45,6 +45,7 @@ import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_i
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/print_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/context_item_email_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/email_loaded.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/email_unsubscribe.dart';
|
||||
@@ -588,7 +589,6 @@ class EmailActionReactor {
|
||||
);
|
||||
}).toList();
|
||||
|
||||
|
||||
final popupMenuWidget = PopupMenuActionGroupWidget(
|
||||
actions: popupMenuItemEmailActions,
|
||||
submenuController: submenuController,
|
||||
@@ -623,9 +623,12 @@ class EmailActionReactor {
|
||||
OnSelectLabelAction? onSelectLabelAction,
|
||||
}) {
|
||||
if (actionType == EmailActionType.labelAs && labels?.isNotEmpty == true) {
|
||||
final listLabels = labels ?? [];
|
||||
final emailLabels = presentationEmail.getLabelList(listLabels);
|
||||
|
||||
return LabelListContextMenu(
|
||||
labelList: labels ?? [],
|
||||
presentationEmail: presentationEmail,
|
||||
labelList: listLabels,
|
||||
emailLabels: emailLabels,
|
||||
imagePaths: imagePaths,
|
||||
onSelectLabelAction: (label, isSelected) =>
|
||||
onSelectLabelAction?.call(label, isSelected),
|
||||
|
||||
@@ -12,8 +12,8 @@ import 'package:tmail_ui_user/features/labels/presentation/widgets/label_item_co
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
typedef OnAddLabelToEmailCallback = void Function(
|
||||
EmailId emailId,
|
||||
typedef OnAddLabelToEmailsCallback = void Function(
|
||||
List<EmailId> emailIds,
|
||||
Label label,
|
||||
bool isSelected,
|
||||
);
|
||||
@@ -21,15 +21,15 @@ typedef OnAddLabelToEmailCallback = void Function(
|
||||
class AddLabelToEmailModal extends StatefulWidget {
|
||||
final List<Label> labels;
|
||||
final List<Label> emailLabels;
|
||||
final EmailId emailId;
|
||||
final OnAddLabelToEmailCallback onAddLabelToEmailCallback;
|
||||
final List<EmailId> emailIds;
|
||||
final OnAddLabelToEmailsCallback onAddLabelToEmailsCallback;
|
||||
|
||||
const AddLabelToEmailModal({
|
||||
super.key,
|
||||
required this.labels,
|
||||
required this.emailLabels,
|
||||
required this.emailId,
|
||||
required this.onAddLabelToEmailCallback,
|
||||
required this.emailIds,
|
||||
required this.onAddLabelToEmailsCallback,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -146,7 +146,7 @@ class _AddLabelToEmailModalState extends State<AddLabelToEmailModal> {
|
||||
}
|
||||
|
||||
void _onSelectLabel(Label label, bool isSelected) {
|
||||
widget.onAddLabelToEmailCallback(widget.emailId, label, isSelected);
|
||||
widget.onAddLabelToEmailsCallback(widget.emailIds, label, isSelected);
|
||||
popBack();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/label_item_context_menu.dart';
|
||||
|
||||
class LabelListContextMenu extends StatelessWidget {
|
||||
final PresentationEmail presentationEmail;
|
||||
final List<Label> labelList;
|
||||
final List<Label> emailLabels;
|
||||
final ImagePaths imagePaths;
|
||||
final OnSelectLabelAction onSelectLabelAction;
|
||||
|
||||
const LabelListContextMenu({
|
||||
super.key,
|
||||
required this.labelList,
|
||||
required this.presentationEmail,
|
||||
required this.emailLabels,
|
||||
required this.imagePaths,
|
||||
required this.onSelectLabelAction,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final emailLabels = presentationEmail.getLabelList(labelList);
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: labelList.length,
|
||||
|
||||
@@ -33,6 +33,7 @@ import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/repository/email_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/add_a_label_to_a_thread_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/delete_email_permanently_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/delete_multiple_emails_permanently_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/usecase/download_all_attachments_for_web_interactor.dart';
|
||||
@@ -370,6 +371,7 @@ class MailboxDashBoardBindings extends BaseBindings {
|
||||
Get.find<EmailRepository>(),
|
||||
));
|
||||
Get.lazyPut(() => MarkAsStarMultipleEmailInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => AddALabelToAThreadInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => MoveMultipleEmailToMailboxInteractor(
|
||||
Get.find<EmailRepository>(),
|
||||
));
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
|
||||
extension CheckLabelAvailableExtension on MailboxDashBoardController {
|
||||
bool get isLabelFeatureEnabled {
|
||||
return isLabelCapabilitySupported &&
|
||||
labelController.isLabelSettingEnabled.isTrue;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,13 @@ extension MapKeywordsExtension on Map<KeyWordIdentifier, bool>? {
|
||||
List<KeyWordIdentifier> get enabledKeywords =>
|
||||
this?.entries.where((e) => e.value).map((e) => e.key).toList() ?? [];
|
||||
|
||||
Set<KeyWordIdentifier> get enabledKeywordSet => this == null
|
||||
? const {}
|
||||
: {
|
||||
for (final entry in this!.entries)
|
||||
if (entry.value) entry.key
|
||||
};
|
||||
|
||||
Map<KeyWordIdentifier, bool> withKeyword(KeyWordIdentifier keyword) {
|
||||
return Map<KeyWordIdentifier, bool>.from(this ?? {})..[keyword] = true;
|
||||
}
|
||||
|
||||
@@ -16,4 +16,21 @@ extension PresentationEmailMapExtension on Map<EmailId, PresentationEmail?> {
|
||||
}
|
||||
return newMap;
|
||||
}
|
||||
|
||||
Map<EmailId, PresentationEmail?> toggleListEmailsKeywordByIds({
|
||||
required List<EmailId> emailIds,
|
||||
required KeyWordIdentifier keyword,
|
||||
required bool remove,
|
||||
}) {
|
||||
final updatedMap = Map<EmailId, PresentationEmail?>.from(this);
|
||||
|
||||
for (final emailId in emailIds) {
|
||||
final email = updatedMap[emailId];
|
||||
if (email == null) continue;
|
||||
|
||||
updatedMap[emailId] = email.toggleKeyword(keyword, remove);
|
||||
}
|
||||
|
||||
return updatedMap;
|
||||
}
|
||||
}
|
||||
|
||||
+49
-2
@@ -1,9 +1,12 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/extensions/map_keywords_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/extensions/email_in_thread_detail_info_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/model/email_in_thread_detail_info.dart';
|
||||
|
||||
extension ListEmailInThreadDetailInfoExtension on List<EmailInThreadDetailInfo> {
|
||||
extension ListEmailInThreadDetailInfoExtension
|
||||
on List<EmailInThreadDetailInfo> {
|
||||
List<EmailId> emailIdsToDisplay(bool isSentMailbox) => isSentMailbox
|
||||
? map((email) => email.emailId).toList()
|
||||
: where((email) => email.isValidToDisplay)
|
||||
@@ -22,4 +25,48 @@ extension ListEmailInThreadDetailInfoExtension on List<EmailInThreadDetailInfo>
|
||||
return emailInfo.toggleKeyword(keyword, remove);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
List<EmailInThreadDetailInfo> toggleListEmailsKeywordByIds({
|
||||
required List<EmailId> emailIds,
|
||||
required KeyWordIdentifier keyword,
|
||||
required bool remove,
|
||||
}) {
|
||||
final targetIds = emailIds.toSet();
|
||||
|
||||
return map((emailInfo) {
|
||||
if (!targetIds.contains(emailInfo.emailId)) {
|
||||
return emailInfo;
|
||||
}
|
||||
|
||||
return emailInfo.toggleKeyword(keyword, remove);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Label> findCommonLabelsInThread({
|
||||
required List<Label> labels,
|
||||
}) {
|
||||
if (isEmpty || labels.isEmpty) return const [];
|
||||
|
||||
final iterator = where((e) => e.isValidToDisplay).iterator;
|
||||
if (!iterator.moveNext()) return const [];
|
||||
|
||||
// Initialize with the first valid email
|
||||
var commonKeywords = iterator.current.keywords.enabledKeywordSet;
|
||||
|
||||
if (commonKeywords.isEmpty) return const [];
|
||||
|
||||
// Intersect with remaining emails
|
||||
while (iterator.moveNext()) {
|
||||
commonKeywords = commonKeywords.intersection(
|
||||
iterator.current.keywords.enabledKeywordSet,
|
||||
);
|
||||
|
||||
if (commonKeywords.isEmpty) return const [];
|
||||
}
|
||||
|
||||
return labels
|
||||
.where((label) =>
|
||||
label.keyword != null && commonKeywords.contains(label.keyword))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:labels/labels.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_thread_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/email_loaded_extension.dart';
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/exceptions/label_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/add_label_to_email_modal.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/labels/check_label_available_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/extensions/presentation_email_map_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/extensions/list_email_in_thread_detail_info_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
||||
import 'package:tmail_ui_user/main/routes/dialog_router.dart';
|
||||
|
||||
extension AddLabelToThreadExtension on ThreadDetailController {
|
||||
Future<void> openAddLabelToEmailDialogModal() async {
|
||||
if (!mailboxDashBoardController.isLabelFeatureEnabled) return;
|
||||
|
||||
final labels = mailboxDashBoardController.labelController.labels;
|
||||
if (emailsInThreadDetailInfo.isEmpty || labels.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
final threadLabels =
|
||||
emailsInThreadDetailInfo.findCommonLabelsInThread(labels: labels);
|
||||
|
||||
final emailIds = emailsInThreadDetailInfo.emailIdsToDisplay(true);
|
||||
|
||||
await DialogRouter().openDialogModal(
|
||||
child: AddLabelToEmailModal(
|
||||
labels: labels,
|
||||
emailLabels: threadLabels,
|
||||
emailIds: emailIds,
|
||||
onAddLabelToEmailsCallback: (emailIds, label, isSelected) {
|
||||
toggleLabelToThread(label, isSelected, currentEmailIds: emailIds);
|
||||
},
|
||||
),
|
||||
dialogLabel: 'add-label-to-thread-modal',
|
||||
);
|
||||
}
|
||||
|
||||
void toggleLabelToThread(
|
||||
Label label,
|
||||
bool isSelected, {
|
||||
List<EmailId>? currentEmailIds,
|
||||
}) {
|
||||
if (isSelected) {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
final session = mailboxDashBoardController.sessionCurrent;
|
||||
final emailIds =
|
||||
currentEmailIds ?? emailsInThreadDetailInfo.emailIdsToDisplay(true);
|
||||
|
||||
_addALabelToAThread(
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
emailIds: emailIds,
|
||||
label: label,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _addALabelToAThread({
|
||||
required Session? session,
|
||||
required AccountId? accountId,
|
||||
required Label label,
|
||||
required List<EmailId> emailIds,
|
||||
}) {
|
||||
final labelDisplay = label.safeDisplayName;
|
||||
|
||||
if (session == null) {
|
||||
consumeState(
|
||||
Stream.value(
|
||||
Left(AddALabelToAThreadFailure(
|
||||
exception: NotFoundSessionException(),
|
||||
labelDisplay: labelDisplay,
|
||||
)),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountId == null) {
|
||||
consumeState(
|
||||
Stream.value(
|
||||
Left(AddALabelToAThreadFailure(
|
||||
exception: NotFoundAccountIdException(),
|
||||
labelDisplay: labelDisplay,
|
||||
)),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final labelKeyword = label.keyword;
|
||||
if (labelKeyword == null) {
|
||||
consumeState(
|
||||
Stream.value(Left(
|
||||
AddALabelToAThreadFailure(
|
||||
exception: LabelKeywordIsNull(),
|
||||
labelDisplay: labelDisplay,
|
||||
),
|
||||
)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
consumeState(addALabelToAThreadInteractor.execute(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
label.safeDisplayName,
|
||||
));
|
||||
}
|
||||
|
||||
void handleAddLabelToThreadSuccess(AddALabelToAThreadSuccess success) {
|
||||
toastManager.showMessageSuccess(success);
|
||||
|
||||
_autoSyncLabelToThreadOnMemory(
|
||||
emailIds: success.emailIds,
|
||||
labelKeyword: success.labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
void handleAddLabelToThreadFailure(AddALabelToAThreadFailure failure) {
|
||||
toastManager.showMessageFailure(failure);
|
||||
}
|
||||
|
||||
void _autoSyncLabelToThreadOnMemory({
|
||||
required List<EmailId> emailIds,
|
||||
required KeyWordIdentifier labelKeyword,
|
||||
}) {
|
||||
_updateLabelInThreadOnMemory(
|
||||
emailIds: emailIds,
|
||||
labelKeyword: labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
void _updateLabelInThreadOnMemory({
|
||||
required List<EmailId> emailIds,
|
||||
required KeyWordIdentifier labelKeyword,
|
||||
}) {
|
||||
emailIdsPresentation.value =
|
||||
emailIdsPresentation.toggleListEmailsKeywordByIds(
|
||||
emailIds: emailIds,
|
||||
keyword: labelKeyword,
|
||||
remove: false,
|
||||
);
|
||||
|
||||
emailsInThreadDetailInfo.value =
|
||||
emailsInThreadDetailInfo.toggleListEmailsKeywordByIds(
|
||||
emailIds: emailIds,
|
||||
keyword: labelKeyword,
|
||||
remove: false,
|
||||
);
|
||||
|
||||
final emailLoaded = currentEmailLoaded.value;
|
||||
final emailLoadedId = emailLoaded?.emailCurrent?.id;
|
||||
if (emailLoaded != null &&
|
||||
emailLoadedId != null &&
|
||||
emailIds.contains(emailLoadedId)) {
|
||||
currentEmailLoaded.value = emailLoaded.toggleEmailKeyword(
|
||||
emailId: emailLoadedId,
|
||||
keyword: labelKeyword,
|
||||
remove: false,
|
||||
);
|
||||
}
|
||||
|
||||
mailboxDashBoardController.updateEmailFlagByEmailIds(
|
||||
emailIds,
|
||||
isLabelAdded: true,
|
||||
labelKeyword: labelKeyword,
|
||||
);
|
||||
|
||||
mailboxDashBoardController.labelController.isLabelSettingEnabled.refresh();
|
||||
}
|
||||
}
|
||||
+63
-1
@@ -1,23 +1,32 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/read_actions.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/popup_menu/popup_menu_action_group_widget.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/popup_menu/popup_submenu_controller.dart';
|
||||
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/context_item_email_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/popup_menu_item_email_action.dart';
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/label_item_context_menu.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/label_list_context_menu.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/handle_open_context_menu_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/labels/check_label_available_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_email_read_state.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/state/mark_as_star_multiple_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/extensions/list_email_in_thread_detail_info_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/model/email_in_thread_detail_info.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/close_thread_detail_action.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/get_thread_detail_action_status.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/labels/add_label_to_thread_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/parsing_email_opened_properties_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
@@ -115,6 +124,10 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
|
||||
_moveToMailbox(mailboxId, threadDetailActionType);
|
||||
break;
|
||||
case EmailActionType.labelAs:
|
||||
if (!mailboxDashBoardController.isLabelFeatureEnabled) return;
|
||||
openAddLabelToEmailDialogModal();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -124,6 +137,8 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
if (currentContext == null) return;
|
||||
|
||||
final moreActions = [
|
||||
if (mailboxDashBoardController.isLabelFeatureEnabled)
|
||||
EmailActionType.labelAs,
|
||||
threadDetailIsRead
|
||||
? EmailActionType.markAsUnread
|
||||
: EmailActionType.markAsRead,
|
||||
@@ -158,6 +173,8 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
useGroupedActions: true,
|
||||
);
|
||||
} else {
|
||||
final submenuController = PopupSubmenuController();
|
||||
|
||||
final popupMenuItemEmailActions = moreActions.map((actionType) {
|
||||
return PopupMenuItemEmailAction(
|
||||
actionType,
|
||||
@@ -165,13 +182,27 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
imagePaths,
|
||||
key: '${actionType.name}_action',
|
||||
category: actionType.category,
|
||||
submenu: _getEmailActionSubmenu(
|
||||
actionType: actionType,
|
||||
imagePaths: imagePaths,
|
||||
emailInThreadDetailInfos: emailsInThreadDetailInfo,
|
||||
labels: mailboxDashBoardController.labelController.labels,
|
||||
onSelectLabelAction: (label, isSelected) {
|
||||
toggleLabelToThread(label, isSelected);
|
||||
submenuController.hide();
|
||||
popBack();
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
final popupMenuWidget = PopupMenuActionGroupWidget(
|
||||
actions: popupMenuItemEmailActions,
|
||||
submenuController: submenuController,
|
||||
onActionSelected: (action) {
|
||||
onThreadDetailActionClick(action.action);
|
||||
if (_shouldHandleAction(action.action)) {
|
||||
onThreadDetailActionClick(action.action);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -179,8 +210,39 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
currentContext!,
|
||||
position,
|
||||
popupMenuWidget,
|
||||
).whenComplete(submenuController.hide);
|
||||
}
|
||||
}
|
||||
|
||||
bool _shouldHandleAction(EmailActionType action) {
|
||||
if (action != EmailActionType.labelAs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return PlatformInfo.isWebTouchDevice || PlatformInfo.isMobile;
|
||||
}
|
||||
|
||||
Widget? _getEmailActionSubmenu({
|
||||
required EmailActionType actionType,
|
||||
required ImagePaths imagePaths,
|
||||
required List<EmailInThreadDetailInfo> emailInThreadDetailInfos,
|
||||
required List<Label>? labels,
|
||||
OnSelectLabelAction? onSelectLabelAction,
|
||||
}) {
|
||||
if (actionType == EmailActionType.labelAs && labels?.isNotEmpty == true) {
|
||||
final listLabels = labels ?? [];
|
||||
final threadLabels =
|
||||
emailInThreadDetailInfos.findCommonLabelsInThread(labels: listLabels);
|
||||
|
||||
return LabelListContextMenu(
|
||||
labelList: listLabels,
|
||||
emailLabels: threadLabels,
|
||||
imagePaths: imagePaths,
|
||||
onSelectLabelAction: (label, isSelected) =>
|
||||
onSelectLabelAction?.call(label, isSelected),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _moveToMailbox(MailboxId mailboxId, EmailActionType emailActionType) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:core/data/model/source_type/data_source_type.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/http/http_client.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/add_a_label_to_a_thread_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
@@ -45,6 +46,7 @@ class ThreadDetailBindings extends BaseBindings {
|
||||
Get.find<GetEmailContentInteractor>(),
|
||||
Get.find<MarkAsStarMultipleEmailInteractor>(),
|
||||
Get.find<MarkAsMultipleEmailReadInteractor>(),
|
||||
Get.find<AddALabelToAThreadInteractor>(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@ import 'package:model/email/presentation_email.dart';
|
||||
import 'package:model/extensions/keyword_identifier_extension.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_thread_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/print_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/add_a_label_to_a_thread_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
@@ -49,6 +51,7 @@ import 'package:tmail_ui_user/features/thread_detail/presentation/extension/hand
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/handle_mail_shortcut_actions_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/handle_refresh_thread_detail_action.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/initialize_thread_detail_emails.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/labels/add_label_to_thread_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/mark_collapsed_email_unread_success.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/quick_create_rule_from_collapsed_email_success.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/thread_detail_on_selected_email_updated.dart';
|
||||
@@ -66,6 +69,7 @@ class ThreadDetailController extends BaseController {
|
||||
final GetEmailContentInteractor _getEmailContentInteractor;
|
||||
final MarkAsStarMultipleEmailInteractor markAsStarMultipleEmailInteractor;
|
||||
final MarkAsMultipleEmailReadInteractor markAsMultipleEmailReadInteractor;
|
||||
final AddALabelToAThreadInteractor addALabelToAThreadInteractor;
|
||||
|
||||
ThreadDetailController(
|
||||
this._getEmailIdsByThreadIdInteractor,
|
||||
@@ -76,6 +80,7 @@ class ThreadDetailController extends BaseController {
|
||||
this._getEmailContentInteractor,
|
||||
this.markAsStarMultipleEmailInteractor,
|
||||
this.markAsMultipleEmailReadInteractor,
|
||||
this.addALabelToAThreadInteractor,
|
||||
);
|
||||
|
||||
final emailIdsPresentation = <EmailId, PresentationEmail?>{}.obs;
|
||||
@@ -260,6 +265,8 @@ class ThreadDetailController extends BaseController {
|
||||
);
|
||||
} else if (success is CreateNewRuleFilterSuccess) {
|
||||
quickCreateRuleFromCollapsedEmailSuccess(success);
|
||||
} else if (success is AddALabelToAThreadSuccess) {
|
||||
handleAddLabelToThreadSuccess(success);
|
||||
} else {
|
||||
super.handleSuccessViewState(success);
|
||||
}
|
||||
@@ -269,26 +276,24 @@ class ThreadDetailController extends BaseController {
|
||||
void handleFailureViewState(failure) {
|
||||
if (failure is GetThreadByIdFailure) {
|
||||
handleGetThreadByIdFailure(failure);
|
||||
}
|
||||
if (failure is GetEmailsByIdsFailure) {
|
||||
} else if (failure is GetEmailsByIdsFailure) {
|
||||
if (failure.updateCurrentThreadDetail) return;
|
||||
showRetryToast(failure);
|
||||
return;
|
||||
}
|
||||
if (failure is PrintEmailFailure) {
|
||||
} else if (failure is PrintEmailFailure) {
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).unknownError,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (failure is MarkAsMultipleEmailReadFailure ||
|
||||
} else if (failure is MarkAsMultipleEmailReadFailure ||
|
||||
failure is MarkAsStarMultipleEmailFailure) {
|
||||
toastManager.showMessageFailure(failure as FeatureFailure);
|
||||
} else if (failure is AddALabelToAThreadFailure) {
|
||||
handleAddLabelToThreadFailure(failure);
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -4880,6 +4880,24 @@
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"aiScribe": "AI Scribe",
|
||||
"@aiScribe": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"aiScribeSettingExplanation": "Use AI to help write and improve your emails",
|
||||
"@aiScribeSettingExplanation": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"aiScribeToggleDescription": "Enable AI Scribe",
|
||||
"@aiScribeToggleDescription": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"showMoreAttachmentButton": "Show +{count} more",
|
||||
"@showMoreAttachmentButton": {
|
||||
"type": "text",
|
||||
@@ -5321,5 +5339,25 @@
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"addLabelToThreadSuccessfullyMessage": "All emails in thread added to the \"{labelName}\" label",
|
||||
"@addLabelToThreadSuccessfullyMessage": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"labelName"
|
||||
],
|
||||
"placeholders": {
|
||||
"labelName": {}
|
||||
}
|
||||
},
|
||||
"addLabelToThreadFailureMessage": "Cannot add all emails in thread to the \"{labelName}\" label",
|
||||
"@addLabelToThreadFailureMessage": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"labelName"
|
||||
],
|
||||
"placeholders": {
|
||||
"labelName": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5649,4 +5649,21 @@ class AppLocalizations {
|
||||
name: 'addLabel',
|
||||
);
|
||||
}
|
||||
|
||||
String addLabelToThreadSuccessfullyMessage(String labelName) {
|
||||
return Intl.message(
|
||||
'All emails in thread added to the "$labelName" label',
|
||||
name: 'addLabelToThreadSuccessfullyMessage',
|
||||
args: [labelName],
|
||||
);
|
||||
}
|
||||
|
||||
String addLabelToThreadFailureMessage(String labelName) {
|
||||
return Intl.message(
|
||||
'Cannot add all emails in thread to the "$labelName" label',
|
||||
name: 'addLabelToThreadFailureMessage',
|
||||
args: [labelName],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exc
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_thread_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reply_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/state/parse_email_by_blob_id_state.dart';
|
||||
@@ -205,6 +206,9 @@ class ToastManager {
|
||||
} else if (failure is AddALabelToAnEmailFailure) {
|
||||
message = message ??
|
||||
appLocalizations.addLabelToEmailFailureMessage(failure.labelDisplay);
|
||||
} else if (failure is AddALabelToAThreadFailure) {
|
||||
message = message ??
|
||||
appLocalizations.addLabelToThreadFailureMessage(failure.labelDisplay);
|
||||
}
|
||||
log('ToastManager::showMessageFailure: Message: $message');
|
||||
if (message?.trim().isNotEmpty == true) {
|
||||
@@ -276,6 +280,10 @@ class ToastManager {
|
||||
message = appLocalizations.addLabelToEmailSuccessfullyMessage(
|
||||
success.labelDisplay,
|
||||
);
|
||||
} else if (success is AddALabelToAThreadSuccess) {
|
||||
message = appLocalizations.addLabelToThreadSuccessfullyMessage(
|
||||
success.labelDisplay,
|
||||
);
|
||||
}
|
||||
log('ToastManager::showMessageSuccess: Message: $message');
|
||||
if (message?.trim().isNotEmpty == true) {
|
||||
|
||||
@@ -50,4 +50,13 @@ extension ListEmailIdExtension on List<EmailId> {
|
||||
emailId.id: KeyWordIdentifier.emailForwarded.generateForwardedActionPath()
|
||||
};
|
||||
}
|
||||
|
||||
Map<Id, PatchObject> generateMapUpdateObjectLabel(
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return {
|
||||
for (var emailId in this)
|
||||
emailId.id: labelKeyword.generateLabelActionPath()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ export 'scribe/ai/presentation/model/text_selection_model.dart';
|
||||
export 'scribe/ai/presentation/styles/ai_scribe_styles.dart';
|
||||
export 'scribe/ai/presentation/utils/ai_scribe_constants.dart';
|
||||
export 'scribe/ai/presentation/utils/context_menu/hover_submenu_controller.dart';
|
||||
export 'scribe/ai/presentation/utils/context_menu/popup_submenu_controller.dart';
|
||||
export 'scribe/ai/presentation/utils/context_menu/context_submenu_controller.dart';
|
||||
export 'scribe/ai/presentation/utils/modal/ai_scribe_modal_manager.dart';
|
||||
export 'scribe/ai/presentation/utils/modal/anchored_modal_layout_calculator.dart';
|
||||
export 'scribe/ai/presentation/widgets/button/ai_assistant_button.dart';
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
enum SubmenuDirection { left, right, auto }
|
||||
|
||||
class PopupSubmenuController {
|
||||
class ContextSubmenuController {
|
||||
OverlayEntry? _submenuEntry;
|
||||
|
||||
bool get isShowing => _submenuEntry != null;
|
||||
@@ -16,7 +16,7 @@ class AiScribeModalManager {
|
||||
ModalPlacement? preferredPlacement,
|
||||
ModalCrossAxisAlignment crossAxisAlignment = ModalCrossAxisAlignment.center,
|
||||
}) async {
|
||||
final PopupSubmenuController submenuController = PopupSubmenuController();
|
||||
final ContextSubmenuController submenuController = ContextSubmenuController();
|
||||
|
||||
final aiAction = await Get.dialog<AIAction>(
|
||||
AiScribeModalWidget(
|
||||
|
||||
@@ -6,7 +6,7 @@ class AiScribeContextMenu extends StatefulWidget {
|
||||
final ImagePaths imagePaths;
|
||||
final List<AiScribeContextMenuAction> menuActions;
|
||||
final ValueChanged<AiScribeContextMenuAction> onActionSelected;
|
||||
final PopupSubmenuController? submenuController;
|
||||
final ContextSubmenuController? submenuController;
|
||||
|
||||
const AiScribeContextMenu({
|
||||
super.key,
|
||||
|
||||
@@ -13,7 +13,7 @@ class AiScribeModalWidget extends StatelessWidget {
|
||||
final Size? buttonSize;
|
||||
final ModalPlacement? preferredPlacement;
|
||||
final ModalCrossAxisAlignment crossAxisAlignment;
|
||||
final PopupSubmenuController? submenuController;
|
||||
final ContextSubmenuController? submenuController;
|
||||
|
||||
const AiScribeModalWidget({
|
||||
super.key,
|
||||
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/extensions/list_email_in_thread_detail_info_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/model/email_in_thread_detail_info.dart';
|
||||
|
||||
void main() {
|
||||
group(
|
||||
'ListEmailInThreadDetailInfoExtension.findCommonLabelsInThread',
|
||||
() {
|
||||
final seen = KeyWordIdentifier.emailSeen;
|
||||
final flagged = KeyWordIdentifier.emailFlagged;
|
||||
final answered = KeyWordIdentifier.emailAnswered;
|
||||
|
||||
Label label(KeyWordIdentifier keyword) => Label(
|
||||
keyword: keyword,
|
||||
displayName: keyword.value,
|
||||
);
|
||||
|
||||
EmailInThreadDetailInfo email({
|
||||
required Map<KeyWordIdentifier, bool>? keywords,
|
||||
bool isValidToDisplay = true,
|
||||
}) {
|
||||
return EmailInThreadDetailInfo(
|
||||
emailId: EmailId(Id('email-${keywords.hashCode}')),
|
||||
keywords: keywords,
|
||||
mailboxIds: {MailboxId(Id('inbox')): true},
|
||||
isValidToDisplay: isValidToDisplay,
|
||||
);
|
||||
}
|
||||
|
||||
test(
|
||||
'returns empty list when email list is empty',
|
||||
() {
|
||||
final result = <EmailInThreadDetailInfo>[].findCommonLabelsInThread(
|
||||
labels: [label(seen)],
|
||||
);
|
||||
|
||||
expect(result, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'returns empty list when labels list is empty',
|
||||
() {
|
||||
final emails = [
|
||||
email(keywords: {seen: true}),
|
||||
];
|
||||
|
||||
final result = emails.findCommonLabelsInThread(labels: []);
|
||||
|
||||
expect(result, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'returns only labels whose keyword appears in all valid emails',
|
||||
() {
|
||||
final emails = [
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
flagged: true,
|
||||
},
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
flagged: false,
|
||||
},
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
final labels = [
|
||||
label(seen),
|
||||
label(flagged),
|
||||
label(answered),
|
||||
];
|
||||
|
||||
final result = emails.findCommonLabelsInThread(labels: labels);
|
||||
|
||||
expect(
|
||||
result.map((l) => l.keyword),
|
||||
equals([seen]),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'ignores emails that are not valid to display',
|
||||
() {
|
||||
final emails = [
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
flagged: true,
|
||||
},
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
flagged: true,
|
||||
},
|
||||
isValidToDisplay: false,
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
final labels = [
|
||||
label(seen),
|
||||
label(flagged),
|
||||
];
|
||||
|
||||
final result = emails.findCommonLabelsInThread(labels: labels);
|
||||
|
||||
expect(
|
||||
result.map((l) => l.keyword),
|
||||
equals([seen]),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'returns empty list when no common keyword exists',
|
||||
() {
|
||||
final emails = [
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
},
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
flagged: true,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
final labels = [
|
||||
label(seen),
|
||||
label(flagged),
|
||||
];
|
||||
|
||||
final result = emails.findCommonLabelsInThread(labels: labels);
|
||||
|
||||
expect(result, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'returns empty list when first valid email has no enabled keywords',
|
||||
() {
|
||||
final emails = [
|
||||
email(
|
||||
keywords: {
|
||||
seen: false,
|
||||
flagged: false,
|
||||
},
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
final labels = [
|
||||
label(seen),
|
||||
label(flagged),
|
||||
];
|
||||
|
||||
final result = emails.findCommonLabelsInThread(labels: labels);
|
||||
|
||||
expect(result, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'ignores labels with null keyword',
|
||||
() {
|
||||
final emails = [
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
},
|
||||
),
|
||||
email(
|
||||
keywords: {
|
||||
seen: true,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
final labels = [
|
||||
Label(displayName: 'No keyword'),
|
||||
label(seen),
|
||||
];
|
||||
|
||||
final result = emails.findCommonLabelsInThread(labels: labels);
|
||||
|
||||
expect(result.length, 1);
|
||||
expect(result.first.keyword, seen);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user