Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications > Comments: remove Notification when Comment is removed #17992

Merged
merged 6 commits into from
Feb 21, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
case .mediaPickerPermissionsNotice:
return true
case .notificationCommentDetails:
return false
return BuildConfiguration.current ~= [.localDeveloper, .a8cBranchTest, .a8cPrereleaseTesting]
case .statsPerformanceImprovements:
return BuildConfiguration.current == .localDeveloper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CoreData
protocol CommentDetailsNotificationNavigationDelegate: AnyObject {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this protocol name isn't really accurate with the new method I added. I'll make a note to rename it in a future PR.

func previousNotificationTapped(current: Notification?)
func nextNotificationTapped(current: Notification?)
func commentWasModerated(for notification: Notification?)
}

class CommentDetailViewController: UIViewController {
Expand Down Expand Up @@ -770,6 +771,8 @@ private extension String {
extension CommentDetailViewController: CommentModerationBarDelegate {
func statusChangedTo(_ commentStatus: CommentStatusType) {

notifyDelegateCommentModerated()

switch commentStatus {
case .pending:
unapproveComment()
Expand Down Expand Up @@ -850,12 +853,27 @@ private extension CommentDetailViewController {
})
}

func notifyDelegateCommentModerated() {
guard let notification = notification else {
return
}

notificationNavigationDelegate?.commentWasModerated(for: notification)
}

func showActionableNotice(title: String) {
guard !isNotificationComment else {
return
}

guard viewIsVisible, !isLastInList else {
displayNotice(title: title)
return
}

// Dismiss any old notices to avoid stacked Next notices.
dismissNotice()

displayActionableNotice(title: title,
style: NormalNoticeStyle(showNextArrow: true),
actionTitle: ModerationMessages.next,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class NotificationsViewController: UITableViewController, UIViewControllerRestor
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

syncNotificationsWithModeratedComments()
setupInlinePrompt()

// Manually deselect the selected row.
Expand Down Expand Up @@ -241,6 +242,7 @@ class NotificationsViewController: UITableViewController, UIViewControllerRestor
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

Expand Down Expand Up @@ -381,6 +383,11 @@ class NotificationsViewController: UITableViewController, UIViewControllerRestor

selectedNotification = note
showDetails(for: note)

if !splitViewControllerIsHorizontallyCompact {
syncNotificationsWithModeratedComments()
}

}

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
Expand Down Expand Up @@ -869,6 +876,24 @@ private extension NotificationsViewController {
func deletionRequestForNoteWithID(_ noteObjectID: NSManagedObjectID) -> NotificationDeletionRequest? {
return notificationDeletionRequests[noteObjectID]
}

// With the `notificationCommentDetails` feature, Comment moderation is handled by the view.
// To avoid updating the Notifications here prematurely, affecting the previous/next buttons,
// the Notifications are tracked in NotificationCommentDetailCoordinator when their comments are moderated.
// Those Notifications are updated here when the view is shown to update the list accordingly.
func syncNotificationsWithModeratedComments() {
if let selectedNotification = selectedNotification,
notificationCommentDetailCoordinator.notificationsCommentModerated.contains(selectedNotification) {
self.selectedNotification = nil
}

notificationCommentDetailCoordinator.notificationsCommentModerated.forEach {
syncNotification(with: $0.notificationId, timeout: Syncing.pushMaxWait, success: {_ in })
}

notificationCommentDetailCoordinator.notificationsCommentModerated = []
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class NotificationCommentDetailCoordinator: NSObject {
// This happens due to Navigation Events (Next / Previous)
var onSelectedNoteChange: ((Notification) -> Void)?

// Keep track of Notifications that have moderated Comments so they can be updated
// the next time the Notifications list is displayed.
var notificationsCommentModerated: [Notification] = []

private lazy var commentService: CommentService = {
return .init(managedObjectContext: managedObjectContext)
}()
Expand Down Expand Up @@ -268,4 +272,13 @@ extension NotificationCommentDetailCoordinator: CommentDetailsNotificationNaviga
updateViewWith(notification: nextNotification)
}

func commentWasModerated(for notification: Notification?) {
guard let notification = notification,
!notificationsCommentModerated.contains(notification) else {
return
}

notificationsCommentModerated.append(notification)
}

}