From dc77f16b13bd6a728e1a9810c849621f70e8d46f Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 22 Jul 2021 14:29:24 -0400 Subject: [PATCH] fix comments paging issue --- .../repositories/responses/CommentsFetchResponse.kt | 3 +-- .../instagrabber/viewmodels/CommentsViewerViewModel.java | 5 +++-- .../java/awais/instagrabber/webservices/CommentService.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.kt index acf21eef..c7628bf8 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.kt @@ -5,6 +5,5 @@ import awais.instagrabber.models.Comment data class CommentsFetchResponse( val commentCount: Int, val nextMinId: String?, - val comments: List?, - val hasMoreComments: Boolean + val comments: List? ) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java index 21eb2b19..2d065f06 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java +++ b/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java @@ -32,6 +32,7 @@ import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.Utils; +import awais.instagrabber.utils.TextUtils; import awais.instagrabber.webservices.CommentService; import awais.instagrabber.webservices.GraphQLRepository; import awais.instagrabber.webservices.ServiceCallback; @@ -77,7 +78,7 @@ public class CommentsViewerViewModel extends ViewModel { comments = mergeList(rootList, comments); } rootCursor = result.getNextMinId(); - rootHasNext = result.getHasMoreComments(); + rootHasNext = !TextUtils.isEmpty(rootCursor); rootList.postValue(Resource.success(comments)); } @@ -233,7 +234,7 @@ public class CommentsViewerViewModel extends ViewModel { final Comment commentModel = getComment(commentsJsonArray.getJSONObject(i).getJSONObject("node"), root); builder.add(commentModel); } - final Object result = root ? new CommentsFetchResponse(count, endCursor, builder.build(), hasNextPage) + final Object result = root ? new CommentsFetchResponse(count, endCursor, builder.build()) : new ChildCommentsFetchResponse(count, endCursor, builder.build(), hasNextPage); //noinspection unchecked callback.onSuccess(result); diff --git a/app/src/main/java/awais/instagrabber/webservices/CommentService.java b/app/src/main/java/awais/instagrabber/webservices/CommentService.java index f67931e3..a1010119 100644 --- a/app/src/main/java/awais/instagrabber/webservices/CommentService.java +++ b/app/src/main/java/awais/instagrabber/webservices/CommentService.java @@ -70,11 +70,11 @@ public class CommentService { } public void fetchComments(@NonNull final String mediaId, - final String maxId, + final String minId, @NonNull final ServiceCallback callback) { final Map form = new HashMap<>(); form.put("can_support_threading", "true"); - if (maxId != null) form.put("max_id", maxId); + if (minId != null) form.put("min_id", minId); final Call request = repository.fetchComments(mediaId, form); request.enqueue(new Callback() { @Override