X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FViewSonePage.java;h=a94b4afa785998ad71dc7cfe346ac3e4f57a077a;hb=60fda3f6fd8cd72151338c831f509dd8d9d0f9ff;hp=57d407094f2ac00a389a5d5dc9f44b29204b6908;hpb=7d5aff5d52afa5d9725ce252c846b1aca6f1a761;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index 57d4070..a94b4af 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 @@ -36,6 +36,8 @@ import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Optional; + /** * Lets the user browser another Sone. * @@ -65,9 +67,9 @@ public class ViewSonePage extends SoneTemplatePage { @Override protected String getPageTitle(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); - if ((sone != null) && (sone.getTime() > 0)) { - String soneName = SoneAccessor.getNiceName(sone); + Optional sone = webInterface.getCore().getSone(soneId); + if (sone.isPresent()) { + String soneName = SoneAccessor.getNiceName(sone.get()); return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title"); } return webInterface.getL10n().getString("Page.ViewSone.Page.TitleWithoutSone"); @@ -80,26 +82,26 @@ public class ViewSonePage extends SoneTemplatePage { 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); - templateContext.set("sone", sone); + Optional sone = webInterface.getCore().getSone(soneId); + templateContext.set("sone", sone.orNull()); templateContext.set("soneId", soneId); - if (sone == null) { + if (!sone.isPresent()) { return; } - List sonePosts = sone.getPosts(); - sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone)); + List sonePosts = sone.get().getPosts(); + sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.get().getId())); Collections.sort(sonePosts, Post.TIME_COMPARATOR); 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(); + Set replies = sone.get().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()))) { + Optional post = reply.getPost(); + if (!post.isPresent() || repliedPosts.containsKey(post.get()) || sone.get().equals(post.get().getSone()) || (sone.get().getId().equals(post.get().getRecipientId().orNull()))) { continue; } - repliedPosts.put(post, webInterface.getCore().getReplies(post)); + repliedPosts.put(post.get(), webInterface.getCore().getReplies(post.get().getId())); } List posts = new ArrayList(repliedPosts.keySet()); Collections.sort(posts, new Comparator() {