X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FIndexPage.java;h=db48314e874f13f582de886280abf3ecef3e67e8;hb=9ee1da2306234248b6077946fc254d8436fb4bd1;hp=0e72938b5f89aa55f77da025a6b1822d28aeed4e;hpb=a76953c600f2078049dc12bf1dcbab416716b776;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index 0e72938..db48314 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -17,7 +17,17 @@ package net.pterodactylus.sone.web; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.collection.Pagination; +import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; /** * The index page shows the main page of Sone. This page will contain the posts @@ -34,7 +44,7 @@ public class IndexPage extends SoneTemplatePage { * The Sone web interface */ public IndexPage(Template template, WebInterface webInterface) { - super("index.html", template, "Page.Index.Title", webInterface); + super("index.html", template, "Page.Index.Title", webInterface, true); } // @@ -45,8 +55,37 @@ public class IndexPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected boolean requiresLogin() { - return true; + protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + Sone currentSone = getCurrentSone(request.getToadletContext()); + List allPosts = new ArrayList(); + allPosts.addAll(currentSone.getPosts()); + for (String friendSoneId : currentSone.getFriends()) { + if (!webInterface.getCore().hasSone(friendSoneId)) { + continue; + } + allPosts.addAll(webInterface.getCore().getSone(friendSoneId).getPosts()); + } + for (Sone sone : webInterface.getCore().getSones()) { + for (Post post : sone.getPosts()) { + if (currentSone.equals(post.getRecipient()) && !allPosts.contains(post)) { + allPosts.add(post); + } + } + } + Collections.sort(allPosts, Post.TIME_COMPARATOR); + Pagination pagination = new Pagination(allPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); + templateContext.set("pagination", pagination); + templateContext.set("posts", pagination.getItems()); + + /* mark it all as known. */ + for (Post post : pagination.getItems()) { + webInterface.getCore().markPostKnown(post); + for (Reply reply : webInterface.getCore().getReplies(post)) { + webInterface.getCore().markReplyKnown(reply); + } + } + } }