TF-4236 Fix partial-update validation for thread label ops.

This commit is contained in:
dab246
2026-01-26 10:22:39 +07:00
committed by Dat H. Pham
parent b633bcf709
commit a05a28700a
4 changed files with 22 additions and 11 deletions
+15 -7
View File
@@ -971,6 +971,10 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
List<EmailId> emailIds,
KeyWordIdentifier labelKeyword,
) async {
if (emailIds.isEmpty) {
throw ArgumentError.value(emailIds, 'emailIds', 'must not be empty');
}
final method = SetEmailMethod(accountId)
..addUpdates(emailIds.generateMapUpdateObjectLabel(labelKeyword));
@@ -987,8 +991,9 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
);
final emailIdsUpdated = response?.updated?.keys ?? <Id>[];
final ids = emailIds.map((emailId) => emailId.id);
final isUpdated = emailIdsUpdated.every(ids.contains);
final ids = emailIds.toSetIds();
final isUpdated = ids.every(emailIdsUpdated.contains) &&
emailIdsUpdated.length == ids.length;
if (emailIdsUpdated.isEmpty || !isUpdated) {
throw parseErrorForSetResponse(response, emailIds.first.id);
@@ -1031,6 +1036,10 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
List<EmailId> emailIds,
KeyWordIdentifier labelKeyword,
) async {
if (emailIds.isEmpty) {
throw ArgumentError.value(emailIds, 'emailIds', 'must not be empty');
}
final method = SetEmailMethod(accountId)
..addUpdates(emailIds.generateMapUpdateObjectLabel(
labelKeyword,
@@ -1050,13 +1059,12 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
);
final emailIdsUpdated = response?.updated?.keys ?? <Id>[];
final ids = emailIds.map((emailId) => emailId.id);
final isUpdated = emailIdsUpdated.every(ids.contains);
final ids = emailIds.toSetIds();
final isUpdated = emailIdsUpdated.every(ids.contains) &&
emailIdsUpdated.length == ids.length;
if (emailIdsUpdated.isEmpty || !isUpdated) {
for (var id in emailIds) {
throw parseErrorForSetResponse(response, id.id);
}
throw parseErrorForSetResponse(response, emailIds.first.id);
}
}
}
@@ -32,11 +32,11 @@ extension MapKeywordsExtension on Map<KeyWordIdentifier, bool>? {
this?.remove(keyword);
}
void toggleKeyword(KeyWordIdentifier keyword, bool remove) {
if (remove) {
this?.remove(keyword);
void toggleKeyword(KeyWordIdentifier keyword, bool shouldRemove) {
if (shouldRemove) {
removeKeyword(keyword);
} else {
this?[keyword] = true;
addKeyword(keyword);
}
}
}