@@ -142,6 +142,12 @@ extension NSNotification.Name {
142142 WPAnalytics . trackReader ( . readerArticleCommentsOpened, properties: properties)
143143 }
144144
145+ // MARK: - Notification
146+
147+ @objc func postCommentModifiedNotification( ) {
148+ NotificationCenter . default. post ( name: . ReaderCommentModifiedNotification, object: nil )
149+ }
150+
145151}
146152
147153// MARK: - Popover Presentation Delegate
@@ -190,13 +196,13 @@ private extension ReaderCommentsViewController {
190196 return [
191197 [
192198 . unapprove { [ weak self] in
193- self ? . moderateComment ( comment, status: . pending, handler : handler )
199+ self ? . moderateComment ( comment, status: . pending)
194200 } ,
195201 . spam { [ weak self] in
196- self ? . moderateComment ( comment, status: . spam, handler : handler )
202+ self ? . moderateComment ( comment, status: . spam)
197203 } ,
198204 . trash { [ weak self] in
199- self ? . moderateComment ( comment, status: . unapproved, handler : handler )
205+ self ? . moderateComment ( comment, status: . unapproved)
200206 }
201207 ] ,
202208 [
@@ -223,7 +229,7 @@ private extension ReaderCommentsViewController {
223229 CommentAnalytics . trackCommentEdited ( comment: comment)
224230
225231 self ? . commentService. uploadComment ( comment, success: {
226- NotificationCenter . default . post ( name : . ReaderCommentModifiedNotification , object : nil )
232+ self ? . commentModified = true
227233
228234 // update the thread again in case the approval status changed.
229235 tableView. reloadRows ( at: [ indexPath] , with: . automatic)
@@ -237,23 +243,18 @@ private extension ReaderCommentsViewController {
237243 present ( navigationControllerToPresent, animated: true )
238244 }
239245
240- func moderateComment( _ comment: Comment , status: CommentStatusType , handler : WPTableViewHandler ) {
246+ func moderateComment( _ comment: Comment , status: CommentStatusType ) {
241247 let successBlock : ( String ) -> Void = { [ weak self] noticeText in
242- NotificationCenter . default. post ( name: . ReaderCommentModifiedNotification, object: nil )
243-
244- // Adjust the ReaderPost's comment count.
245- if let post = self ? . post, let commentCount = post. commentCount? . intValue {
246- let adjustment = ( status == . approved) ? 1 : - 1
247- post. commentCount = NSNumber ( value: commentCount + adjustment)
248- }
248+ self ? . commentModified = true
249+ self ? . refreshAfterCommentModeration ( )
249250
250- // Refresh the UI. The table view handler is needed because the fetched results delegate is set to nil .
251- handler . refreshTableViewPreservingOffset ( )
251+ // Dismiss any old notices to avoid stacked Undo notices .
252+ self ? . dismissNotice ( )
252253
253254 // If the status is Approved, the user has undone a comment moderation.
254255 // So don't show the Undo option in this case.
255256 ( status == . approved) ? self ? . displayNotice ( title: noticeText) :
256- self ? . showActionableNotice ( title: noticeText, comment: comment, handler : handler )
257+ self ? . showActionableNotice ( title: noticeText, comment: comment)
257258 }
258259
259260 switch status {
@@ -288,12 +289,12 @@ private extension ReaderCommentsViewController {
288289 }
289290 }
290291
291- func showActionableNotice( title: String , comment: Comment , handler : WPTableViewHandler ) {
292+ func showActionableNotice( title: String , comment: Comment ) {
292293 displayActionableNotice ( title: title,
293294 actionTitle: . undoActionTitle,
294295 actionHandler: { [ weak self] _ in
295296 // Set the Comment's status back to Approved when the user selects Undo on the notice.
296- self ? . moderateComment ( comment, status: . approved, handler : handler )
297+ self ? . moderateComment ( comment, status: . approved)
297298 } )
298299 }
299300
0 commit comments