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: fix notification selection issues #17978

Merged
merged 4 commits into from
Feb 18, 2022
Merged
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
@@ -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()
})