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.selectAll:
|
||||||
case EmailSelectionActionType.moreAction:
|
case EmailSelectionActionType.moreAction:
|
||||||
return null;
|
return null;
|
||||||
|
case EmailSelectionActionType.labelAs:
|
||||||
|
return EmailActionType.labelAs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ enum EmailSelectionActionType {
|
|||||||
markAsStarred,
|
markAsStarred,
|
||||||
unMarkAsStarred,
|
unMarkAsStarred,
|
||||||
moveToFolder,
|
moveToFolder,
|
||||||
|
labelAs,
|
||||||
moveToTrash,
|
moveToTrash,
|
||||||
markAsSpam,
|
markAsSpam,
|
||||||
markAsNotSpam,
|
markAsNotSpam,
|
||||||
@@ -43,6 +44,8 @@ enum EmailSelectionActionType {
|
|||||||
return appLocalizations.delete_permanently;
|
return appLocalizations.delete_permanently;
|
||||||
case EmailSelectionActionType.moreAction:
|
case EmailSelectionActionType.moreAction:
|
||||||
return appLocalizations.more;
|
return appLocalizations.more;
|
||||||
|
case EmailSelectionActionType.labelAs:
|
||||||
|
return appLocalizations.labelAs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +74,8 @@ enum EmailSelectionActionType {
|
|||||||
return imagePaths.icMailboxArchived;
|
return imagePaths.icMailboxArchived;
|
||||||
case EmailSelectionActionType.moreAction:
|
case EmailSelectionActionType.moreAction:
|
||||||
return imagePaths.icMoreVertical;
|
return imagePaths.icMoreVertical;
|
||||||
|
case EmailSelectionActionType.labelAs:
|
||||||
|
return imagePaths.icTag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5483,5 +5483,35 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"placeholders_order": [],
|
"placeholders_order": [],
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"chooseLabel": "Choose label",
|
||||||
|
"@chooseLabel": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"selectLabel": "Select label",
|
||||||
|
"@selectLabel": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"addListLabelToListEmailSuccessfullyMessage": "Labels have been successfully added to these emails.",
|
||||||
|
"@addListLabelToListEmailSuccessfullyMessage": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"addListLabelToListEmailHasSomeFailureMessage": "Labels have been successfully added to some emails.",
|
||||||
|
"@addListLabelToListEmailHasSomeFailureMessage": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"addListLabelToListEmailFailureMessage": "Adding labels to these emails failed",
|
||||||
|
"@addListLabelToListEmailFailureMessage": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5804,4 +5804,39 @@ class AppLocalizations {
|
|||||||
name: 'allEmailTrashAndSpam',
|
name: 'allEmailTrashAndSpam',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get chooseLabel {
|
||||||
|
return Intl.message(
|
||||||
|
'Choose label',
|
||||||
|
name: 'chooseLabel',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get selectLabel {
|
||||||
|
return Intl.message(
|
||||||
|
'Select label',
|
||||||
|
name: 'selectLabel',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get addListLabelToListEmailSuccessfullyMessage {
|
||||||
|
return Intl.message(
|
||||||
|
'Labels have been successfully added to these emails.',
|
||||||
|
name: 'addListLabelToListEmailSuccessfullyMessage',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get addListLabelToListEmailHasSomeFailureMessage {
|
||||||
|
return Intl.message(
|
||||||
|
'Labels have been successfully added to some emails.',
|
||||||
|
name: 'addListLabelToListEmailHasSomeFailureMessage',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get addListLabelToListEmailFailureMessage {
|
||||||
|
return Intl.message(
|
||||||
|
'Adding labels to these emails failed',
|
||||||
|
name: 'addListLabelToListEmailFailureMessage',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ 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_a_thread_state.dart';
|
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_a_thread_state.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_email_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/calendar_event_reply_state.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/email/domain/state/labels/remove_a_label_from_a_thread_state.dart';
|
import 'package:tmail_ui_user/features/email/domain/state/labels/remove_a_label_from_a_thread_state.dart';
|
||||||
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart';
|
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart';
|
||||||
import 'package:tmail_ui_user/features/email/domain/state/remove_a_label_from_an_email_state.dart';
|
import 'package:tmail_ui_user/features/email/domain/state/remove_a_label_from_an_email_state.dart';
|
||||||
@@ -229,6 +230,9 @@ class ToastManager {
|
|||||||
);
|
);
|
||||||
} else if (failure is DeleteALabelFailure) {
|
} else if (failure is DeleteALabelFailure) {
|
||||||
message = message ?? appLocalizations.deleteALabelFailure;
|
message = message ?? appLocalizations.deleteALabelFailure;
|
||||||
|
} else if (failure is AddListLabelsToListEmailsFailure) {
|
||||||
|
message =
|
||||||
|
message ?? appLocalizations.addListLabelToListEmailFailureMessage;
|
||||||
}
|
}
|
||||||
log('ToastManager::showMessageFailure: Message: $message');
|
log('ToastManager::showMessageFailure: Message: $message');
|
||||||
if (message?.trim().isNotEmpty == true) {
|
if (message?.trim().isNotEmpty == true) {
|
||||||
@@ -320,6 +324,10 @@ class ToastManager {
|
|||||||
message = appLocalizations.deleteLabelSuccessfullyMessage(
|
message = appLocalizations.deleteLabelSuccessfullyMessage(
|
||||||
success.deletedLabel.safeDisplayName,
|
success.deletedLabel.safeDisplayName,
|
||||||
);
|
);
|
||||||
|
} else if (success is AddListLabelsToListEmailsHasSomeFailure) {
|
||||||
|
message = appLocalizations.addListLabelToListEmailHasSomeFailureMessage;
|
||||||
|
} else if (success is AddListLabelsToListEmailsSuccess) {
|
||||||
|
message = appLocalizations.addListLabelToListEmailSuccessfullyMessage;
|
||||||
}
|
}
|
||||||
log('ToastManager::showMessageSuccess: Message: $message');
|
log('ToastManager::showMessageSuccess: Message: $message');
|
||||||
if (message?.trim().isNotEmpty == true) {
|
if (message?.trim().isNotEmpty == true) {
|
||||||
|
|||||||
@@ -62,4 +62,17 @@ extension ListEmailIdExtension on List<EmailId> {
|
|||||||
emailId.id: labelKeyword.generateLabelActionPath(remove: remove)
|
emailId.id: labelKeyword.generateLabelActionPath(remove: remove)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<Id, PatchObject> generateMapUpdateObjectListLabel(
|
||||||
|
List<KeyWordIdentifier> labelKeywords, {
|
||||||
|
bool remove = false,
|
||||||
|
}) {
|
||||||
|
return {
|
||||||
|
for (var emailId in this)
|
||||||
|
emailId.id: PatchObject({
|
||||||
|
for (var key in labelKeywords)
|
||||||
|
key.generatePath(): remove ? null : true,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user