Move post liking from Sone to Post.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / LikePage.java
index 960f32b..970b4c5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - LikePage.java - Copyright © 2010–2012 David Roden
+ * Sone - LikePage.java - Copyright © 2010–2013 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,8 @@ import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.util.web.Method;
 
+import com.google.common.base.Optional;
+
 /**
  * Page that lets the user like a {@link Post}.
  *
@@ -47,9 +49,6 @@ public class LikePage extends SoneTemplatePage {
        // TEMPLATEPAGE METHODS
        //
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
@@ -59,7 +58,10 @@ public class LikePage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
                        if ("post".equals(type)) {
-                               currentSone.addLikedPostId(id);
+                               Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+                               if (post.isPresent()) {
+                                       post.get().like(currentSone);
+                               }
                        } else if ("reply".equals(type)) {
                                currentSone.addLikedReplyId(id);
                        }