Merge pull request #138 from OHermesJunior/improve-removed

Improve removed thing not found detection.
This commit is contained in:
Docile-Alligator 2020-06-22 16:44:14 +08:00 committed by GitHub
commit 51714b95ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View File

@ -37,19 +37,19 @@ public class FetchRemovedComment {
});
}
private static CommentData parseRemovedComment(JSONObject comment, CommentData commentData) throws JSONException {
String id = comment.getString(JSONUtils.ID_KEY);
if (id.equals(commentData.getId())) {
String author = comment.getString(JSONUtils.AUTHOR_KEY);
String commentMarkdown = "";
if (!comment.isNull(JSONUtils.BODY_KEY)) {
commentMarkdown = Utils.modifyMarkdown(comment.getString(JSONUtils.BODY_KEY).trim());
}
private static CommentData parseRemovedComment(JSONObject result, CommentData comment) throws JSONException {
String id = result.getString(JSONUtils.ID_KEY);
String author = result.getString(JSONUtils.AUTHOR_KEY);
String body = Utils.modifyMarkdown(result.optString(JSONUtils.BODY_KEY).trim());
commentData.setAuthor(author);
commentData.setCommentMarkdown(commentMarkdown);
commentData.setCommentRawText(commentMarkdown);
return commentData;
if ( id.equals(comment.getId()) &&
(!author.equals(comment.getAuthor()) ||
!body.equals(comment.getCommentRawText()))
) {
comment.setAuthor(author);
comment.setCommentMarkdown(body);
comment.setCommentRawText(body);
return comment;
} else {
return null;
}

View File

@ -40,26 +40,29 @@ public class FetchRemovedPost {
});
}
private static Post parseRemovedPost(JSONObject postJson, Post post) throws JSONException {
String id = postJson.getString(JSONUtils.ID_KEY);
if (id.equals(post.getId())) {
String author = postJson.getString(JSONUtils.AUTHOR_KEY);
String title = postJson.getString(JSONUtils.TITLE_KEY);
String postContent = Utils.modifyMarkdown(postJson.getString(JSONUtils.SELFTEXT_KEY).trim());
private static Post parseRemovedPost(JSONObject result, Post post) throws JSONException {
String id = result.getString(JSONUtils.ID_KEY);
String author = result.getString(JSONUtils.AUTHOR_KEY);
String title = result.getString(JSONUtils.TITLE_KEY);
String body = Utils.modifyMarkdown(result.getString(JSONUtils.SELFTEXT_KEY).trim());
if ( id.equals(post.getId()) &&
(!author.equals(post.getAuthor()) ||
foundSelfText(post.getSelfText(), body))
) {
post.setAuthor(author);
post.setTitle(title);
post.setSelfText(postContent);
post.setSelfText(body);
post.setSelfTextPlain("");
post.setSelfTextPlainTrimmed("");
String url = postJson.optString(JSONUtils.URL_KEY);
String url = result.optString(JSONUtils.URL_KEY);
if (url.endsWith("gif") || url.endsWith("mp4")) {
post.setVideoUrl(url);
post.setVideoDownloadUrl(url);
} 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 videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
@ -81,8 +84,8 @@ public class FetchRemovedPost {
}
}
if (!postJson.isNull("thumbnail")) {
post.setThumbnailPreviewUrl(postJson.getString("thumbnail"));
if (!result.isNull("thumbnail")) {
post.setThumbnailPreviewUrl(result.getString("thumbnail"));
}
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 {
void fetchSuccess(Post post);