diff --git a/WordPress/Classes/ViewRelated/Notifications/Tools/NotificationCommentDetailCoordinator.swift b/WordPress/Classes/ViewRelated/Notifications/Tools/NotificationCommentDetailCoordinator.swift index 1605b5748c3e..1c628fd1b61e 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Tools/NotificationCommentDetailCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Tools/NotificationCommentDetailCoordinator.swift @@ -10,8 +10,10 @@ class NotificationCommentDetailCoordinator: NSObject { private var comment: Comment? private let managedObjectContext = ContextManager.shared.mainContext private var viewController: CommentDetailViewController? - private var commentID: NSNumber? private var blog: Blog? + private var commentID: NSNumber? { + notification?.metaCommentID + } // Arrow navigation data source private weak var notificationsNavigationDataSource: NotificationsNavigationDataSource? @@ -38,8 +40,9 @@ class NotificationCommentDetailCoordinator: NSObject { configure(with: notification) if let comment = loadCommentFromCache(commentID) { - createViewController(comment: comment) - completion(viewController) + createViewController(comment: comment) { + completion(self.viewController) + } return } @@ -50,8 +53,9 @@ class NotificationCommentDetailCoordinator: NSObject { return } - self.createViewController(comment: comment) - completion(self.viewController) + self.createViewController(comment: comment) { + completion(self.viewController) + } }) } @@ -62,8 +66,11 @@ class NotificationCommentDetailCoordinator: NSObject { private extension NotificationCommentDetailCoordinator { func configure(with notification: Notification) { + // Clear previous notification's properties. + blog = nil + comment = nil + self.notification = notification - commentID = notification.metaCommentID if let siteID = notification.metaSiteID { blog = Blog.lookup(withID: siteID, in: managedObjectContext) @@ -104,7 +111,6 @@ private extension NotificationCommentDetailCoordinator { // If the comment has a parent and it is not cached, fetch it so the details header is correct. guard let notification = notification, let parentID = notification.metaParentID, - let blog = blog, loadCommentFromCache(parentID) == nil else { completion() return @@ -115,7 +121,7 @@ private extension NotificationCommentDetailCoordinator { }) } - func createViewController(comment: Comment) { + func createViewController(comment: Comment, completion: @escaping () -> Void) { self.comment = comment fetchParentCommentIfNeeded(completion: { [weak self] in @@ -129,6 +135,7 @@ private extension NotificationCommentDetailCoordinator { managedObjectContext: self.managedObjectContext) self.updateNavigationButtonStates() + completion() }) } @@ -173,6 +180,7 @@ private extension NotificationCommentDetailCoordinator { func refreshViewController() { if let comment = loadCommentFromCache(commentID) { + self.comment = comment viewController?.refreshView(comment: comment, notification: notification) updateNavigationButtonStates() return @@ -184,6 +192,7 @@ private extension NotificationCommentDetailCoordinator { return } + self.comment = comment self.viewController?.refreshView(comment: comment, notification: self.notification) self.updateNavigationButtonStates() })