Skip to content

Commit a18565a

Browse files
committed
Update post's Comment snippet when comments are changed in the Comments view.
1 parent f39e0d0 commit a18565a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import Foundation
22
import UIKit
33
import WordPressShared
44

5+
// Notification sent when a comment is moderated/edited to allow views that display Comments to update if necessary.
6+
// Specifically, the Comments snippet on ReaderDetailViewController.
7+
extension NSNotification.Name {
8+
static let ReaderCommentModifiedNotification = NSNotification.Name(rawValue: "ReaderCommentModifiedNotification")
9+
}
510

611
@objc public extension ReaderCommentsViewController {
712
func shouldShowSuggestions(for siteID: NSNumber?) -> Bool {
@@ -218,6 +223,8 @@ private extension ReaderCommentsViewController {
218223
CommentAnalytics.trackCommentEdited(comment: comment)
219224

220225
self?.commentService.uploadComment(comment, success: {
226+
NotificationCenter.default.post(name: .ReaderCommentModifiedNotification, object: nil)
227+
221228
// update the thread again in case the approval status changed.
222229
tableView.reloadRows(at: [indexPath], with: .automatic)
223230
}, failure: { _ in
@@ -232,6 +239,8 @@ private extension ReaderCommentsViewController {
232239

233240
func moderateComment(_ comment: Comment, status: CommentStatusType, handler: WPTableViewHandler) {
234241
let successBlock: (String) -> Void = { [weak self] noticeText in
242+
NotificationCenter.default.post(name: .ReaderCommentModifiedNotification, object: nil)
243+
235244
// Adjust the ReaderPost's comment count.
236245
if let post = self?.post, let commentCount = post.commentCount?.intValue {
237246
let adjustment = (status == .approved) ? 1 : -1

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
169169

170170
// Fixes swipe to go back not working when leftBarButtonItem is set
171171
navigationController?.interactivePopGestureRecognizer?.delegate = self
172+
173+
// When comments are moderated or edited from the Comments view, update the Comments snippet here.
174+
NotificationCenter.default.addObserver(self, selector: #selector(fetchComments), name: .ReaderCommentModifiedNotification, object: nil)
172175
}
173176

174177
override func viewWillAppear(_ animated: Bool) {
@@ -229,10 +232,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
229232
toolbar.configure(for: post, in: self)
230233
header.configure(for: post)
231234
fetchLikes()
232-
233-
if FeatureFlag.postDetailsComments.enabled {
234-
fetchComments()
235-
}
235+
fetchComments()
236236

237237
if let postURLString = post.permaLink,
238238
let postURL = URL(string: postURLString) {
@@ -528,10 +528,11 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
528528
view.setNeedsDisplay()
529529
}
530530

531-
private func fetchComments() {
532-
guard let post = post else {
533-
return
534-
}
531+
@objc private func fetchComments() {
532+
guard FeatureFlag.postDetailsComments.enabled,
533+
let post = post else {
534+
return
535+
}
535536

536537
coordinator?.fetchComments(for: post)
537538
}

0 commit comments

Comments
 (0)