added parent id to posts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package de.anxietyprime.swajodel;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class JodelPost {
|
||||
// id of the post
|
||||
public Long id;
|
||||
// id of the author in db
|
||||
private Long authorID;
|
||||
private final Long authorID;
|
||||
// anonymized authorID
|
||||
public Long anonymousID;
|
||||
// title of the post
|
||||
@@ -61,9 +61,10 @@ public class JodelPost {
|
||||
}
|
||||
|
||||
// add a comment if it is really a comment
|
||||
public boolean addComment(JodelPost post, long parent) {
|
||||
public boolean addComment(JodelPost post) {
|
||||
if (post.parent.isEmpty()) return true;
|
||||
// check if the post is a direct comment
|
||||
if (parent == this.id) {
|
||||
if (Objects.equals(post.parent.get(), this.id)) {
|
||||
// add the comment
|
||||
this.comments.add(post);
|
||||
// return success
|
||||
@@ -72,7 +73,7 @@ public class JodelPost {
|
||||
// recursively repeat this for all comments
|
||||
for (JodelPost comment : this.comments) {
|
||||
// return success if the post is a comment on a child
|
||||
if (comment.addComment(post, parent)) return true;
|
||||
if (comment.addComment(post)) return true;
|
||||
}
|
||||
// return no success
|
||||
return false;
|
||||
@@ -88,6 +89,7 @@ public class JodelPost {
|
||||
this.date = rs.getTimestamp("postdate");
|
||||
this.location = new Location(rs.getLong("longitude"), rs.getLong("latitude"));
|
||||
this.reactions = new Reactions(rs.getLong("positive"), rs.getLong("negative"));
|
||||
this.parent = Optional.of(rs.getLong("parent"));
|
||||
}
|
||||
|
||||
// constructor from authorID for tests
|
||||
@@ -115,4 +117,10 @@ public class JodelPost {
|
||||
public long getAuthorID() {
|
||||
return authorID;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isComment() {
|
||||
if (parent.isEmpty()) return false;
|
||||
return !Objects.equals(id, parent.get());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user