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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user