From: David ‘Bombe’ Roden Date: Mon, 17 Jan 2011 14:45:45 +0000 (+0100) Subject: Add page that marks posts, replies, and Sones as read. X-Git-Tag: 0.4.2^2~27^2~9 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=d3b65841aac0702c8cb8a6ac2907792743ea3d2b Add page that marks posts, replies, and Sones as read. --- 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 index 0000000..3c1b6ab --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index d08cc17..1c923fb 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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"));