Use a more general way to like something.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 Oct 2010 11:23:08 +0000 (13:23 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 Oct 2010 11:23:08 +0000 (13:23 +0200)
src/main/java/net/pterodactylus/sone/web/LikePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/LikePostPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UnlikePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/templates/include/viewPost.html
src/main/resources/templates/like.html [new file with mode: 0644]
src/main/resources/templates/likePost.html [deleted file]
src/main/resources/templates/unlike.html [new file with mode: 0644]
src/main/resources/templates/unlikePost.html [deleted file]

diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java
new file mode 100644 (file)
index 0000000..e9d79ba
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Sone - LikePage.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * Page that lets the user like a {@link Post}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LikePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “like post” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public LikePage(Template template, WebInterface webInterface) {
+               super("like.html", template, "Page.LikePost.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               if (request.getMethod() == Method.POST) {
+                       String type=request.getHttpRequest().getPartAsStringFailsafe("type", 16);
+                       String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       if ("post".equals(type)) {
+                               currentSone.addLikedPostId(id);
+                       } else if ("reply".equals(type)) {
+                               currentSone.addLikedReplyId(id);
+                       }
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected boolean requiresLogin() {
+               return true;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/LikePostPage.java b/src/main/java/net/pterodactylus/sone/web/LikePostPage.java
deleted file mode 100644 (file)
index 991627e..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Sone - LikePostPage.java - Copyright © 2010 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.Template;
-
-/**
- * Page that lets the user like a {@link Post}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class LikePostPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “like post” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public LikePostPage(Template template, WebInterface webInterface) {
-               /* TODO */
-               super("likePost.html", template, "Page.LikePost.Title", webInterface);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void processTemplate(Request request, Template template) throws RedirectException {
-               super.processTemplate(request, template);
-               if (request.getMethod() == Method.POST) {
-                       String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       currentSone.addLikedPostId(postId);
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected boolean requiresLogin() {
-               return true;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java
new file mode 100644 (file)
index 0000000..bedf759
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Sone - UnlikePage.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * Page that lets the user unlike a {@link Post}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UnlikePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “unlike post” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public UnlikePage(Template template, WebInterface webInterface) {
+               super("unlike.html", template, "Page.UnlikePost.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               if (request.getMethod() == Method.POST) {
+                       String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
+                       String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       if ("post".equals(type)) {
+                               currentSone.removeLikedPostId(id);
+                       } else if ("reply".equals(type)) {
+                               currentSone.removeLikedReplyId(id);
+                       }
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected boolean requiresLogin() {
+               return true;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java
deleted file mode 100644 (file)
index b325b5e..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Sone - UnlikePostPage.java - Copyright © 2010 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.Template;
-
-/**
- * Page that lets the user unlike a {@link Post}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UnlikePostPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “unlike post” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UnlikePostPage(Template template, WebInterface webInterface) {
-               super("unlikePost.html", template, "Page.UnlikePost.Title", webInterface);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void processTemplate(Request request, Template template) throws RedirectException {
-               super.processTemplate(request, template);
-               if (request.getMethod() == Method.POST) {
-                       String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       currentSone.removeLikedPostId(postId);
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected boolean requiresLogin() {
-               return true;
-       }
-
-}
index bb7f740..d809580 100644 (file)
@@ -202,8 +202,8 @@ public class WebInterface extends AbstractService {
                Template blockSoneTemplate = templateFactory.createTemplate(createReader("/templates/blockSone.html"));
                Template unblockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unblockSone.html"));
                Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
-               Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/likePost.html"));
-               Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlikePost.html"));
+               Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/like.html"));
+               Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html"));
                Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
                Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
                Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
@@ -226,8 +226,8 @@ public class WebInterface extends AbstractService {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new BlockSonePage(blockSoneTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UnblockSonePage(unblockSoneTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePostPage(likePostTemplate, this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePostPage(unlikePostTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(likePostTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
index 991ccec..d212c39 100644 (file)
@@ -7,15 +7,17 @@
                <div class="time"><a href="viewPost.html?post=<% post.id|html>"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></a></div>
                <div class="likes<%if post.likes.size|match value=0> hidden<%/if>"><span>⬆<span class="like-count"><% post.likes.size></span></span></div>
                <%ifnull ! currentSone>
-                       <form class="like<%if post.liked> hidden<%/if>" action="likePost.html" method="post">
+                       <form class="like<%if post.liked> hidden<%/if>" action="like.html" method="post">
                                <input type="hidden" name="formPassword" value="<% formPassword|html>" />
                                <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+                               <input type="hidden" name="type" value="post" />
                                <input type="hidden" name="post" value="<% post.id|html>" />
                                <button type="submit" value="1"><%= View.Post.LikeLink|l10n|html></button>
                        </form>
-                       <form class="unlike<%if ! post.liked> hidden<%/if>" action="unlikePost.html" method="post">
+                       <form class="unlike<%if ! post.liked> hidden<%/if>" action="unlike.html" method="post">
                                <input type="hidden" name="formPassword" value="<% formPassword|html>" />
                                <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+                               <input type="hidden" name="type" value="post" />
                                <input type="hidden" name="post" value="<% post.id|html>" />
                                <button type="submit" value="1"><%= View.Post.UnlikeLink|l10n|html></button>
                        </form>
diff --git a/src/main/resources/templates/like.html b/src/main/resources/templates/like.html
new file mode 100644 (file)
index 0000000..196af72
--- /dev/null
@@ -0,0 +1,3 @@
+<%include include/head.html>
+
+<%include include/tail.html>
diff --git a/src/main/resources/templates/likePost.html b/src/main/resources/templates/likePost.html
deleted file mode 100644 (file)
index 196af72..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<%include include/head.html>
-
-<%include include/tail.html>
diff --git a/src/main/resources/templates/unlike.html b/src/main/resources/templates/unlike.html
new file mode 100644 (file)
index 0000000..196af72
--- /dev/null
@@ -0,0 +1,3 @@
+<%include include/head.html>
+
+<%include include/tail.html>
diff --git a/src/main/resources/templates/unlikePost.html b/src/main/resources/templates/unlikePost.html
deleted file mode 100644 (file)
index 196af72..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<%include include/head.html>
-
-<%include include/tail.html>