TF-4195 Add Label to Thread
This commit is contained in:
@@ -211,4 +211,11 @@ abstract class EmailDataSource {
|
||||
EmailId emailId,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
}
|
||||
@@ -570,4 +570,21 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.addLabelToThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -580,4 +580,9 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -356,4 +356,9 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -270,4 +270,9 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
Future<void> addLabelToEmail(Session session, AccountId accountId, EmailId emailId, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -964,4 +964,36 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
throw parseErrorForSetResponse(response, emailId.id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) async {
|
||||
final method = SetEmailMethod(accountId)
|
||||
..addUpdates(emailIds.generateMapUpdateObjectLabel(labelKeyword));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -495,4 +495,19 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) {
|
||||
return emailDataSource[DataSourceType.network]!.addLabelToThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user