Skip to content

Commit

Permalink
Merge pull request #17515 from wordpress-mobile/feature/17511-update_…
Browse files Browse the repository at this point in the history
…comment_fetching

Hierarchical Comments: add fetch method to provide count
  • Loading branch information
ScoutHarris authored Nov 22, 2021
2 parents 69ca695 + cb11cc9 commit d56a867
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def wordpress_ui
end

def wordpress_kit
pod 'WordPressKit', '~> 4.43.0'
pod 'WordPressKit', '~> 4.44.0-beta'
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :tag => ''
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => ''
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :commit => ''
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ PODS:
- WordPressKit (~> 4.18-beta)
- WordPressShared (~> 1.12-beta)
- WordPressUI (~> 1.7-beta)
- WordPressKit (4.43.0):
- WordPressKit (4.44.0-beta.1):
- Alamofire (~> 4.8.0)
- CocoaLumberjack (~> 3.4)
- NSObject-SafeExpectations (= 0.0.4)
Expand Down Expand Up @@ -553,7 +553,7 @@ DEPENDENCIES:
- SVProgressHUD (= 2.2.5)
- WordPress-Editor-iOS (~> 1.19.5)
- WordPressAuthenticator (~> 1.42.1)
- WordPressKit (~> 4.43.0)
- WordPressKit (~> 4.44.0-beta)
- WordPressMocks (~> 0.0.15)
- WordPressShared (~> 1.16.2)
- WordPressUI (~> 1.12.2)
Expand Down Expand Up @@ -810,7 +810,7 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: af36d9cb86a0109b568f516874870e2801ba1bd9
WordPress-Editor-iOS: 446be349b94707c1a82a83d525b86dbcf18cf2c7
WordPressAuthenticator: 111793c08fa8e9d9a72aed5b33a094c91ff4fd82
WordPressKit: ea1b285bae9156e387ddcbe2a7f919c0783a9b91
WordPressKit: 7fe46752fe65808f80163ae135bb5c3f081d108b
WordPressMocks: 6b52b0764d9939408151367dd9c6e8a910877f4d
WordPressShared: 6f4d949aa3ec8c3b9c24f5aa601473f087badd24
WordPressUI: c573f4b5c2e5d0ffcebe69ecf86ae75ab7b6ff4d
Expand All @@ -826,6 +826,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: e27423c004a5a1410c15933407747374e7c6cb6e

PODFILE CHECKSUM: 05f1d233304eca44dd7b86f86e966d786c29c86f
PODFILE CHECKSUM: 70e2c1b2bb057852c4af271041294e98678f6963

COCOAPODS: 1.10.1
10 changes: 8 additions & 2 deletions WordPress/Classes/Services/CommentService.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ extern NSUInteger const WPTopLevelHierarchicalCommentsPerPage;
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;

// Sync a list of comments sorted by hierarchy
// Sync a list of comments sorted by hierarchy, fetched by page number.
- (void)syncHierarchicalCommentsForPost:(ReaderPost *)post
page:(NSUInteger)page
success:(void (^)(NSInteger count, BOOL hasMore))success
success:(void (^)(BOOL hasMore, NSNumber *totalComments))success
failure:(void (^)(NSError *error))failure;

// Sync a list of comments sorted by hierarchy, restricted by the specified number of _top level_ comments.
- (void)syncHierarchicalCommentsForPost:(ReaderPost *)post
numberTopLevelComments:(NSUInteger)number
success:(void (^)(BOOL hasMore, NSNumber *totalComments))success
failure:(void (^)(NSError *error))failure;

// Counts and returns the number of full pages of hierarchcial comments synced for a post.
Expand Down
39 changes: 34 additions & 5 deletions WordPress/Classes/Services/CommentService.m
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,47 @@ - (void)deleteComment:(Comment *)comment

- (void)syncHierarchicalCommentsForPost:(ReaderPost *)post
page:(NSUInteger)page
success:(void (^)(NSInteger count, BOOL hasMore))success
success:(void (^)(BOOL hasMore, NSNumber *totalComments))success
failure:(void (^)(NSError *error))failure
{
[self syncHierarchicalCommentsForPost:post
page:page
numberTopLevelComments:WPTopLevelHierarchicalCommentsPerPage
success:success
failure:failure];
}

- (void)syncHierarchicalCommentsForPost:(ReaderPost *)post
number:(NSUInteger)number
success:(void (^)(BOOL hasMore, NSNumber *totalComments))success
failure:(void (^)(NSError *error))failure
{
[self syncHierarchicalCommentsForPost:post
page:1
numberTopLevelComments:number
success:success
failure:failure];
}

- (void)syncHierarchicalCommentsForPost:(ReaderPost *)post
page:(NSUInteger)page
numberTopLevelComments:(NSUInteger)number
success:(void (^)(BOOL hasMore, NSNumber *totalComments))success
failure:(void (^)(NSError *error))failure
{
NSManagedObjectID *postObjectID = post.objectID;
NSNumber *siteID = post.siteID;
NSNumber *postID = post.postID;

NSUInteger commentsPerPage = number ?: WPTopLevelHierarchicalCommentsPerPage;
NSUInteger pageNumber = page ?: 1;

[self.managedObjectContext performBlock:^{
CommentServiceRemoteREST *service = [self restRemoteForSite:siteID];
[service syncHierarchicalCommentsForPost:postID
page:page
number:WPTopLevelHierarchicalCommentsPerPage
success:^(NSArray *comments) {
page:pageNumber
number:commentsPerPage
success:^(NSArray *comments, NSNumber *totalComments) {
[self.managedObjectContext performBlock:^{
NSError *error;
ReaderPost *aPost = (ReaderPost *)[self.managedObjectContext existingObjectWithID:postObjectID error:&error];
Expand Down Expand Up @@ -554,7 +583,7 @@ - (void)syncHierarchicalCommentsForPost:(ReaderPost *)post
}

dispatch_async(dispatch_get_main_queue(), ^{
success([comments count], hasMore);
success(hasMore, totalComments);
});
}];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ - (void)syncHelper:(WPContentSyncHelper *)syncHelper syncContentWithUserInteract
{
self.failedToFetchComments = NO;
CommentService *service = [[CommentService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] newDerivedContext]];
[service syncHierarchicalCommentsForPost:self.post page:1 success:^(NSInteger count, BOOL hasMore) {
[service syncHierarchicalCommentsForPost:self.post page:1 success:^(BOOL hasMore, NSNumber *totalComments) {
if (success) {
success(hasMore);
}
Expand All @@ -993,7 +993,7 @@ - (void)syncHelper:(WPContentSyncHelper *)syncHelper syncMoreWithSuccess:(void (

CommentService *service = [[CommentService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] newDerivedContext]];
NSInteger page = [service numberOfHierarchicalPagesSyncedforPost:self.post] + 1;
[service syncHierarchicalCommentsForPost:self.post page:page success:^(NSInteger count, BOOL hasMore) {
[service syncHierarchicalCommentsForPost:self.post page:page success:^(BOOL hasMore, NSNumber *totalComments) {
if (success) {
success(hasMore);
}
Expand Down

0 comments on commit d56a867

Please sign in to comment.