TF-4195 Add Label to Thread
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user