Skip to content

Commit fe79495

Browse files
committed
Merge trunk into merge/release-19.2.0.0-into-trunk – Again
Unfortunately, the PR (#17900 (comment)), couldn't be merged yesterday, so new conflicts arose. There was one one `Podfile.lock` in the checksum field. I solved by re-running `bundle exec pod install` after the merge to generate an up-to-date value. Git auto-resolved a conflict on the `RELEASE-NOTES.txt` file in an incorrect way: it kept both new line after the 19.3 header and the first entry for that version. I overwrote it by removing the new line.
2 parents c48d330 + ecef425 commit fe79495

9 files changed

Lines changed: 150 additions & 21 deletions

File tree

.buildkite/cache-builder.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ steps:
2626
- label: ":cocoapods: Rebuild CocoaPods cache"
2727
command: |
2828
echo "--- :rubygems: Setting up Gems"
29+
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
30+
gem install bundler:2.3.6
31+
2932
install_gems
3033
3134
echo "--- :cocoapods: Rebuilding Pod Cache"

.buildkite/commands/installable-build-jetpack.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
echo "--- :rubygems: Fixing Ruby Setup"
55
gem install bundler
66

7+
# FIXIT-13.1: Installable Builds want the latest version of Sentry CLI
8+
brew update
9+
brew upgrade sentry-cli
10+
711
echo "--- :rubygems: Setting up Gems"
812
install_gems
913

.buildkite/commands/installable-build-wordpress.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
echo "--- :rubygems: Fixing Ruby Setup"
55
gem install bundler
66

7+
# FIXIT-13.1: Installable Builds want the latest version of Sentry CLI
8+
brew update
9+
brew upgrade sentry-cli
10+
711
echo "--- :rubygems: Setting up Gems"
812
install_gems
913

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
19.3
22
-----
3-
3+
* [*] Stats: fix navigation between Stats tab. [#17894]
44

55
19.2
66
-----

WordPress/Classes/Services/CommentService.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ extern NSUInteger const WPTopLevelHierarchicalCommentsPerPage;
6464
withStatus:(CommentStatusFilter)status
6565
success:(void (^)(BOOL hasMore))success
6666
failure:(void (^)(NSError *))failure;
67-
67+
68+
// Load a single comment
69+
- (void)loadCommentWithID:(NSNumber *_Nonnull)commentID
70+
forBlog:(Blog *_Nonnull)blog
71+
success:(void (^_Nullable)(Comment *_Nullable))success
72+
failure:(void (^_Nullable)(NSError *_Nullable))failure;
73+
6874
// Upload comment
6975
- (void)uploadComment:(Comment *)comment
7076
success:(void (^)(void))success

WordPress/Classes/Services/CommentService.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,49 @@ - (void)loadMoreCommentsForBlog:(Blog *)blog
358358
}];
359359
}
360360

