Skip to content

Commit 8837ff9

Browse files
committed
Add offset param to fetchAuthors call
1 parent db8361c commit 8837ff9

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

WordPress/src/main/java/org/wordpress/android/ui/people/utils/PeopleUtils.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class PeopleUtils {
2525
// We limit followers we display to 1000 to avoid API performance issues
2626
public static final int FOLLOWER_PAGE_LIMIT = 50;
2727
public static final int FETCH_LIMIT = 20;
28-
public static final int FETCH_ALL_USERS_LIMIT = 1000;
28+
public static final int AUTHOR_FETCH_LIMIT = 100;
2929

3030
public static void fetchUsers(final SiteModel site, final int offset, final FetchUsersCallback callback) {
3131
RestRequest.Listener listener = new RestRequest.Listener() {
@@ -65,13 +65,15 @@ public void onErrorResponse(VolleyError volleyError) {
6565
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
6666
}
6767

68-
public static void fetchAuthors(final SiteModel site, final FetchUsersCallback callback) {
68+
public static void fetchAuthors(final SiteModel site, final int offset, final FetchUsersCallback callback) {
6969
RestRequest.Listener listener = jsonObject -> {
7070
if (jsonObject != null && callback != null) {
7171
try {
7272
JSONArray jsonArray = jsonObject.getJSONArray("users");
7373
List<Person> people = peopleListFromJSON(jsonArray, site.getId(), Person.PersonType.USER);
74-
callback.onSuccess(people, true);
74+
int numberOfUsers = jsonObject.optInt("found");
75+
boolean isEndOfList = (people.size() + offset) >= numberOfUsers;
76+
callback.onSuccess(people, isEndOfList);
7577
} catch (JSONException e) {
7678
AppLog.e(T.API, "JSON exception occurred while parsing the response for sites/%s/users: " + e);
7779
callback.onError();
@@ -87,8 +89,8 @@ public static void fetchAuthors(final SiteModel site, final FetchUsersCallback c
8789
};
8890

8991
Map<String, String> params = new HashMap<>();
90-
params.put("number", Integer.toString(PeopleUtils.FETCH_ALL_USERS_LIMIT));
91-
params.put("offset", "0");
92+
params.put("number", Integer.toString(PeopleUtils.AUTHOR_FETCH_LIMIT));
93+
params.put("offset", Integer.toString(offset));
9294
params.put("order_by", "display_name");
9395
params.put("order", "ASC");
9496
params.put("authors_only", "true");

WordPress/src/main/java/org/wordpress/android/ui/people/utils/PeopleUtilsWrapper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class PeopleUtilsWrapper @Inject constructor() {
2626

2727
fun fetchAuthors(
2828
site: SiteModel,
29+
offset: Int,
2930
callback: FetchUsersCallback
30-
) = PeopleUtils.fetchAuthors(site, callback)
31+
) = PeopleUtils.fetchAuthors(site, offset, callback)
3132

3233
fun fetchRevisionAuthorsDetails(
3334
site: SiteModel,

WordPress/src/test/java/org/wordpress/android/ui/posts/PublishSettingsViewModelTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ class PublishSettingsViewModelTest : BaseUnitTest() {
125125
whenever(siteStore.getSiteByLocalId(localSiteId)).thenReturn(site)
126126

127127
val peopleList = listOf(Person(1, 1), Person(2, 1))
128-
whenever(peopleUtilsWrapper.fetchAuthors(any(), any()))
129-
.then { it.getArgument<FetchUsersCallback>(1).onSuccess(peopleList, true) }
128+
whenever(peopleUtilsWrapper.fetchAuthors(any(), any(), any()))
129+
.then { it.getArgument<FetchUsersCallback>(2).onSuccess(peopleList, true) }
130130

131131
var authors = listOf<Person>()
132132
viewModel.authors.observeForever { authors = it }

0 commit comments

Comments
 (0)