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=47f2715347b6bc8ea683aed402ce25235f608119;hpb=78cd820b392069def4640d45497e4097ef031d53;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 47f2715..db48314 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -19,12 +19,15 @@ package net.pterodactylus.sone.web; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; 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 @@ -41,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); } // @@ -52,35 +55,37 @@ public class IndexPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - Sone sone = getCurrentSone(request.getToadletContext()); + protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + Sone currentSone = getCurrentSone(request.getToadletContext()); List allPosts = new ArrayList(); - allPosts.addAll(sone.getPosts()); - for (Sone friendSone : sone.getFriends()) { - allPosts.addAll(friendSone.getPosts()); + allPosts.addAll(currentSone.getPosts()); + for (String friendSoneId : currentSone.getFriends()) { + if (!webInterface.getCore().hasSone(friendSoneId)) { + continue; + } + allPosts.addAll(webInterface.getCore().getSone(friendSoneId).getPosts()); } - Collections.sort(allPosts, new Comparator() { - - @Override - public int compare(Post leftPost, Post rightPost) { - return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime())); + 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()); - }); - template.set("posts", allPosts); - } - - // - // SONETEMPLATEPAGE METHODS - // + /* 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); + } + } - /** - * {@inheritDoc} - */ - @Override - protected boolean requiresLogin() { - return true; } }