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 split view: set selected Notification after removing moderated #18002

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import UIKit
import CoreData


@objc protocol CommentDetailsModerationDelegate: AnyObject {
@objc protocol CommentDetailsDelegate: AnyObject {
func nextCommentSelected()
}

protocol CommentDetailsNotificationNavigationDelegate: AnyObject {
protocol CommentDetailsNotificationDelegate: AnyObject {
func previousNotificationTapped(current: Notification?)
func nextNotificationTapped(current: Notification?)
func commentWasModerated(for notification: Notification?)
Expand All @@ -25,16 +25,16 @@ class CommentDetailViewController: UIViewController {
private var keyboardManager: KeyboardDismissHelper?
private var dismissKeyboardTapGesture = UITapGestureRecognizer()

@objc weak var moderationDelegate: CommentDetailsModerationDelegate?
@objc weak var commentDelegate: CommentDetailsDelegate?
private weak var notificationDelegate: CommentDetailsNotificationDelegate?

private var comment: Comment
private var isLastInList = true
private var managedObjectContext: NSManagedObjectContext
private var rows = [RowType]()
private var moderationBar: CommentModerationBar?
private var notification: Notification?

private weak var notificationNavigationDelegate: CommentDetailsNotificationNavigationDelegate?

private var isNotificationComment: Bool {
notification != nil
}
Expand Down Expand Up @@ -220,11 +220,11 @@ class CommentDetailViewController: UIViewController {

init(comment: Comment,
notification: Notification?,
notificationNavigationDelegate: CommentDetailsNotificationNavigationDelegate?,
notificationDelegate: CommentDetailsNotificationDelegate?,
managedObjectContext: NSManagedObjectContext = ContextManager.sharedInstance().mainContext) {
self.comment = comment
self.notification = notification
self.notificationNavigationDelegate = notificationNavigationDelegate
self.notificationDelegate = notificationDelegate
self.managedObjectContext = managedObjectContext
super.init(nibName: nil, bundle: nil)
}
Expand Down Expand Up @@ -675,11 +675,11 @@ private extension CommentDetailViewController {
}

@objc func previousButtonTapped() {
notificationNavigationDelegate?.previousNotificationTapped(current: notification)
notificationDelegate?.previousNotificationTapped(current: notification)
}

@objc func nextButtonTapped() {
notificationNavigationDelegate?.nextNotificationTapped(current: notification)
notificationDelegate?.nextNotificationTapped(current: notification)
}

func deleteButtonTapped() {
Expand Down Expand Up @@ -858,7 +858,7 @@ private extension CommentDetailViewController {
return
}

notificationNavigationDelegate?.commentWasModerated(for: notification)
notificationDelegate?.commentWasModerated(for: notification)
}

func showActionableNotice(title: String) {
Expand Down Expand Up @@ -888,7 +888,7 @@ private extension CommentDetailViewController {
}

WPAnalytics.track(.commentSnackbarNext)
moderationDelegate?.nextCommentSelected()
commentDelegate?.nextCommentSelected()
}

struct ModerationMessages {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
static NSString *RestorableBlogIdKey = @"restorableBlogIdKey";
static NSString *RestorableFilterIndexKey = @"restorableFilterIndexKey";

@interface CommentsViewController () <WPTableViewHandlerDelegate, WPContentSyncHelperDelegate, UIViewControllerRestoration, NoResultsViewControllerDelegate, CommentDetailsModerationDelegate>
@interface CommentsViewController () <WPTableViewHandlerDelegate, WPContentSyncHelperDelegate, UIViewControllerRestoration, NoResultsViewControllerDelegate, CommentDetailsDelegate>
@property (nonatomic, strong) WPTableViewHandler *tableViewHandler;
@property (nonatomic, strong) WPContentSyncHelper *syncHelper;
@property (nonatomic, strong) NoResultsViewController *noResultsViewController;
Expand Down Expand Up @@ -233,7 +233,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
self.commentDetailViewController = [[CommentDetailViewController alloc] initWithComment:comment
isLastInList:[self isLastRow:indexPath]
managedObjectContext:[ContextManager sharedInstance].mainContext];
self.commentDetailViewController.moderationDelegate = self;
self.commentDetailViewController.commentDelegate = self;
[self.navigationController pushViewController:self.commentDetailViewController animated:YES];
[CommentAnalytics trackCommentViewedWithComment:comment];
}
Expand Down Expand Up @@ -752,7 +752,7 @@ - (void)actionButtonPressed
[self refreshNoConnectionView];
}

#pragma mark - CommentDetailsModerationDelegate
#pragma mark - CommentDetailsDelegate

- (void)nextCommentSelected
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,10 @@ extension NotificationsViewController {
return
}

presentCommentDetail(for: note)
presentDetails(for: note)
}

private func presentCommentDetail(for note: Notification) {
private func presentDetails(for note: Notification) {
// This dispatch avoids a bug that was occurring occasionally where navigation (nav bar and tab bar)
// would be missing entirely when launching the app from the background and presenting a notification.
// The issue seems tied to performing a `pop` in `prepareToShowDetails` and presenting
Expand Down Expand Up @@ -882,9 +882,21 @@ private extension NotificationsViewController {
// 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,
// If the currently selected notification is about to be removed, find the next available and select it.
// This is only necessary for split view to prevent the details from showing for removed notifications.
if !splitViewControllerIsHorizontallyCompact,
let selectedNotification = selectedNotification,
notificationCommentDetailCoordinator.notificationsCommentModerated.contains(selectedNotification) {
self.selectedNotification = nil

guard let notifications = tableViewHandler.resultsController.fetchedObjects as? [Notification],
let nextAvailable = notifications.first(where: { !notificationCommentDetailCoordinator.notificationsCommentModerated.contains($0) }),
let indexPath = tableViewHandler.resultsController.indexPath(forObject: nextAvailable) else {
self.selectedNotification = nil
return
}

self.selectedNotification = nextAvailable
tableView(tableView, didSelectRowAt: indexPath)
}

notificationCommentDetailCoordinator.notificationsCommentModerated.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private extension NotificationCommentDetailCoordinator {

self.viewController = CommentDetailViewController(comment: comment,
notification: self.notification,
notificationNavigationDelegate: self,
notificationDelegate: self,
managedObjectContext: self.managedObjectContext)

self.updateNavigationButtonStates()
Expand Down Expand Up @@ -248,9 +248,9 @@ private extension NotificationCommentDetailCoordinator {

}

// MARK: - CommentDetailsNotificationNavigationDelegate
// MARK: - CommentDetailsNotificationDelegate

extension NotificationCommentDetailCoordinator: CommentDetailsNotificationNavigationDelegate {
extension NotificationCommentDetailCoordinator: CommentDetailsNotificationDelegate {

func previousNotificationTapped(current: Notification?) {
guard let current = current,
Expand Down