Skip to content

Commit b56d4e7

Browse files
authored
Reader: Update Reader hasMore API logic (#22597)
2 parents 4f2cdc3 + f290aed commit b56d4e7

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

API-Mocks/WordPressMocks/src/main/assets/mocks/__files/__admin/scenarios.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"state" : "Started",
1313
"possibleStates" : [ "Started", "initial_likes_list", "post_liked", "new_likes_list" ]
1414
},
15+
{
16+
"id" : "reader_subscriptions_flow",
17+
"name" : "reader_subscriptions_flow",
18+
"state" : "Started",
19+
"possibleStates" : [ "Started", "initial_subscriptions_list", "empty_subscriptions_list" ]
20+
},
1521
{
1622
"id" : "new_page_flow",
1723
"name" : "new_page_flow",

API-Mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/reader/rest_v12_read_following.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"scenarioName": "reader_subscriptions_flow",
3+
"requiredScenarioState": "Started",
4+
"newScenarioState": "initial_subscriptions_list",
25
"request": {
36
"method": "GET",
47
"urlPath": "/rest/v1.2/read/following"
@@ -1478,4 +1481,4 @@
14781481
"Cache-Control": "no-cache, must-revalidate, max-age=0"
14791482
}
14801483
}
1481-
}
1484+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"scenarioName": "reader_subscriptions_flow",
3+
"requiredScenarioState": "initial_subscriptions_list",
4+
"newScenarioState": "empty_subscriptions_list",
5+
"request": {
6+
"method": "GET",
7+
"urlPath": "/rest/v1.2/read/following"
8+
},
9+
"response": {
10+
"status": 200,
11+
"jsonBody": {
12+
"date_range": {
13+
"before": "2019-05-23T13:00:09+00:00",
14+
"after": "2021-05-17T16:34:44+00:00"
15+
},
16+
"number": 0,
17+
"posts": [
18+
]
19+
},
20+
"headers": {
21+
"Content-Type": "application/json",
22+
"Connection": "keep-alive",
23+
"Cache-Control": "no-cache, must-revalidate, max-age=0"
24+
}
25+
}
26+
}

WordPress/Classes/Services/Reader Post/ReaderPostService.m

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,7 @@ - (void)mergePosts:(NSArray *)remotePosts
768768
[self deletePostsFromBlockedSitesInContext:context];
769769

770770
BOOL spaceAvailable = ([self numberOfPostsForTopic:readerTopic inContext:context] < [self maxPostsToSaveForTopic:readerTopic]);
771-
if ([ReaderHelpers isTopicTag:readerTopic] || [ReaderHelpers isRSSFeed:readerTopic]) {
772-
// For tags and RSS feeds, assume there is more content as long as more than zero results are returned.
773-
hasMore = (postsCount > 0 ) && spaceAvailable;
774-
} else {
775-
// For other topics, assume there is more content as long as the number of results requested is returned.
776-
hasMore = ([remotePosts count] == [self numberToSyncForTopic:readerTopic]) && spaceAvailable;
777-
}
771+
hasMore = postsCount > 0 && spaceAvailable;
778772
} completion:^{
779773
if (success) {
780774
success(postsCount, hasMore);
@@ -1151,16 +1145,8 @@ - (ReaderPost *)createOrReplaceFromRemotePost:(RemoteReaderPost *)remotePost for
11511145
#pragma mark Internal
11521146

11531147
- (BOOL)canLoadMorePostsForTopic:(ReaderAbstractTopic * _Nonnull)readerTopic remotePosts:(NSArray * _Nonnull)remotePosts inContext: (NSManagedObjectContext * _Nonnull)context {
1154-
BOOL hasMore = NO;
11551148
BOOL spaceAvailable = ([self numberOfPostsForTopic:readerTopic inContext:context] < [self maxPostsToSaveForTopic:readerTopic]);
1156-
if ([ReaderHelpers isTopicTag:readerTopic] || [ReaderHelpers isRSSFeed:readerTopic]) {
1157-
// For tags and RSS feeds, assume there is more content as long as more than zero results are returned.
1158-
hasMore = ([remotePosts count] > 0 ) && spaceAvailable;
1159-
} else {
1160-
// For other topics, assume there is more content as long as the number of results requested is returned.
1161-
hasMore = ([remotePosts count] == [self numberToSyncForTopic:readerTopic]) && spaceAvailable;
1162-
}
1163-
return hasMore;
1149+
return [remotePosts count] > 0 && spaceAvailable;
11641150
}
11651151

11661152
@end

WordPress/UITests/Tests/ReaderTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ReaderTests: XCTestCase {
66
@MainActor
77
override func setUp() async throws {
88
setUpTestSuite()
9+
try await WireMock.setUpScenario(scenario: "reader_subscriptions_flow")
910
try await WireMock.setUpScenario(scenario: "reader_like_post_flow")
1011

1112
try LoginFlow

0 commit comments

Comments
 (0)