use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class Lbry method processErrorJson.
private static void processErrorJson(JSONObject json) throws JSONException, LbryResponseException {
if (json.has("error")) {
String errorMessage = null;
Object jsonError = json.get("error");
if (jsonError instanceof String) {
errorMessage = jsonError.toString();
} else {
errorMessage = ((JSONObject) jsonError).getString("message");
}
throw new LbryResponseException(!Helper.isNullOrEmpty(errorMessage) ? errorMessage : json.getString("error"));
} else {
throw new LbryResponseException("Protocol error with unknown response signature.");
}
}
use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class CommentListTask method doInBackground.
protected List<Comment> doInBackground(Void... voids) {
List<Comment> comments = null;
try {
Map<String, Object> options = new HashMap<>();
options.put("claim_id", claim);
options.put("page", page);
options.put("page_size", pageSize);
options.put("hidden", false);
options.put("include_replies", false);
options.put("is_channel_signature_valid", true);
options.put("skip_validation", true);
options.put("visible", true);
JSONObject result = (JSONObject) Lbry.parseResponse(Comments.performRequest(Lbry.buildJsonParams(options), "comment.List"));
if (result != null && result.has("items")) {
JSONArray items = result.getJSONArray("items");
List<Comment> children = new ArrayList<>();
comments = new ArrayList<>();
for (int i = 0; i < items.length(); i++) {
Comment comment = Comment.fromJSONObject(items.getJSONObject(i));
if (comment != null) {
if (!Helper.isNullOrEmpty(comment.getParentId())) {
children.add(comment);
} else {
comments.add(comment);
}
}
}
// Sort all replies from oldest to newest at once and then group them by its parent comment
Collections.sort(children);
Map<String, List<Comment>> groupedChildrenList = children.stream().collect(groupingBy(Comment::getParentId));
List<Comment> finalComments = comments;
groupedChildrenList.forEach((key, value) -> {
Comment c = finalComments.stream().filter(v -> key.equalsIgnoreCase(v.getId())).findFirst().orElse(null);
finalComments.addAll(finalComments.indexOf(c) + 1, value);
});
comments = finalComments;
}
} catch (JSONException | LbryResponseException | IOException ex) {
error = ex;
}
return comments;
}
Aggregations