Move reply like functionality from Sone to Reply.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / LikeAjaxPage.java
index 55a947a..84a93e3 100644 (file)
 package net.pterodactylus.sone.web.ajax;
 
 import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 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 like a {@link Post}.
  *
@@ -39,9 +42,6 @@ public class LikeAjaxPage extends JsonPage {
                super("like.ajax", webInterface);
        }
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
        protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String type = request.getHttpRequest().getParam("type", null);
@@ -54,10 +54,16 @@ public class LikeAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                if ("post".equals(type)) {
-                       currentSone.addLikedPostId(id);
+                       Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+                       if (post.isPresent()) {
+                               post.get().like(currentSone);
+                       }
                        webInterface.getCore().touchConfiguration();
                } else if ("reply".equals(type)) {
-                       currentSone.addLikedReplyId(id);
+                       Optional<PostReply> postReply = webInterface.getCore().getDatabase().getPostReply(id);
+                       if (postReply.isPresent()) {
+                               postReply.get().like(currentSone);
+                       }
                        webInterface.getCore().touchConfiguration();
                } else {
                        return createErrorJsonObject("invalid-type");