TW-4308 Add labels for several messages part 2 (#4431)
Add ChooseLabelModal, delegate, and update label UI components Wire add-labels action across Thread, Search, and Dashboard
This commit is contained in:
@@ -3,21 +3,29 @@ 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';
|
||||
|
||||
typedef OnSyncListLabelForListEmail = void Function(
|
||||
List<EmailId> emailIds,
|
||||
List<KeyWordIdentifier> labelKeywords,
|
||||
{bool shouldRemove}
|
||||
);
|
||||
|
||||
class AddingListLabelsToListEmails extends LoadingState {}
|
||||
|
||||
class AddListLabelsToListEmailsSuccess extends UIState {
|
||||
final List<EmailId> emailIds;
|
||||
final List<KeyWordIdentifier> labelKeywords;
|
||||
final List<String> labelDisplays;
|
||||
final OnSyncListLabelForListEmail? onSync;
|
||||
|
||||
AddListLabelsToListEmailsSuccess(
|
||||
this.emailIds,
|
||||
this.labelKeywords,
|
||||
this.labelDisplays,
|
||||
);
|
||||
this.labelDisplays, {
|
||||
this.onSync,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [emailIds, labelKeywords, labelDisplays];
|
||||
List<Object?> get props => [emailIds, labelKeywords, labelDisplays];
|
||||
}
|
||||
|
||||
class AddListLabelsToListEmailsHasSomeFailure
|
||||
@@ -25,11 +33,12 @@ class AddListLabelsToListEmailsHasSomeFailure
|
||||
AddListLabelsToListEmailsHasSomeFailure(
|
||||
super.emailIds,
|
||||
super.labelKeywords,
|
||||
super.labelDisplays,
|
||||
);
|
||||
super.labelDisplays, {
|
||||
super.onSync,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [...super.props, 'hasSomeFailure'];
|
||||
List<Object?> get props => [...super.props, 'hasSomeFailure'];
|
||||
}
|
||||
|
||||
class AddListLabelsToListEmailsFailure extends FeatureFailure {
|
||||
|
||||
+15
-16
@@ -3,12 +3,11 @@ 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/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/labels/add_list_label_to_list_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/model/add_list_labels_to_list_emails_params.dart';
|
||||
|
||||
class AddListLabelToListEmailsInteractor {
|
||||
final EmailRepository _emailRepository;
|
||||
@@ -18,15 +17,13 @@ class AddListLabelToListEmailsInteractor {
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
List<KeyWordIdentifier> labelKeywords,
|
||||
List<String> labelDisplays,
|
||||
AddListLabelsToListEmailsParams params,
|
||||
) async* {
|
||||
try {
|
||||
if (emailIds.isEmpty) {
|
||||
if (params.emailIds.isEmpty) {
|
||||
yield Left(AddListLabelsToListEmailsFailure(
|
||||
exception: EmailIdsSuccessIsEmptyException(),
|
||||
labelDisplays: labelDisplays,
|
||||
labelDisplays: params.labelDisplays,
|
||||
));
|
||||
return;
|
||||
}
|
||||
@@ -34,33 +31,35 @@ class AddListLabelToListEmailsInteractor {
|
||||
final result = await _emailRepository.addListLabelToListEmail(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeywords,
|
||||
params.emailIds,
|
||||
params.labelKeywords,
|
||||
);
|
||||
if (emailIds.length == result.emailIdsSuccess.length) {
|
||||
if (params.emailIds.length == result.emailIdsSuccess.length) {
|
||||
yield Right(AddListLabelsToListEmailsSuccess(
|
||||
result.emailIdsSuccess,
|
||||
labelKeywords,
|
||||
labelDisplays,
|
||||
params.labelKeywords,
|
||||
params.labelDisplays,
|
||||
onSync: params.onSync,
|
||||
));
|
||||
} else if (result.emailIdsSuccess.isEmpty) {
|
||||
yield Left(AddListLabelsToListEmailsFailure(
|
||||
exception: result.mapErrors.isNotEmpty
|
||||
? SetMethodException(result.mapErrors)
|
||||
: EmailIdsSuccessIsEmptyException(),
|
||||
labelDisplays: labelDisplays,
|
||||
labelDisplays: params.labelDisplays,
|
||||
));
|
||||
} else {
|
||||
yield Right(AddListLabelsToListEmailsHasSomeFailure(
|
||||
result.emailIdsSuccess,
|
||||
labelKeywords,
|
||||
labelDisplays,
|
||||
params.labelKeywords,
|
||||
params.labelDisplays,
|
||||
onSync: params.onSync,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left(AddListLabelsToListEmailsFailure(
|
||||
exception: e,
|
||||
labelDisplays: labelDisplays,
|
||||
labelDisplays: params.labelDisplays,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user