From: David ‘Bombe’ Roden Date: Thu, 7 Apr 2011 09:13:12 +0000 (+0200) Subject: Mark all elements as known in the processing method, not after rendering. X-Git-Tag: 0.6.1^2~26^2~8 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9ee1da2306234248b6077946fc254d8436fb4bd1;p=Sone.git Mark all elements as known in the processing method, not after rendering. This allows to react to changes in the notification with JavaScript, in order to mark elements on the page as known without having the currently reloading page clear everything in all tabs. --- diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index 2d85e02..db48314 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -77,21 +77,15 @@ public class IndexPage extends SoneTemplatePage { Pagination pagination = new Pagination(allPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); - } - /** - * {@inheritDoc} - */ - @Override - protected void postProcess(Request request, TemplateContext templateContext) { - @SuppressWarnings("unchecked") - List posts = (List) templateContext.get("posts"); - for (Post post : posts) { + /* 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); } } + } } diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index c0e6364..6b1b4e3 100644 --- a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java @@ -62,17 +62,9 @@ public class KnownSonesPage extends SoneTemplatePage { Pagination sonePagination = new Pagination(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", sonePagination); templateContext.set("knownSones", sonePagination.getItems()); - } - /** - * {@inheritDoc} - */ - @Override - protected void postProcess(Request request, TemplateContext templateContext) { - super.postProcess(request, templateContext); - @SuppressWarnings("unchecked") - List sones = (List) templateContext.get("knownSones"); - for (Sone sone : sones) { + /* mark Sones as known. */ + for (Sone sone : sonePagination.getItems()) { webInterface.getCore().markSoneKnown(sone); } } diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 2b854f3..73673ab 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -110,6 +110,17 @@ public class SearchPage extends SoneTemplatePage { templateContext.set("soneHits", sonePagination.getItems()); templateContext.set("postPagination", postPagination); templateContext.set("postHits", postPagination.getItems()); + + /* mark found posts and Sones as knew. */ + for (Sone sone : sonePagination.getItems()) { + webInterface.getCore().markSoneKnown(sone); + } + for (Post post : postPagination.getItems()) { + webInterface.getCore().markPostKnown(post); + for (Reply reply : webInterface.getCore().getReplies(post)) { + webInterface.getCore().markReplyKnown(reply); + } + } } // diff --git a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java index e528709..fe63b34 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java @@ -73,17 +73,6 @@ public class ViewPostPage extends SoneTemplatePage { Post post = webInterface.getCore().getPost(postId); templateContext.set("post", post); templateContext.set("raw", raw); - } - - /** - * {@inheritDoc} - */ - @Override - protected void postProcess(Request request, TemplateContext templateContext) { - Post post = (Post) templateContext.get("post"); - if (post == null) { - return; - } webInterface.getCore().markPostKnown(post); for (Reply reply : webInterface.getCore().getReplies(post)) { webInterface.getCore().markReplyKnown(reply); diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index c7edc32..82284d5 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -29,6 +29,7 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.template.SoneAccessor; +import net.pterodactylus.util.collection.ListBuilder; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; @@ -108,22 +109,10 @@ public class ViewSonePage extends SoneTemplatePage { Pagination repliedPostPagination = new Pagination(posts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("repliedPostPage"), 0)); templateContext.set("repliedPostPagination", repliedPostPagination); templateContext.set("repliedPosts", repliedPostPagination.getItems()); - } - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("unchecked") - protected void postProcess(Request request, TemplateContext templateContext) { - Sone sone = (Sone) templateContext.get("sone"); - if (sone == null) { - return; - } + /* mark Sone and posts and replies as known. */ webInterface.getCore().markSoneKnown(sone); - List posts = (List) templateContext.get("posts"); - posts.addAll((List) templateContext.get("repliedPosts")); - for (Post post : posts) { + for (Post post : new ListBuilder().addAll(postPagination.getItems()).addAll(repliedPostPagination.getItems()).get()) { if (post.getSone() != null) { webInterface.getCore().markPostKnown(post); }