Skip to content

Commit 0ebebbe

Browse files
authored
Merge pull request #17917 from wordpress-mobile/fix/17290-show_replied_cell
Comment moderation: update view correctly when selecting Next on confirmation notice
2 parents 68a8b80 + d91d581 commit 0ebebbe

1 file changed

Lines changed: 31 additions & 26 deletions

File tree

WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,7 @@ class CommentDetailViewController: UIViewController {
4343
}
4444

4545
private var replyID: Int32 {
46-
didSet {
47-
// toggle reply indicator cell visibility only when the value changes from 0 to any positive number, or vice versa.
48-
if oldValue == 0 && replyID > 0 {
49-
// show the reply indicator row.
50-
// update the rows first so replyIndicator is present in `rows`.
51-
configureRows()
52-
guard let replyIndicatorRow = rows.firstIndex(of: .replyIndicator) else {
53-
tableView.reloadData()
54-
return
55-
}
56-
tableView.insertRows(at: [IndexPath(row: replyIndicatorRow, section: .zero)], with: .fade)
57-
58-
} else if oldValue > 0 && replyID == 0 {
59-
// hide the reply indicator row.
60-
// get the reply indicator row first before it is removed via `configureRows`.
61-
guard let replyIndicatorRow = rows.firstIndex(of: .replyIndicator) else {
62-
return
63-
}
64-
configureRows()
65-
tableView.deleteRows(at: [IndexPath(row: replyIndicatorRow, section: .zero)], with: .fade)
66-
}
67-
}
46+
return comment.replyID
6847
}
6948

7049
private var isCommentReplied: Bool {
@@ -204,7 +183,6 @@ class CommentDetailViewController: UIViewController {
204183
self.comment = comment
205184
self.isLastInList = isLastInList
206185
self.managedObjectContext = managedObjectContext
207-
self.replyID = comment.replyID
208186
super.init(nibName: nil, bundle: nil)
209187
}
210188

@@ -214,7 +192,6 @@ class CommentDetailViewController: UIViewController {
214192
self.comment = comment
215193
self.notification = notification
216194
self.managedObjectContext = managedObjectContext
217-
self.replyID = comment.replyID
218195
super.init(nibName: nil, bundle: nil)
219196
}
220197

@@ -264,7 +241,9 @@ class CommentDetailViewController: UIViewController {
264241
@objc func displayComment(_ comment: Comment, isLastInList: Bool) {
265242
self.comment = comment
266243
self.isLastInList = isLastInList
244+
replyTextView?.placeholder = String(format: .replyPlaceholderFormat, comment.authorForDisplay())
267245
refreshData()
246+
refreshCommentReplyIfNeeded()
268247
}
269248
}
270249

@@ -526,15 +505,41 @@ private extension CommentDetailViewController {
526505
self.comment.replyID = Int32(replyID)
527506
ContextManager.sharedInstance().saveContextAndWait(context)
528507

529-
// update local replyID to trigger table view updates.
530-
self.replyID = self.comment.replyID
508+
self.updateReplyIndicator()
531509

532510
} failure: { error in
533511
DDLogError("Failed fetching latest comment reply ID: \(String(describing: error))")
534512
}
535513

536514
}
537515

516+
func updateReplyIndicator() {
517+
518+
// If there is a reply, add reply indicator if it is not being shown.
519+
if replyID > 0 && !rows.contains(.replyIndicator) {
520+
// Update the rows first so replyIndicator is present in `rows`.
521+
configureRows()
522+
guard let replyIndicatorRow = rows.firstIndex(of: .replyIndicator) else {
523+
tableView.reloadData()
524+
return
525+
}
526+
527+
tableView.insertRows(at: [IndexPath(row: replyIndicatorRow, section: .zero)], with: .fade)
528+
return
529+
}
530+
531+
// If there is not a reply, remove reply indicator if it is being shown.
532+
if replyID == 0 && rows.contains(.replyIndicator) {
533+
// Get the reply indicator row first before it is removed via `configureRows`.
534+
guard let replyIndicatorRow = rows.firstIndex(of: .replyIndicator) else {
535+
return
536+
}
537+
538+
configureRows()
539+
tableView.deleteRows(at: [IndexPath(row: replyIndicatorRow, section: .zero)], with: .fade)
540+
}
541+
}
542+
538543
// MARK: Actions and navigations
539544

540545
// Shows the comment thread with the parent comment highlighted.

0 commit comments

Comments
 (0)