TF-4308 add domain state, interactor, model extensions, and localization
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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 AddingListLabelsToListEmails extends LoadingState {}
|
||||
|
||||
class AddListLabelsToListEmailsSuccess extends UIState {
|
||||
final List<EmailId> emailIds;
|
||||
final List<KeyWordIdentifier> labelKeywords;
|
||||
final List<String> labelDisplays;
|
||||
|
||||
AddListLabelsToListEmailsSuccess(
|
||||
this.emailIds,
|
||||
this.labelKeywords,
|
||||
this.labelDisplays,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object> get props => [emailIds, labelKeywords, labelDisplays];
|
||||
}
|
||||
|
||||
class AddListLabelsToListEmailsHasSomeFailure
|
||||
extends AddListLabelsToListEmailsSuccess {
|
||||
AddListLabelsToListEmailsHasSomeFailure(
|
||||
super.emailIds,
|
||||
super.labelKeywords,
|
||||
super.labelDisplays,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object> get props => [...super.props, 'hasSomeFailure'];
|
||||
}
|
||||
|
||||
class AddListLabelsToListEmailsFailure extends FeatureFailure {
|
||||
final List<String> labelDisplays;
|
||||
|
||||
AddListLabelsToListEmailsFailure({
|
||||
dynamic exception,
|
||||
required this.labelDisplays,
|
||||
}) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [...super.props, labelDisplays];
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
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/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';
|
||||
|
||||
class AddListLabelToListEmailsInteractor {
|
||||
final EmailRepository _emailRepository;
|
||||
|
||||
AddListLabelToListEmailsInteractor(this._emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
List<KeyWordIdentifier> labelKeywords,
|
||||
List<String> labelDisplays,
|
||||
) async* {
|
||||
try {
|
||||
if (emailIds.isEmpty) {
|
||||
yield Left(AddListLabelsToListEmailsFailure(
|
||||
exception: EmailIdsSuccessIsEmptyException(),
|
||||
labelDisplays: labelDisplays,
|
||||
));
|
||||
return;
|
||||
}
|
||||
yield Right(AddingListLabelsToListEmails());
|
||||
final result = await _emailRepository.addListLabelToListEmail(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeywords,
|
||||
);
|
||||
if (emailIds.length == result.emailIdsSuccess.length) {
|
||||
yield Right(AddListLabelsToListEmailsSuccess(
|
||||
result.emailIdsSuccess,
|
||||
labelKeywords,
|
||||
labelDisplays,
|
||||
));
|
||||
} else if (result.emailIdsSuccess.isEmpty) {
|
||||
yield Left(AddListLabelsToListEmailsFailure(
|
||||
exception: result.mapErrors.isNotEmpty
|
||||
? SetMethodException(result.mapErrors)
|
||||
: EmailIdsSuccessIsEmptyException(),
|
||||
labelDisplays: labelDisplays,
|
||||
));
|
||||
} else {
|
||||
yield Right(AddListLabelsToListEmailsHasSomeFailure(
|
||||
result.emailIdsSuccess,
|
||||
labelKeywords,
|
||||
labelDisplays,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left(AddListLabelsToListEmailsFailure(
|
||||
exception: e,
|
||||
labelDisplays: labelDisplays,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ extension EmailSelectionActionTypeExtension on EmailSelectionActionType {
|
||||
case EmailSelectionActionType.selectAll:
|
||||
case EmailSelectionActionType.moreAction:
|
||||
return null;
|
||||
case EmailSelectionActionType.labelAs:
|
||||
return EmailActionType.labelAs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ enum EmailSelectionActionType {
|
||||
markAsStarred,
|
||||
unMarkAsStarred,
|
||||
moveToFolder,
|
||||
labelAs,
|
||||
moveToTrash,
|
||||
markAsSpam,
|
||||
markAsNotSpam,
|
||||
@@ -43,6 +44,8 @@ enum EmailSelectionActionType {
|
||||
return appLocalizations.delete_permanently;
|
||||
case EmailSelectionActionType.moreAction:
|
||||
return appLocalizations.more;
|
||||
case EmailSelectionActionType.labelAs:
|
||||
return appLocalizations.labelAs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +74,8 @@ enum EmailSelectionActionType {
|
||||
return imagePaths.icMailboxArchived;
|
||||
case EmailSelectionActionType.moreAction:
|
||||
return imagePaths.icMoreVertical;
|
||||
case EmailSelectionActionType.labelAs:
|
||||
return imagePaths.icTag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user