Skip to content

Commit

Permalink
Merge trunk into merge/release-19.2.0.0-into-trunk – Again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mokagio committed Feb 8, 2022
2 parents c48d330 + ecef425 commit fe79495
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .buildkite/cache-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ steps:
- label: ":cocoapods: Rebuild CocoaPods cache"
command: |
echo "--- :rubygems: Setting up Gems"
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
gem install bundler:2.3.6
install_gems
echo "--- :cocoapods: Rebuilding Pod Cache"
Expand Down
4 changes: 4 additions & 0 deletions .buildkite/commands/installable-build-jetpack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
echo "--- :rubygems: Fixing Ruby Setup"
gem install bundler

# FIXIT-13.1: Installable Builds want the latest version of Sentry CLI
brew update
brew upgrade sentry-cli

echo "--- :rubygems: Setting up Gems"
install_gems

Expand Down
4 changes: 4 additions & 0 deletions .buildkite/commands/installable-build-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
echo "--- :rubygems: Fixing Ruby Setup"
gem install bundler

# FIXIT-13.1: Installable Builds want the latest version of Sentry CLI
brew update
brew upgrade sentry-cli

echo "--- :rubygems: Setting up Gems"
install_gems

Expand Down
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
19.3
-----

* [*] Stats: fix navigation between Stats tab. [#17894]

19.2
-----
Expand Down
8 changes: 7 additions & 1 deletion WordPress/Classes/Services/CommentService.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ extern NSUInteger const WPTopLevelHierarchicalCommentsPerPage;
withStatus:(CommentStatusFilter)status
success:(void (^)(BOOL hasMore))success
failure:(void (^)(NSError *))failure;


// Load a single comment
- (void)loadCommentWithID:(NSNumber *_Nonnull)commentID
forBlog:(Blog *_Nonnull)blog
success:(void (^_Nullable)(Comment *_Nullable))success
failure:(void (^_Nullable)(NSError *_Nullable))failure;

// Upload comment
- (void)uploadComment:(Comment *)comment
success:(void (^)(void))success
Expand Down
43 changes: 43 additions & 0 deletions WordPress/Classes/Services/CommentService.m
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,49 @@ - (void)loadMoreCommentsForBlog:(Blog *)blog
}];
}

- (void)loadCommentWithID:(NSNumber *)commentID
forBlog:(Blog *)blog
success:(void (^)(Comment *comment))success
failure:(void (^)(NSError *))failure {

NSManagedObjectID *blogID = blog.objectID;
id<CommentServiceRemote> remote = [self remoteForBlog:blog];

[remote getCommentWithID:commentID
success:^(RemoteComment *remoteComment) {
[self.managedObjectContext performBlock:^{
Blog *blog = (Blog *)[self.managedObjectContext existingObjectWithID:blogID error:nil];
if (!blog) {
return;
}

Comment *comment = [self findCommentWithID:remoteComment.commentID inBlog:blog];
if (!comment) {
comment = [self createCommentForBlog:blog];
}

[self updateComment:comment withRemoteComment:remoteComment];

[[ContextManager sharedInstance] saveContext:self.managedObjectContext withCompletionBlock:^{
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
success(comment);
});
}
}];
}];
} failure:^(NSError *error) {
DDLogError(@"Error loading comment for blog: %@", error);
[self.managedObjectContext performBlock:^{
if (failure) {
dispatch_async(dispatch_get_main_queue(), ^{
failure(error);
});
}
}];
}];
}

