1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

fix various comments bugs

1. redo ChildCommentsFetchResponse structure, stress-tested
2. navigation on more graph again
3. proper "next page" handling
This commit is contained in:
Austin Huang 2021-06-07 18:10:48 -04:00
parent 118fffc074
commit 544d9f87bc
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
5 changed files with 58 additions and 21 deletions

View File

@ -8,27 +8,30 @@ import awais.instagrabber.models.Comment;
public class ChildCommentsFetchResponse { public class ChildCommentsFetchResponse {
private final int childCommentCount; private final int childCommentCount;
private final String nextMinId; private final String nextMaxChildCursor;
private final List<Comment> childComments; private final List<Comment> childComments;
private final boolean hasMoreTailChildComments;
public ChildCommentsFetchResponse(final int childCommentCount, public ChildCommentsFetchResponse(final int childCommentCount,
final String nextMinId, // unconfirmed final String nextMaxChildCursor,
final List<Comment> childComments) { final List<Comment> childComments,
final boolean hasMoreTailChildComments) {
this.childCommentCount = childCommentCount; this.childCommentCount = childCommentCount;
this.nextMinId = nextMinId; this.nextMaxChildCursor = nextMaxChildCursor;
this.childComments = childComments; this.childComments = childComments;
this.hasMoreTailChildComments = hasMoreTailChildComments;
} }
public int getChildCommentCount() { public int getChildCommentCount() {
return childCommentCount; return childCommentCount;
} }
public String getNextMinId() { public String getNextMaxChildCursor() {
return nextMinId; return nextMaxChildCursor;
} }
public boolean hasNext() { public boolean getHasMoreTailChildComments() {
return nextMinId != null; return hasMoreTailChildComments;
} }
public List<Comment> getChildComments() { public List<Comment> getChildComments() {
@ -38,10 +41,11 @@ public class ChildCommentsFetchResponse {
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return "CommentsFetchResponse{" + return "ChildCommentsFetchResponse{" +
"childCommentCount=" + childCommentCount + "childCommentCount=" + childCommentCount +
", nextMinId='" + nextMinId + '\'' + ", nextMaxChildCursor='" + nextMaxChildCursor + '\'' +
", childComments=" + childComments + ", childComments=" + childComments +
", hasMoreTailChildComments=" + hasMoreTailChildComments +
'}'; '}';
} }
} }

View File

@ -10,13 +10,16 @@ public class CommentsFetchResponse {
private final int commentCount; private final int commentCount;
private final String nextMinId; private final String nextMinId;
private final List<Comment> comments; private final List<Comment> comments;
private final boolean hasMoreComments;
public CommentsFetchResponse(final int commentCount, public CommentsFetchResponse(final int commentCount,
final String nextMinId, final String nextMinId,
final List<Comment> comments) { final List<Comment> comments,
final boolean hasMoreComments) {
this.commentCount = commentCount; this.commentCount = commentCount;
this.nextMinId = nextMinId; this.nextMinId = nextMinId;
this.comments = comments; this.comments = comments;
this.hasMoreComments = hasMoreComments;
} }
public int getCommentCount() { public int getCommentCount() {
@ -27,14 +30,14 @@ public class CommentsFetchResponse {
return nextMinId; return nextMinId;
} }
public boolean hasNext() {
return nextMinId != null;
}
public List<Comment> getComments() { public List<Comment> getComments() {
return comments; return comments;
} }
public boolean getHasMoreComments() {
return hasMoreComments;
}
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
@ -42,6 +45,7 @@ public class CommentsFetchResponse {
"commentCount=" + commentCount + "commentCount=" + commentCount +
", nextMinId='" + nextMinId + '\'' + ", nextMinId='" + nextMinId + '\'' +
", comments=" + comments + ", comments=" + comments +
", hasMoreComments=" + hasMoreComments +
'}'; '}';
} }
} }

View File

@ -6,7 +6,7 @@ import java.io.Serializable
data class User @JvmOverloads constructor( data class User @JvmOverloads constructor(
val pk: Long = 0, val pk: Long = 0,
val username: String = "", val username: String = "",
val fullName: String = "", val fullName: String? = "",
val isPrivate: Boolean = false, val isPrivate: Boolean = false,
val profilePicUrl: String? = null, val profilePicUrl: String? = null,
val isVerified: Boolean = false, val isVerified: Boolean = false,

View File

@ -74,7 +74,7 @@ public class CommentsViewerViewModel extends ViewModel {
comments = mergeList(rootList, comments); comments = mergeList(rootList, comments);
} }
rootCursor = result.getNextMinId(); rootCursor = result.getNextMinId();
rootHasNext = result.hasNext(); rootHasNext = result.getHasMoreComments();
rootList.postValue(Resource.success(comments)); rootList.postValue(Resource.success(comments));
} }
@ -100,8 +100,8 @@ public class CommentsViewerViewModel extends ViewModel {
if (repliesCursor != null) { if (repliesCursor != null) {
comments = mergeList(replyList, comments); comments = mergeList(replyList, comments);
} }
repliesCursor = result.getNextMinId(); repliesCursor = result.getNextMaxChildCursor();
repliesHasNext = result.hasNext(); repliesHasNext = result.getHasMoreTailChildComments();
replyList.postValue(Resource.success(comments)); replyList.postValue(Resource.success(comments));
} }
@ -228,8 +228,8 @@ public class CommentsViewerViewModel extends ViewModel {
final Comment commentModel = getComment(commentsJsonArray.getJSONObject(i).getJSONObject("node"), root); final Comment commentModel = getComment(commentsJsonArray.getJSONObject(i).getJSONObject("node"), root);
builder.add(commentModel); builder.add(commentModel);
} }
final Object result = root ? new CommentsFetchResponse(count, endCursor, builder.build()) final Object result = root ? new CommentsFetchResponse(count, endCursor, builder.build(), hasNextPage)
: new ChildCommentsFetchResponse(count, endCursor, builder.build()); : new ChildCommentsFetchResponse(count, endCursor, builder.build(), hasNextPage);
//noinspection unchecked //noinspection unchecked
callback.onSuccess(result); callback.onSuccess(result);
} catch (Exception e) { } catch (Exception e) {

View File

@ -13,6 +13,35 @@
<include app:graph="@navigation/story_list_nav_graph" /> <include app:graph="@navigation/story_list_nav_graph" />
<include app:graph="@navigation/discover_nav_graph" /> <include app:graph="@navigation/discover_nav_graph" />
<action
android:id="@+id/action_global_commentsViewerFragment"
app:destination="@id/comments_nav_graph">
<argument
android:name="shortCode"
app:argType="string"
app:nullable="false" />
<argument
android:name="postId"
app:argType="string"
app:nullable="false" />
<argument
android:name="postUserId"
app:argType="long" />
</action>
<action
android:id="@+id/action_global_likesViewerFragment"
app:destination="@id/likes_nav_graph">
<argument
android:name="postId"
app:argType="string"
app:nullable="false" />
<argument
android:name="isComment"
app:argType="boolean"
app:nullable="false" />
</action>
<action <action
android:id="@+id/action_global_profileFragment" android:id="@+id/action_global_profileFragment"
app:destination="@id/profile_nav_graph"> app:destination="@id/profile_nav_graph">