361+
- (void)loadCommentWithID:(NSNumber *)commentID
362+
forBlog:(Blog *)blog
363+
success:(void (^)(Comment *comment))success
364+
failure:(void (^)(NSError *))failure {
365+
366+
NSManagedObjectID *blogID = blog.objectID;
367+
id<CommentServiceRemote> remote = [self remoteForBlog:blog];
368+
369+
[remote getCommentWithID:commentID
370+
success:^(RemoteComment *remoteComment) {
371+
[self.managedObjectContext performBlock:^{
372+
Blog *blog = (Blog *)[self.managedObjectContext existingObjectWithID:blogID error:nil];
373+
if (!blog) {
374+
return;
375+
}
376+
377+
Comment *comment = [self findCommentWithID:remoteComment.commentID inBlog:blog];
378+
if (!comment) {
379+
comment = [self createCommentForBlog:blog];
380+
}
381+
382+
[self updateComment:comment withRemoteComment:remoteComment];
383+
384+
[[ContextManager sharedInstance] saveContext:self.managedObjectContext withCompletionBlock:^{
385+
if (success) {
386+
dispatch_async(dispatch_get_main_queue(), ^{
387+
success(comment);
388+
});
389+
}
390+
}];
391+
}];
392+
} failure:^(NSError *error) {
393+
DDLogError(@"Error loading comment for blog: %@", error);
394+
[self.managedObjectContext performBlock:^{
395+
if (failure) {
396+
dispatch_async(dispatch_get_main_queue(), ^{
397+
failure(error);
398+
});
399+
}
400+
}];
401+
}];
402+
}
403+
361404
// Upload comment
362405
- (void)uploadComment:(Comment *)comment
363406
success:(void (^)(void))success

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -706,42 +706,49 @@ extension NotificationsViewController {
706706

707707
// Display Details
708708
//
709-
if let postID = note.metaPostID, let siteID = note.metaSiteID, note.kind == .matcher || note.kind == .newPost {
709+
if let postID = note.metaPostID,
710+
let siteID = note.metaSiteID,
711+
note.kind == .matcher || note.kind == .newPost {
710712
let readerViewController = ReaderDetailViewController.controllerWithPostID(postID, siteID: siteID)
711713
readerViewController.navigationItem.largeTitleDisplayMode = .never
712714
showDetailViewController(readerViewController, sender: nil)
713715

714716
return
715717
}
716718

719+
presentCommentDetail(for: note)
720+
}
721+
722+
private func presentCommentDetail(for note: Notification) {
717723
// This dispatch avoids a bug that was occurring occasionally where navigation (nav bar and tab bar)
718724
// would be missing entirely when launching the app from the background and presenting a notification.
719725
// The issue seems tied to performing a `pop` in `prepareToShowDetails` and presenting
720726
// the new detail view controller at the same time. More info: https://github.com/wordpress-mobile/WordPress-iOS/issues/6976
721727
//
722728
// Plus: Avoid pushing multiple DetailsViewController's, upon quick & repeated touch events.
723-
//
729+
724730
view.isUserInteractionEnabled = false
725731

726732
DispatchQueue.main.async {
727733
if FeatureFlag.notificationCommentDetails.enabled,
728734
note.kind == .comment {
729735
let notificationCommentDetailCoordinator = NotificationCommentDetailCoordinator(notification: note)
730736

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.
737+
notificationCommentDetailCoordinator.createViewController { commentDetailViewController in
738+
guard let commentDetailViewController = commentDetailViewController else {
739+
// TODO: show error view
740+
return
741+
}
734742

735-
if let commentDetailViewController = notificationCommentDetailCoordinator.viewController {
736743
commentDetailViewController.navigationItem.largeTitleDisplayMode = .never
737744
self.showDetailViewController(commentDetailViewController, sender: nil)
738-
} else {
739-
// TODO: remove when NotificationCommentDetailCoordinator updated to fetch comment.
740-
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
745+
self.view.isUserInteractionEnabled = true
741746
}
742-
} else {
743-
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
747+
748+
return
744749
}
750+
751+
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
745752
self.view.isUserInteractionEnabled = true
746753
}
747754
}

WordPress/Classes/ViewRelated/Notifications/Tools/NotificationCommentDetailCoordinator.swift

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class NotificationCommentDetailCoordinator: NSObject {
99
private let notification: Notification
1010
private var comment: Comment?
1111
private let managedObjectContext = ContextManager.shared.mainContext
12-
private(set) var viewController: CommentDetailViewController?
12+
private var viewController: CommentDetailViewController?
13+
private var commentID: NSNumber?
14+
private var blog: Blog?
1315

1416
private lazy var commentService: CommentService = {
1517
return .init(managedObjectContext: managedObjectContext)
@@ -19,8 +21,34 @@ class NotificationCommentDetailCoordinator: NSObject {
1921

2022
init(notification: Notification) {
2123
self.notification = notification
24+
commentID = notification.metaCommentID
25+
26+
if let siteID = notification.metaSiteID {
27+
blog = Blog.lookup(withID: siteID, in: managedObjectContext)
28+
}
29+
2230
super.init()
23-
loadCommentFromCache()
31+
}
32+
33+
// MARK: - Public Methods
34+
35+
func createViewController(completion: @escaping (CommentDetailViewController?) -> Void) {
36+
if let comment = loadCommentFromCache() {
37+
createViewController(comment: comment)
38+
completion(viewController)
39+
return
40+
}
41+
42+
fetchComment(completion: { comment in
43+
guard let comment = comment else {
44+
// TODO: show error view
45+
completion(nil)
46+
return
47+
}
48+
49+
self.createViewController(comment: comment)
50+
completion(self.viewController)
51+
})
2452
}
2553

2654
}
@@ -29,15 +57,36 @@ class NotificationCommentDetailCoordinator: NSObject {
2957

3058
private extension NotificationCommentDetailCoordinator {
3159

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.")
60+
func loadCommentFromCache() -> Comment? {
61+
guard let commentID = commentID,
62+
let blog = blog else {
63+
DDLogError("Notification Comment: unable to load comment due to missing information.")
64+
// TODO: show error view
65+
return nil
66+
}
67+
68+
return commentService.findComment(withID: commentID, in: blog)
69+
}
70+
71+
func fetchComment(completion: @escaping (Comment?) -> Void) {
72+
guard let commentID = commentID,
73+
let blog = blog else {
74+
DDLogError("Notification Comment: unable to fetch comment due to missing information.")
75+
// TODO: show error view
76+
completion(nil)
3877
return
3978
}
4079

80+
// TODO: show loading view
81+
82+
commentService.loadComment(withID: commentID, for: blog, success: { comment in
83+
completion(comment)
84+
}, failure: { error in
85+
// TODO: show error view
86+
})
87+
}
88+
89+
func createViewController(comment: Comment) {
4190
self.comment = comment
4291
viewController = CommentDetailViewController(comment: comment,
4392
notification: notification,

WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
561561
WPAnalytics.track(.statsItemSelectedAddInsight, withProperties: ["insight": insight.title])
562562
insightsToShow.append(insightType)
563563
updateView()
564+
scrollToNewCard()
564565
}
565566

566567
func addInsightDismissed() {
@@ -572,6 +573,18 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
572573
viewNeedsUpdating = false
573574
}
574575

576+
func scrollToNewCard() {
577+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
578+
guard let self = self else { return }
579+
let lastSection = max(self.tableView.numberOfSections - 1, 0)
580+
581+
// newly added card will be penultimate row, above the 'Add Stats Card' row
582+
let newCardRow = max(self.tableView.numberOfRows(inSection: lastSection) - 2, 0)
583+
584+
self.tableView.scrollToRow(at: IndexPath(row: newCardRow, section: lastSection), at: .middle, animated: true)
585+
}
586+
}
587+
575588
func manageInsightSelected(_ insight: StatSection, fromButton: UIButton) {
576589

577590
guard let insightType = insight.insightType else {

0 commit comments

Comments
 (0)