X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FViewSonePage.java;h=f216431534e799e3abd5e329c6367dc715fc3243;hp=c7edc32e33e9bb17844272d67be2a57359b7f28a;hb=d535f744751ba449e0f34fe3a42f1020988f14be;hpb=52a5187a49bde69f9fffb361c644a115e40fdf0a diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index c7edc32..f216431 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -1,5 +1,5 @@ /* - * Sone - ViewSonePage.java - Copyright © 2010 David Roden + * Sone - ViewSonePage.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 @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -26,9 +27,10 @@ import java.util.Map; import java.util.Set; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.template.SoneAccessor; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; @@ -61,9 +63,9 @@ public class ViewSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected String getPageTitle(Request request) { + protected String getPageTitle(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); if ((sone != null) && (sone.getTime() > 0)) { String soneName = SoneAccessor.getNiceName(sone); return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title"); @@ -75,20 +77,24 @@ public class ViewSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); templateContext.set("sone", sone); + templateContext.set("soneId", soneId); + if (sone == null) { + return; + } List sonePosts = sone.getPosts(); - sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone)); + sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.getId())); Collections.sort(sonePosts, Post.TIME_COMPARATOR); - Pagination postPagination = new Pagination(sonePosts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0)); + Pagination postPagination = new Pagination(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0)); templateContext.set("postPagination", postPagination); templateContext.set("posts", postPagination.getItems()); - Set replies = sone.getReplies(); - final Map> repliedPosts = new HashMap>(); - for (Reply reply : replies) { + Set replies = sone.getReplies(); + final Map> repliedPosts = new HashMap>(); + for (PostReply reply : replies) { Post post = reply.getPost(); if (repliedPosts.containsKey(post) || sone.equals(post.getSone()) || (sone.equals(post.getRecipient()))) { continue; @@ -105,7 +111,7 @@ public class ViewSonePage extends SoneTemplatePage { }); - Pagination repliedPostPagination = new Pagination(posts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("repliedPostPage"), 0)); + Pagination repliedPostPagination = new Pagination(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("repliedPostPage"), 0)); templateContext.set("repliedPostPagination", repliedPostPagination); templateContext.set("repliedPosts", repliedPostPagination.getItems()); } @@ -114,23 +120,8 @@ public class ViewSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - @SuppressWarnings("unchecked") - protected void postProcess(Request request, TemplateContext templateContext) { - Sone sone = (Sone) templateContext.get("sone"); - if (sone == null) { - return; - } - webInterface.getCore().markSoneKnown(sone); - List posts = (List) templateContext.get("posts"); - posts.addAll((List) templateContext.get("repliedPosts")); - for (Post post : posts) { - if (post.getSone() != null) { - webInterface.getCore().markPostKnown(post); - } - for (Reply reply : webInterface.getCore().getReplies(post)) { - webInterface.getCore().markReplyKnown(reply); - } - } + public boolean isLinkExcepted(URI link) { + return true; } }