TF-4236 Add repository/interactor for remove a label from an email
This commit is contained in:
@@ -218,4 +218,11 @@ abstract class EmailDataSource {
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> removeLabelFromEmail(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
}
|
||||
@@ -587,4 +587,21 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromEmail(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.removeLabelFromEmail(
|
||||
session,
|
||||
accountId,
|
||||
emailId,
|
||||
labelKeyword,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -585,4 +585,9 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -361,4 +361,9 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -275,4 +275,9 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -996,4 +996,34 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeLabelFromEmail(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) async {
|
||||
final method = SetEmailMethod(accountId)
|
||||
..addUpdates({
|
||||
emailId.id: labelKeyword.generateLabelActionPath(remove: true),
|
||||
});
|
||||
|
||||
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>[];
|
||||
|
||||
if (emailIdsUpdated.isEmpty || !emailIdsUpdated.contains(emailId.id)) {
|
||||
throw parseErrorForSetResponse(response, emailId.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -510,4 +510,19 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromEmail(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return emailDataSource[DataSourceType.network]!.removeLabelFromEmail(
|
||||
session,
|
||||
accountId,
|
||||
emailId,
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -175,4 +175,11 @@ abstract class EmailRepository {
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> removeLabelFromEmail(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
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 RemovingALabelFromAnEmail extends LoadingState {}
|
||||
|
||||
class RemoveALabelFromAnEmailSuccess extends UIState {
|
||||
final EmailId emailId;
|
||||
final KeyWordIdentifier labelKeyword;
|
||||
final String labelDisplay;
|
||||
|
||||
RemoveALabelFromAnEmailSuccess(this.emailId, this.labelKeyword, this.labelDisplay);
|
||||
|
||||
@override
|
||||
List<Object> get props => [emailId, labelKeyword, labelDisplay];
|
||||
}
|
||||
|
||||
class RemoveALabelFromAnEmailFailure extends FeatureFailure {
|
||||
final String labelDisplay;
|
||||
|
||||
RemoveALabelFromAnEmailFailure({
|
||||
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/remove_a_label_from_an_email_state.dart';
|
||||
|
||||
class RemoveALabelFromAnEmailInteractor {
|
||||
final EmailRepository _emailRepository;
|
||||
|
||||
RemoveALabelFromAnEmailInteractor(this._emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
String labelDisplay,
|
||||
) async* {
|
||||
try {
|
||||
yield Right(RemovingALabelFromAnEmail());
|
||||
await _emailRepository.removeLabelFromEmail(
|
||||
session,
|
||||
accountId,
|
||||
emailId,
|
||||
labelKeyword,
|
||||
);
|
||||
yield Right(RemoveALabelFromAnEmailSuccess(
|
||||
emailId,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
} catch (e) {
|
||||
yield Left(RemoveALabelFromAnEmailFailure(
|
||||
exception: e,
|
||||
labelDisplay: labelDisplay,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user