TF-4195 Add Label to Thread

This commit is contained in:
dab246
2026-01-06 12:35:13 +07:00
committed by Dat H. Pham
parent ef1efc9310
commit 94fd6f8071
34 changed files with 829 additions and 40 deletions
@@ -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);
}
}
}
}