X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FUnbookmarkPage.java;h=9cc266e844af92b2639dc6d692adb389e71644c9;hp=85a0359b12da474bd53c603b9ee9779e588f2cd1;hb=9acbc5bdec4ccb752e0856a501568b0bb6161579;hpb=6e98888ca9440b004c7d65786ea47c4f263de7b2 diff --git a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java index 85a0359..9cc266e 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java @@ -1,5 +1,5 @@ /* - * Sone - BookmarkPage.java - Copyright © 2011 David Roden + * Sone - UnbookmarkPage.java - Copyright © 2011–2016 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 @@ -17,9 +17,15 @@ package net.pterodactylus.sone.web; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import java.util.Set; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.web.page.FreenetRequest; 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 unbookmark a post. @@ -46,14 +52,26 @@ public class UnbookmarkPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { - super.processTemplate(request, templateContext); + protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException { if (request.getMethod() == Method.POST) { String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); - webInterface.getCore().unbookmarkPost(id); + Optional post = webInterface.getCore().getPost(id); + if (post.isPresent()) { + webInterface.getCore().unbookmarkPost(post.get()); + } throw new RedirectException(returnPage); } + String id = request.getHttpRequest().getParam("post"); + if (id.equals("allNotLoaded")) { + Set posts = webInterface.getCore().getBookmarkedPosts(); + for (Post post : posts) { + if (!post.isLoaded()) { + webInterface.getCore().unbookmarkPost(post); + } + } + throw new RedirectException("bookmarks.html"); + } } }