From: David ‘Bombe’ Roden Date: Tue, 5 Nov 2013 20:48:25 +0000 (+0100) Subject: Move isLikedPostId from Sone to Post. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6abff3e875d253a011c73574f2a6012a28af279a;p=Sone.git Move isLikedPostId from Sone to Post. --- diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index 474f9d1..36db3a3 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -128,6 +128,7 @@ public interface Post extends Identified { public void like(Sone localSone); public void unlike(Sone localSone); + boolean isLiked(Sone sone); Set getLikes(); List getReplies(); diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index e340bdf..44929c6 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -408,16 +408,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { Sone setLikePostIds(Set likedPostIds); /** - * Checks whether the given post ID is liked by this Sone. - * - * @param postId - * The ID of the post - * @return {@code true} if this Sone likes the given post, {@code false} - * otherwise - */ - boolean isLikedPostId(String postId); - - /** * Returns the IDs of all liked replies. * * @return All liked replies’ IDs diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java index 587add9..a1204f9 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java @@ -139,6 +139,11 @@ public class DefaultPost implements Post { } @Override + public boolean isLiked(Sone sone) { + return database.isLiked(this, sone); + } + + @Override public Set getLikes() { return database.getLikes(this); } diff --git a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java index a25f245..d8956db 100644 --- a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java @@ -102,6 +102,7 @@ public interface PostDatabase { void likePost(Post post, Sone localSone); void unlikePost(Post post, Sone localSone); + boolean isLiked(Post post, Sone sone); Set getLikes(Post post); } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 975b8ab..bdc247e 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -309,6 +309,15 @@ public class MemoryDatabase extends AbstractService implements Database { } } + public boolean isLiked(Post post, Sone sone) { + lock.readLock().lock(); + try { + return likedPostsBySone.containsEntry(sone, post); + } finally { + lock.readLock().unlock(); + } + } + @Override public Set getLikes(Post post) { lock.readLock().lock(); diff --git a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java index c3f9de3..26a05db 100644 --- a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java @@ -59,7 +59,7 @@ public class PostAccessor extends ReflectionAccessor { return post.getLikes(); } else if (member.equals("liked")) { Sone currentSone = (Sone) templateContext.get("currentSone"); - return (currentSone != null) && (currentSone.isLikedPostId(post.getId())); + return (currentSone != null) && post.isLiked(currentSone); } else if (member.equals("new")) { return !post.isKnown(); } else if (member.equals("bookmarked")) {