Skip to content

Commit 7a1d430

Browse files
authored
Delete pre-saved local comment when the server fails to create a comment (#24548)
1 parent 095fe87 commit 7a1d430

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

WordPress/Classes/Services/CommentService.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,19 @@ - (void)uploadComment:(Comment *)comment
429429
} else {
430430
[remote createComment:remoteComment
431431
success:successBlock
432-
failure:failure];
432+
failure:^(NSError *error) {
433+
// When the site fails to create a comment, we need to delete the comment in the local database.
434+
[self.coreDataStack performAndSaveUsingBlock:^(NSManagedObjectContext *context) {
435+
Comment *commentInContext = [context existingObjectWithID:commentObjectID error:nil];
436+
if (commentInContext) {
437+
[context deleteObject:commentInContext];
438+
}
439+
} completion:^{
440+
if (failure != nil) {
441+
failure(error);
442+
}
443+
} onQueue:dispatch_get_main_queue()];
444+
}];
433445
}
434446
}
435447

0 commit comments

Comments
 (0)