TF-4236 Implement remove a label from an thread
This commit is contained in:
@@ -225,4 +225,11 @@ abstract class EmailDataSource {
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
}
|
||||
@@ -604,4 +604,21 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.removeLabelFromThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -590,4 +590,9 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
Future<void> removeLabelFromEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -366,4 +366,9 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
Future<void> removeLabelFromEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -280,4 +280,9 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
Future<void> removeLabelFromEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -1026,4 +1026,39 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
throw parseErrorForSetResponse(response, emailId.id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) async {
|
||||
final method = SetEmailMethod(accountId)
|
||||
..addUpdates(emailIds.generateMapUpdateObjectLabel(
|
||||
labelKeyword,
|
||||
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>[];
|
||||
final ids = emailIds.map((emailId) => emailId.id);
|
||||
final isUpdated = emailIdsUpdated.every(ids.contains);
|
||||
|
||||
if (emailIdsUpdated.isEmpty || !isUpdated) {
|
||||
for (var id in emailIds) {
|
||||
throw parseErrorForSetResponse(response, id.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -525,4 +525,19 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return emailDataSource[DataSourceType.network]!.removeLabelFromThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user