Skip to content

Commit 37a8636

Browse files
committed
Don't show non-approved cached comments.
1 parent b08f57b commit 37a8636

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ typedef NS_ENUM(NSUInteger, ReaderCommentsSource) {
3434

3535
// Comment moderation support.
3636
@property (nonatomic, assign, readwrite) BOOL commentModified;
37+
- (void)refreshAfterCommentModeration;
38+
3739
@end

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ - (void)refreshNoResultsView
939939
[self.noResultsViewController didMoveToParentViewController:self];
940940
}
941941

942+
- (void)refreshAfterCommentModeration
943+
{
944+
[self.tableViewHandler refreshTableView];
945+
[self refreshNoResultsView];
946+
}
947+
942948
- (void)updateTableViewForAttachments
943949
{
944950
[self.tableView performBatchUpdates:nil completion:nil];
@@ -1205,9 +1211,11 @@ - (NSFetchRequest *)fetchRequest
12051211
return nil;
12061212
}
12071213

1208-
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:NSStringFromClass([Comment class])];
1209-
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"post = %@", self.post];
1214+
// Moderated comments could still be cached, so filter out non-approved comments.
1215+
NSString *approvedStatus = [Comment descriptionFor:CommentStatusTypeApproved];
12101216

1217+
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:NSStringFromClass([Comment class])];
1218+
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"post = %@ AND status = %@", self.post, approvedStatus];
12111219
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"hierarchy" ascending:YES];
12121220
[fetchRequest setSortDescriptors:@[sortDescriptor]];
12131221

@@ -1231,12 +1239,6 @@ - (void)configureCell:(UITableViewCell *)aCell atIndexPath:(NSIndexPath *)indexP
12311239
}
12321240

12331241
Comment *comment = [self.tableViewHandler.resultsController objectAtIndexPath:indexPath];
1234-
// The user may have moderated a comment, but it is not removed from the post yet.
1235-
// So check the status to be sure only Approved comments are displayed.
1236-
if (![comment.status isEqualToString:[Comment descriptionFor:CommentStatusTypeApproved]]) {
1237-
return;
1238-
}
1239-
12401242
if ([self newCommentThreadEnabled]) {
12411243
CommentContentTableViewCell *cell = (CommentContentTableViewCell *)aCell;
12421244
[self configureContentCell:cell comment:comment indexPath:indexPath handler:self.tableViewHandler];
@@ -1296,8 +1298,6 @@ - (void)configureCell:(UITableViewCell *)aCell atIndexPath:(NSIndexPath *)indexP
12961298
};
12971299
}
12981300

1299-
1300-
13011301
NSAttributedString *attrStr = [self cacheContentForComment:comment];
13021302
[cell configureCellWithComment:comment attributedString:attrStr];
13031303
}

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,10 @@ private extension ReaderCommentsViewController {
246246
func moderateComment(_ comment: Comment, status: CommentStatusType, handler: WPTableViewHandler) {
247247
let successBlock: (String) -> Void = { [weak self] noticeText in
248248
self?.commentModified = true
249+
self?.refreshAfterCommentModeration()
249250

250-
// Adjust the ReaderPost's comment count.
251-
if let post = self?.post, let commentCount = post.commentCount?.intValue {
252-
let adjustment = (status == .approved) ? 1 : -1
253-
post.commentCount = NSNumber(value: commentCount + adjustment)
254-
}
255-
256-
// Refresh the UI. The table view handler is needed because the fetched results delegate is set to nil.
257-
handler.refreshTableViewPreservingOffset()
251+
// Dismiss any old notices to avoid stacked Undo notices.
252+
self?.dismissNotice()
258253

259254
// If the status is Approved, the user has undone a comment moderation.
260255
// So don't show the Undo option in this case.

WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,15 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
382382
return
383383
}
384384

385+
// Moderated comments could still be cached, so filter out non-approved comments.
386+
let approvedComments = comments.filter({ $0.status == "approve"})
387+
385388
// Set the delegate here so the table isn't shown until fetching is complete.
386389
commentsTableView.delegate = commentsTableViewDelegate
387390
commentsTableView.dataSource = commentsTableViewDelegate
388391

389392
commentsTableViewDelegate.updateWith(post: post,
390-
comments: comments,
393+
comments: approvedComments,
391394
totalComments: totalComments,
392395
presentingViewController: self,
393396
buttonDelegate: self)

0 commit comments

Comments
 (0)