Add page that marks posts, replies, and Sones as read.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Jan 2011 14:45:45 +0000 (15:45 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Jan 2011 14:45:45 +0000 (15:45 +0100)
src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

diff --git a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java
new file mode 100644 (file)
index 0000000..3c1b6ab
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Sone - MarkReadPage.java - Copyright © 2011 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 java.util.StringTokenizer;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.template.DataProvider;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * Page that lets the user mark a number of {@link Sone}s, {@link Post}s, or
+ * {@link Reply Replie}s as known.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class MarkAsKnownPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “mark as known” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public MarkAsKnownPage(Template template, WebInterface webInterface) {
+               super("markAsKnown.html", template, "Page.MarkRead.Title", webInterface);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
+               super.processTemplate(request, dataProvider);
+               String type = request.getHttpRequest().getPartAsStringFailsafe("type", 5);
+               if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) {
+                       throw new RedirectException("invalid.html");
+               }
+               String ids = request.getHttpRequest().getPartAsStringFailsafe("id", 65536);
+               for (StringTokenizer idTokenizer = new StringTokenizer(ids); idTokenizer.hasMoreTokens();) {
+                       String id = idTokenizer.nextToken();
+                       System.out.println("id: " + id);
+                       if (type.equals("post")) {
+                               Post post = webInterface.getCore().getPost(id, false);
+                               if (post == null) {
+                                       continue;
+                               }
+                               webInterface.getCore().markPostKnown(post);
+                       } else if (type.equals("reply")) {
+                               Reply reply = webInterface.getCore().getReply(id, false);
+                               if (reply == null) {
+                                       continue;
+                               }
+                               webInterface.getCore().markReplyKnown(reply);
+                       } else if (type.equals("sone")) {
+                               Sone sone = webInterface.getCore().getSone(id, false);
+                               if (sone == null) {
+                                       continue;
+                               }
+                               webInterface.getCore().markSoneKnown(sone);
+                       }
+               }
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+               System.out.println("returnPage: " + returnPage);
+               throw new RedirectException(returnPage);
+       }
+
+}
index d08cc17..1c923fb 100644 (file)
@@ -526,6 +526,7 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustPage(emptyTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout"));