public Post setKnown(boolean known);
public void like(Sone localSone);
+ public void unlike(Sone localSone);
List<PostReply> getReplies();
boolean isLikedPostId(String postId);
/**
- * Removes the given post ID from the list of posts this Sone likes.
- *
- * @param postId
- * The ID of the post
- * @return This Sone (for method chaining)
- */
- Sone removeLikedPostId(String postId);
-
- /**
* Returns the IDs of all liked replies.
*
* @return All liked replies’ IDs
}
@Override
+ public void unlike(Sone localSone) {
+ database.unlikePost(this, localSone);
+ }
+
+ @Override
public List<PostReply> getReplies() {
return from(database.getReplies(getId())).toSortedList(Reply.TIME_COMPARATOR);
}
void removePosts(Sone sone);
void likePost(Post post, Sone localSone);
+ void unlikePost(Post post, Sone localSone);
}
}
}
+ @Override
+ public void unlikePost(Post post, Sone localSone) {
+ lock.writeLock().lock();
+ try {
+ likedPosts.remove(localSone.getId(), post.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
//
// POSTSTORE METHODS
//
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.web.Method;
+import com.google.common.base.Optional;
+
/**
* Page that lets the user unlike a {@link Post}.
*
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
Sone currentSone = getCurrentSone(request.getToadletContext());
if ("post".equals(type)) {
- currentSone.removeLikedPostId(id);
+ Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+ if (post.isPresent()) {
+ post.get().unlike(currentSone);
+ }
} else if ("reply".equals(type)) {
currentSone.removeLikedReplyId(id);
}
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
+import com.google.common.base.Optional;
+
/**
* AJAX page that lets the user unlike a {@link Post}.
*
return createErrorJsonObject("auth-required");
}
if ("post".equals(type)) {
- currentSone.removeLikedPostId(id);
+ Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+ if (post.isPresent()) {
+ post.get().unlike(currentSone);
+ }
webInterface.getCore().touchConfiguration();
} else if ("reply".equals(type)) {
currentSone.removeLikedReplyId(id);