Improve PeertubeCommentsInfoItemExtractor constructor

This commit is contained in:
TobiGr 2023-05-07 22:53:24 +02:00
parent aff3e795f8
commit d358ba1c41
2 changed files with 13 additions and 11 deletions

View File

@ -54,7 +54,7 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
}
}
boolean isReply() throws ParsingException {
private boolean isReply() throws ParsingException {
if (isReply == null) {
if (getOriginalUrl().contains("/videos/watch/")) {
isReply = false;
@ -73,7 +73,8 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
if (c instanceof JsonObject) {
final JsonObject item = (JsonObject) c;
if (!item.getBoolean(IS_DELETED)) {
collector.commit(new PeertubeCommentsInfoItemExtractor(item, null, this));
collector.commit(new PeertubeCommentsInfoItemExtractor(
item, null, getUrl(), getBaseUrl(), isReply()));
}
}
}
@ -89,7 +90,8 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
final JsonObject item = content.getObject("comment");
final JsonArray children = content.getArray(CHILDREN);
if (!item.getBoolean(IS_DELETED)) {
collector.commit(new PeertubeCommentsInfoItemExtractor(item, children, this));
collector.commit(new PeertubeCommentsInfoItemExtractor(
item, children, getUrl(), getBaseUrl(), isReply()));
}
}
}

View File

@ -31,20 +31,20 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
private final String url;
@Nonnull
private final String baseUrl;
@Nonnull
private final PeertubeCommentsExtractor superCommentExtractor;
private final boolean isReply;
private Integer replyCount;
public PeertubeCommentsInfoItemExtractor(@Nonnull final JsonObject item,
@Nullable final JsonArray children,
@Nonnull final PeertubeCommentsExtractor extractor)
throws ParsingException {
@Nonnull final String url,
@Nonnull final String baseUrl,
final boolean isReply) {
this.item = item;
this.children = children;
this.url = extractor.getUrl();
this.baseUrl = extractor.getBaseUrl();
this.superCommentExtractor = extractor;
this.url = url;
this.baseUrl = baseUrl;
this.isReply = isReply;
}
@Override
@ -130,7 +130,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
}
final String threadId = JsonUtils.getNumber(item, "threadId").toString();
final String repliesUrl = url + "/" + threadId;
if (superCommentExtractor.isReply() && children != null && !children.isEmpty()) {
if (isReply && children != null && !children.isEmpty()) {
// Nested replies are already included in the original thread's request.
// Wrap the replies into a JsonObject, because the original thread's request body
// is also structured like a JsonObject.