Skip to content

Commit f39e0d0

Browse files
authored
Merge pull request #17850 from wordpress-mobile/feature/17790-show_cached_comment
Notifications > Comment Details: show new details view for cached comment
2 parents ed33989 + 47f97e7 commit f39e0d0

File tree

5 files changed

+108
-12
lines changed

5 files changed

+108
-12
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
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Foundation
2+
3+
// This facilitates showing the CommentDetailViewController within the context of Notifications.
4+
5+
class NotificationCommentDetailCoordinator: NSObject {
6+
7+
// MARK: - Properties
8+
9+
private let notification: Notification
10+
private var comment: Comment?
11+
private let managedObjectContext = ContextManager.shared.mainContext
12+
private(set) var viewController: CommentDetailViewController?
13+
14+
private lazy var commentService: CommentService = {
15+
return .init(managedObjectContext: managedObjectContext)
16+
}()
17+
18+
// MARK: - Init
19+
20+
init(notification: Notification) {
21+
self.notification = notification
22+
super.init()
23+
loadCommentFromCache()
24+
}
25+
26+
}
27+
28+
// MARK: - Private Extension
29+
30+
private extension NotificationCommentDetailCoordinator {
31+
32+
func loadCommentFromCache() {
33+
guard let siteID = notification.metaSiteID,
34+
let commentID = notification.metaCommentID,
35+
let blog = Blog.lookup(withID: siteID, in: managedObjectContext),
36+
let comment = commentService.findComment(withID: commentID, in: blog) else {
37+
DDLogError("Notification Comment: failed loading comment from cache.")
38+
return
39+
}
40+
41+
self.comment = comment
42+
viewController = CommentDetailViewController(comment: comment,
43+
notification: notification,
44+
managedObjectContext: managedObjectContext)
45+
}
46+
47+
}

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,8 @@
17291729
988F073A23D0D16700AC67A6 /* WidgetUrlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 988F073323D0CE8800AC67A6 /* WidgetUrlCell.swift */; };
17301730
988F073B23D0D16800AC67A6 /* WidgetUrlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 988F073323D0CE8800AC67A6 /* WidgetUrlCell.swift */; };
17311731
988F073C23D0D16800AC67A6 /* WidgetUrlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 988F073323D0CE8800AC67A6 /* WidgetUrlCell.swift */; };
1732+
988FD74A279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 988FD749279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift */; };
1733+
988FD74B279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 988FD749279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift */; };
17321734
98906502237CC1DF00218CD2 /* WidgetUnconfiguredCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 989064FB237CC1DE00218CD2 /* WidgetUnconfiguredCell.swift */; };
17331735
98906503237CC1DF00218CD2 /* WidgetUnconfiguredCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 989064FB237CC1DE00218CD2 /* WidgetUnconfiguredCell.swift */; };
17341736
98906504237CC1DF00218CD2 /* WidgetUnconfiguredCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 989064FC237CC1DE00218CD2 /* WidgetUnconfiguredCell.xib */; };
@@ -6363,6 +6365,7 @@
63636365
988AD63726B089CE003552B4 /* WordPress 128.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 128.xcdatamodel"; sourceTree = "<group>"; };
63646366
988F073323D0CE8800AC67A6 /* WidgetUrlCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetUrlCell.swift; sourceTree = "<group>"; };
63656367
988F073423D0CE8800AC67A6 /* WidgetUrlCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WidgetUrlCell.xib; sourceTree = "<group>"; };
6368+
988FD749279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCommentDetailCoordinator.swift; sourceTree = "<group>"; };
63666369
989064FB237CC1DE00218CD2 /* WidgetUnconfiguredCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidgetUnconfiguredCell.swift; sourceTree = "<group>"; };
63676370
989064FC237CC1DE00218CD2 /* WidgetUnconfiguredCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WidgetUnconfiguredCell.xib; sourceTree = "<group>"; };
63686371
989064FD237CC1DE00218CD2 /* WidgetTwoColumnCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidgetTwoColumnCell.swift; sourceTree = "<group>"; };
@@ -12974,9 +12977,10 @@
1297412977
B5E23BD919AD0CED000D6879 /* Tools */ = {
1297512978
isa = PBXGroup;
1297612979
children = (
12977-
B54E1DF31A0A7BBF00807537 /* NotificationMediaDownloader.swift */,
1297812980
B54075D31D3D7D5B0095C318 /* IntrinsicTableView.swift */,
1297912981
B56695AF1D411EEB007E342F /* KeyboardDismissHelper.swift */,
12982+
988FD749279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift */,
12983+
B54E1DF31A0A7BBF00807537 /* NotificationMediaDownloader.swift */,
1298012984
B5C0CF3C204DA41000DB0362 /* NotificationReplyStore.swift */,
1298112985
);
1298212986
path = Tools;
@@ -13056,15 +13060,15 @@
1305613060
B5FD453E199D0F2800286FBB /* Controllers */ = {
1305713061
isa = PBXGroup;
1305813062
children = (
13059-
B5DBE4FD1D21A700002E81D3 /* NotificationsViewController.swift */,
13060-
4388FEFD20A4E0B900783948 /* NotificationsViewController+AppRatings.swift */,
13061-
B5120B371D47CC6C0059361A /* NotificationDetailsViewController.swift */,
1306213063
7E987F552108017B00CAFB88 /* NotificationContentRouter.swift */,
13063-
B522C4F71B3DA79B00E47B59 /* NotificationSettingsViewController.swift */,
13064-
B52F8CD71B43260C00D36025 /* NotificationSettingStreamsViewController.swift */,
13064+
B5120B371D47CC6C0059361A /* NotificationDetailsViewController.swift */,
1306513065
B5899ADD1B419C560075A3D6 /* NotificationSettingDetailsViewController.swift */,
13066-
9F8E38BD209C6DE200454E3C /* NotificationSiteSubscriptionViewController.swift */,
13066+
B52F8CD71B43260C00D36025 /* NotificationSettingStreamsViewController.swift */,
13067+
B522C4F71B3DA79B00E47B59 /* NotificationSettingsViewController.swift */,
1306713068
B5F9959F1B59708C00AB0B3E /* NotificationSettingsViewController.xib */,
13069+
9F8E38BD209C6DE200454E3C /* NotificationSiteSubscriptionViewController.swift */,
13070+
B5DBE4FD1D21A700002E81D3 /* NotificationsViewController.swift */,
13071+
4388FEFD20A4E0B900783948 /* NotificationsViewController+AppRatings.swift */,
1306813072
8236EB4F2024ED8C007C7CF9 /* NotificationsViewController+JetpackPrompt.swift */,
1306913073
4388FEFF20A4E19C00783948 /* NotificationsViewController+PushPrimer.swift */,
1307013074
);
@@ -18353,6 +18357,7 @@
1835318357
E61084C01B9B47BA008050C5 /* ReaderListTopic.swift in Sources */,
1835418358
E6374DC11C444D8B00F24720 /* PublicizeService.swift in Sources */,
1835518359
7E4A773C20F80598001C706D /* ActivityContentFactory.swift in Sources */,
18360+
988FD74A279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift in Sources */,
1835618361
C81CCD83243BF7A600A83E27 /* TenorDataLoader.swift in Sources */,
1835718362
98797DBC222F434500128C21 /* OverviewCell.swift in Sources */,
1835818363
1749965F2271BF08007021BD /* WordPressAppDelegate.swift in Sources */,
@@ -20860,6 +20865,7 @@
2086020865
FABB26092602FC2C00C8785C /* PostListFooterView.m in Sources */,
2086120866
FABB260A2602FC2C00C8785C /* ThemeBrowserSearchHeaderView.swift in Sources */,
2086220867
FABB260B2602FC2C00C8785C /* MenuItemInsertionView.m in Sources */,
20868+
988FD74B279B75A400C7E814 /* NotificationCommentDetailCoordinator.swift in Sources */,
2086320869
FABB260C2602FC2C00C8785C /* AllTimeStatsRecordValue+CoreDataClass.swift in Sources */,
2086420870
FABB260D2602FC2C00C8785C /* GutenbergMediaEditorImage.swift in Sources */,
2086520871
FABB260E2602FC2C00C8785C /* NoteBlockHeaderTableViewCell.swift in Sources */,

0 commit comments

Comments
 (0)