X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FNewPage.java;h=175795262fee1ef5cc8221cdb0e96f153b36bdee;hb=76ed638264e531a26e35647d13702db865a52321;hp=af7c1eca7cc3aa0c6961d4c2b6225a64866ba5da;hpb=d5efb086bee8f103cbe90c7a953ffbb7ff27b689;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/NewPage.java b/src/main/java/net/pterodactylus/sone/web/NewPage.java index af7c1ec..1757952 100644 --- a/src/main/java/net/pterodactylus/sone/web/NewPage.java +++ b/src/main/java/net/pterodactylus/sone/web/NewPage.java @@ -1,5 +1,5 @@ /* - * Sone - NewPage.java - Copyright © 2013 David Roden + * Sone - NewPage.java - Copyright © 2013–2015 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,12 +17,16 @@ package net.pterodactylus.sone.web; +import static net.pterodactylus.sone.utils.NumberParsers.parseInt; + import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import com.google.common.collect.Collections2; + import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.notify.ListNotificationFilters; @@ -31,9 +35,6 @@ import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; -import com.google.common.base.Optional; -import com.google.common.primitives.Ints; - /** * Page that displays all new posts and replies. The posts are filtered using * {@link ListNotificationFilters#filterPosts(java.util.Collection, net.pterodactylus.sone.data.Sone)} @@ -68,8 +69,8 @@ public class NewPage extends SoneTemplatePage { /* collect new elements from notifications. */ Set posts = new HashSet(webInterface.getNewPosts()); - for (PostReply reply : webInterface.getNewReplies()) { - posts.add(reply.getPost()); + for (PostReply reply : Collections2.filter(webInterface.getNewReplies(), PostReply.HAS_POST_FILTER)) { + posts.add(reply.getPost().get()); } /* filter and sort them. */ @@ -77,7 +78,7 @@ public class NewPage extends SoneTemplatePage { Collections.sort(sortedPosts, Post.TIME_COMPARATOR); /* paginate them. */ - Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("page"))).or(0)); + Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); }