continue;
}
if (newPost.getTime() < getSoneFollowingTime(sone)) {
- newPost.setKnown(true);
+ newPost.setKnown();
} else if (!newPost.isKnown()) {
eventBus.post(new NewPostFoundEvent(newPost));
}
}
database.storePosts(sone, posts);
for (Post post : posts) {
- post.setKnown(true);
+ post.setKnown();
}
database.storePostReplies(sone, replies);
for (PostReply reply : replies) {
* The post to mark as known
*/
public void markPostKnown(Post post) {
- post.setKnown(true);
+ post.setKnown();
eventBus.post(new MarkPostKnownEvent(post));
touchConfiguration();
for (PostReply reply : post.getReplies()) {
/**
* Sets whether this post is known.
*
- * @param known
- * {@code true} if this post is known, {@code false} otherwise
* @return This post
*/
- public Post setKnown(boolean known);
+ public Post setKnown();
void like(Sone localSone);
void unlike(Sone localSone);
/** The text of the post. */
private final String text;
- /** Whether the post is known. */
- private volatile boolean known;
-
/**
* Creates a new post.
*
@Override
public boolean isKnown() {
- return known;
+ return database.isPostKnown(this);
}
@Override
- public DefaultPost setKnown(boolean known) {
- this.known = known;
+ public DefaultPost setKnown() {
+ database.setPostKnown(this);
return this;
}
*/
void removePosts(Sone sone);
+ void setPostKnown(Post post);
+ boolean isPostKnown(Post post);
void likePost(Post post, Sone localSone);
void unlikePost(Post post, Sone localSone);
boolean isLiked(Post post, Sone sone);
}
}
+ /**
+ * Returns whether the given post is known.
+ *
+ * @param post
+ * The post
+ * @return {@code true} if the post is known, {@code false} otherwise
+ */
+ @Override
+ public boolean isPostKnown(Post post) {
+ lock.readLock().lock();
+ try {
+ return knownPosts.contains(post.getId());
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Sets whether the given post is known.
+ *
+ * @param post
+ * The post
+ */
+ @Override
+ public void setPostKnown(Post post) {
+ lock.writeLock().lock();
+ try {
+ knownPosts.add(post.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
@Override
public void likePost(Post post, Sone localSone) {
lock.writeLock().lock();
}
//
- // PACKAGE-PRIVATE METHODS
- //
-
- /**
- * Returns whether the given post is known.
- *
- * @param post
- * The post
- * @return {@code true} if the post is known, {@code false} otherwise
- */
- boolean isPostKnown(Post post) {
- lock.readLock().lock();
- try {
- return knownPosts.contains(post.getId());
- } finally {
- lock.readLock().unlock();
- }
- }
-
- /**
- * Sets whether the given post is known.
- *
- * @param post
- * The post
- * @param known
- * {@code true} if the post is known, {@code false} otherwise
- */
- void setPostKnown(Post post, boolean known) {
- lock.writeLock().lock();
- try {
- if (known) {
- knownPosts.add(post.getId());
- } else {
- knownPosts.remove(post.getId());
- }
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- //
// PRIVATE METHODS
//