Skip to content

Commit 94c981a

Browse files
committed
Show new Comment detail view when a cached comment notification is selected.
1 parent d86320d commit 94c981a

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
2323
case followConversationPostDetails
2424
case markAllNotificationsAsRead
2525
case mediaPickerPermissionsNotice
26+
case notificationCommentDetails
2627

2728
/// Returns a boolean indicating if the feature is enabled
2829
var enabled: Bool {
@@ -74,6 +75,8 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
7475
return true
7576
case .mediaPickerPermissionsNotice:
7677
return true
78+
case .notificationCommentDetails:
79+
return false
7780
}
7881
}
7982

@@ -142,6 +145,8 @@ extension FeatureFlag {
142145
return "Mark Notifications As Read"
143146
case .mediaPickerPermissionsNotice:
144147
return "Media Picker Permissions Notice"
148+
case .notificationCommentDetails:
149+
return "Notification Comment Details"
145150
}
146151
}
147152

WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ class CommentDetailViewController: UIViewController {
2020

2121
@objc weak var delegate: CommentDetailsDelegate?
2222
private var comment: Comment
23-
private var isLastInList: Bool
23+
private var isLastInList = true
2424
private var managedObjectContext: NSManagedObjectContext
2525
private var rows = [RowType]()
2626
private var moderationBar: CommentModerationBar?
27+
private var notification: Notification?
28+
29+
private var isNotificationComment: Bool {
30+
notification != nil
31+
}
32+
33+
private var viewTitle: String? {
34+
isNotificationComment ? notification?.title : nil
35+
}
2736

2837
private var viewIsVisible: Bool {
2938
return navigationController?.visibleViewController == self
@@ -163,16 +172,26 @@ class CommentDetailViewController: UIViewController {
163172

164173
// MARK: Initialization
165174

166-
@objc required init(comment: Comment,
167-
isLastInList: Bool,
168-
managedObjectContext: NSManagedObjectContext = ContextManager.sharedInstance().mainContext) {
175+
@objc init(comment: Comment,
176+
isLastInList: Bool,
177+
managedObjectContext: NSManagedObjectContext = ContextManager.sharedInstance().mainContext) {
169178
self.comment = comment
170179
self.isLastInList = isLastInList
171180
self.managedObjectContext = managedObjectContext
172181
self.replyID = comment.replyID
173182
super.init(nibName: nil, bundle: nil)
174183
}
175184

185+
init(comment: Comment,
186+
notification: Notification,
187+
managedObjectContext: NSManagedObjectContext = ContextManager.sharedInstance().mainContext) {
188+
self.comment = comment
189+
self.notification = notification
190+
self.managedObjectContext = managedObjectContext
191+
self.replyID = comment.replyID
192+
super.init(nibName: nil, bundle: nil)
193+
}
194+
176195
required init?(coder: NSCoder) {
177196
fatalError("init(coder:) has not been implemented")
178197
}
@@ -280,6 +299,7 @@ private extension CommentDetailViewController {
280299
}
281300

282301
navigationController?.navigationBar.isTranslucent = true
302+
title = viewTitle
283303

284304
configureEditButtonItem()
285305
}

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class NotificationsViewController: UITableViewController, UIViewControllerRestor
312312
return
313313
}
314314

315+
// TODO: add check for CommentDetailViewController
315316
for case let detailVC as NotificationDetailsViewController in navigationControllers {
316317
if detailVC.onDeletionRequestCallback == nil, let note = detailVC.note {
317318
configureDetailsViewController(detailVC, withNote: note)
@@ -723,7 +724,24 @@ extension NotificationsViewController {
723724
view.isUserInteractionEnabled = false
724725

725726
DispatchQueue.main.async {
726-
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
727+
if FeatureFlag.notificationCommentDetails.enabled,
728+
note.kind == .comment {
729+
let notificationCommentDetailCoordinator = NotificationCommentDetailCoordinator(notification: note)
730+
731+
// For now, NotificationCommentDetailCoordinator only loads the Comment if it is cached.
732+
// If the comment is not cached, fall back to showing the old comment view.
733+
// This is temporary until NotificationCommentDetailCoordinator can fetch the comment from the endpoint.
734+
735+
if let commentDetailViewController = notificationCommentDetailCoordinator.viewController {
736+
commentDetailViewController.navigationItem.largeTitleDisplayMode = .never
737+
self.showDetailViewController(commentDetailViewController, sender: nil)
738+
} else {
739+
// TODO: remove when NotificationCommentDetailCoordinator updated to fetch comment.
740+
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
741+
}
742+
} else {
743+
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
744+
}
727745
self.view.isUserInteractionEnabled = true
728746
}
729747
}

0 commit comments

Comments
 (0)