// Upload comment
- (void)uploadComment:(Comment *)comment
success:(void (^)(void))success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,42 +706,49 @@ extension NotificationsViewController {

// Display Details
//
if let postID = note.metaPostID, let siteID = note.metaSiteID, note.kind == .matcher || note.kind == .newPost {
if let postID = note.metaPostID,
let siteID = note.metaSiteID,
note.kind == .matcher || note.kind == .newPost {
let readerViewController = ReaderDetailViewController.controllerWithPostID(postID, siteID: siteID)
readerViewController.navigationItem.largeTitleDisplayMode = .never
showDetailViewController(readerViewController, sender: nil)

return
}

presentCommentDetail(for: note)
}

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

view.isUserInteractionEnabled = false

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

// For now, NotificationCommentDetailCoordinator only loads the Comment if it is cached.
// If the comment is not cached, fall back to showing the old comment view.
// This is temporary until NotificationCommentDetailCoordinator can fetch the comment from the endpoint.
notificationCommentDetailCoordinator.createViewController { commentDetailViewController in
guard let commentDetailViewController = commentDetailViewController else {
// TODO: show error view
return
}

if let commentDetailViewController = notificationCommentDetailCoordinator.viewController {
commentDetailViewController.navigationItem.largeTitleDisplayMode = .never
self.showDetailViewController(commentDetailViewController, sender: nil)
} else {
// TODO: remove when NotificationCommentDetailCoordinator updated to fetch comment.
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
self.view.isUserInteractionEnabled = true
}
} else {
self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)

return
}

self.performSegue(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces(), sender: note)
self.view.isUserInteractionEnabled = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class NotificationCommentDetailCoordinator: NSObject {
private let notification: Notification
private var comment: Comment?
private let managedObjectContext = ContextManager.shared.mainContext
private(set) var viewController: CommentDetailViewController?
private var viewController: CommentDetailViewController?
private var commentID: NSNumber?
private var blog: Blog?

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

init(notification: Notification) {
self.notification = notification
commentID = notification.metaCommentID

if let siteID = notification.metaSiteID {
blog = Blog.lookup(withID: siteID, in: managedObjectContext)
}

super.init()
loadCommentFromCache()
}

// MARK: - Public Methods

func createViewController(completion: @escaping (CommentDetailViewController?) -> Void) {
if let comment = loadCommentFromCache() {
createViewController(comment: comment)
completion(viewController)
return
}

fetchComment(completion: { comment in
guard let comment = comment else {
// TODO: show error view
completion(nil)
return
}

self.createViewController(comment: comment)
completion(self.viewController)
})
}

}
Expand All @@ -29,15 +57,36 @@ class NotificationCommentDetailCoordinator: NSObject {

private extension NotificationCommentDetailCoordinator {

func loadCommentFromCache() {
guard let siteID = notification.metaSiteID,
let commentID = notification.metaCommentID,
let blog = Blog.lookup(withID: siteID, in: managedObjectContext),
let comment = commentService.findComment(withID: commentID, in: blog) else {
DDLogError("Notification Comment: failed loading comment from cache.")
func loadCommentFromCache() -> Comment? {
guard let commentID = commentID,
let blog = blog else {
DDLogError("Notification Comment: unable to load comment due to missing information.")
// TODO: show error view
return nil
}

return commentService.findComment(withID: commentID, in: blog)
}

func fetchComment(completion: @escaping (Comment?) -> Void) {
guard let commentID = commentID,
let blog = blog else {
DDLogError("Notification Comment: unable to fetch comment due to missing information.")
// TODO: show error view
completion(nil)
return
}

// TODO: show loading view

commentService.loadComment(withID: commentID, for: blog, success: { comment in
completion(comment)
}, failure: { error in
// TODO: show error view
})
}

func createViewController(comment: Comment) {
self.comment = comment
viewController = CommentDetailViewController(comment: comment,
notification: notification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
WPAnalytics.track(.statsItemSelectedAddInsight, withProperties: ["insight": insight.title])
insightsToShow.append(insightType)
updateView()
scrollToNewCard()
}

func addInsightDismissed() {
Expand All @@ -572,6 +573,18 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
viewNeedsUpdating = false
}

func scrollToNewCard() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
guard let self = self else { return }
let lastSection = max(self.tableView.numberOfSections - 1, 0)

// newly added card will be penultimate row, above the 'Add Stats Card' row
let newCardRow = max(self.tableView.numberOfRows(inSection: lastSection) - 2, 0)

self.tableView.scrollToRow(at: IndexPath(row: newCardRow, section: lastSection), at: .middle, animated: true)
}
}

func manageInsightSelected(_ insight: StatSection, fromButton: UIButton) {

guard let insightType = insight.insightType else {
Expand Down

0 comments on commit fe79495

Please sign in to comment.