mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 19:38:22 +01:00
Improve removed thing not found detection.
This commit is contained in:
parent
ed679e835d
commit
3a88cacdde
@ -37,19 +37,19 @@ public class FetchRemovedComment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CommentData parseRemovedComment(JSONObject comment, CommentData commentData) throws JSONException {
|
private static CommentData parseRemovedComment(JSONObject result, CommentData comment) throws JSONException {
|
||||||
String id = comment.getString(JSONUtils.ID_KEY);
|
String id = result.getString(JSONUtils.ID_KEY);
|
||||||
if (id.equals(commentData.getId())) {
|
String author = result.getString(JSONUtils.AUTHOR_KEY);
|
||||||
String author = comment.getString(JSONUtils.AUTHOR_KEY);
|
String body = Utils.modifyMarkdown(result.optString(JSONUtils.BODY_KEY).trim());
|
||||||
String commentMarkdown = "";
|
|
||||||
if (!comment.isNull(JSONUtils.BODY_KEY)) {
|
|
||||||
commentMarkdown = Utils.modifyMarkdown(comment.getString(JSONUtils.BODY_KEY).trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
commentData.setAuthor(author);
|
if ( id.equals(comment.getId()) &&
|
||||||
commentData.setCommentMarkdown(commentMarkdown);
|
(!author.equals(comment.getAuthor()) ||
|
||||||
commentData.setCommentRawText(commentMarkdown);
|
!body.equals(comment.getCommentRawText()))
|
||||||
return commentData;
|
) {
|
||||||
|
comment.setAuthor(author);
|
||||||
|
comment.setCommentMarkdown(body);
|
||||||
|
comment.setCommentRawText(body);
|
||||||
|
return comment;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -40,26 +40,29 @@ public class FetchRemovedPost {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Post parseRemovedPost(JSONObject postJson, Post post) throws JSONException {
|
private static Post parseRemovedPost(JSONObject result, Post post) throws JSONException {
|
||||||
String id = postJson.getString(JSONUtils.ID_KEY);
|
String id = result.getString(JSONUtils.ID_KEY);
|
||||||
if (id.equals(post.getId())) {
|
String author = result.getString(JSONUtils.AUTHOR_KEY);
|
||||||
String author = postJson.getString(JSONUtils.AUTHOR_KEY);
|
String title = result.getString(JSONUtils.TITLE_KEY);
|
||||||
String title = postJson.getString(JSONUtils.TITLE_KEY);
|
String body = Utils.modifyMarkdown(result.getString(JSONUtils.SELFTEXT_KEY).trim());
|
||||||
String postContent = Utils.modifyMarkdown(postJson.getString(JSONUtils.SELFTEXT_KEY).trim());
|
|
||||||
|
|
||||||
|
if ( id.equals(post.getId()) &&
|
||||||
|
(!author.equals(post.getAuthor()) ||
|
||||||
|
foundSelfText(post.getSelfText(), body))
|
||||||
|
) {
|
||||||
post.setAuthor(author);
|
post.setAuthor(author);
|
||||||
post.setTitle(title);
|
post.setTitle(title);
|
||||||
post.setSelfText(postContent);
|
post.setSelfText(body);
|
||||||
post.setSelfTextPlain("");
|
post.setSelfTextPlain("");
|
||||||
post.setSelfTextPlainTrimmed("");
|
post.setSelfTextPlainTrimmed("");
|
||||||
|
|
||||||
String url = postJson.optString(JSONUtils.URL_KEY);
|
String url = result.optString(JSONUtils.URL_KEY);
|
||||||
|
|
||||||
if (url.endsWith("gif") || url.endsWith("mp4")) {
|
if (url.endsWith("gif") || url.endsWith("mp4")) {
|
||||||
post.setVideoUrl(url);
|
post.setVideoUrl(url);
|
||||||
post.setVideoDownloadUrl(url);
|
post.setVideoDownloadUrl(url);
|
||||||
} else if (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) {
|
} else if (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) {
|
||||||
JSONObject redditVideoObject = postJson.getJSONObject("secure_media").getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
|
JSONObject redditVideoObject = result.getJSONObject("secure_media").getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
|
||||||
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
|
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
|
||||||
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
|
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
|
||||||
|
|
||||||
@ -81,8 +84,8 @@ public class FetchRemovedPost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!postJson.isNull("thumbnail")) {
|
if (!result.isNull("thumbnail")) {
|
||||||
post.setThumbnailPreviewUrl(postJson.getString("thumbnail"));
|
post.setThumbnailPreviewUrl(result.getString("thumbnail"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return post;
|
return post;
|
||||||
@ -91,6 +94,11 @@ public class FetchRemovedPost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean foundSelfText(String oldText, String newText) {
|
||||||
|
return !(newText.equals("[deleted]") || newText.equals("[removed]")) &&
|
||||||
|
!newText.equals(oldText);
|
||||||
|
}
|
||||||
|
|
||||||
public interface FetchRemovedPostListener {
|
public interface FetchRemovedPostListener {
|
||||||
void fetchSuccess(Post post);
|
void fetchSuccess(Post post);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user