Move post liking from Sone to Post.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / LikeAjaxPage.java
index 6787711..ceeaf16 100644 (file)
@@ -21,7 +21,8 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.json.JsonObject;
+
+import com.google.common.base.Optional;
 
 /**
  * AJAX page that lets the user like a {@link Post}.
@@ -40,11 +41,8 @@ public class LikeAjaxPage extends JsonPage {
                super("like.ajax", webInterface);
        }
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
-       protected JsonObject createJsonObject(FreenetRequest request) {
+       protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String type = request.getHttpRequest().getParam("type", null);
                String id = request.getHttpRequest().getParam(type, null);
                if ((id == null) || (id.length() == 0)) {
@@ -55,7 +53,10 @@ 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);