From 9ee1da2306234248b6077946fc254d8436fb4bd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 7 Apr 2011 11:13:12 +0200 Subject: [PATCH] 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. --- src/main/java/net/pterodactylus/sone/web/IndexPage.java | 12 +++--------- .../java/net/pterodactylus/sone/web/KnownSonesPage.java | 12 ++---------- .../java/net/pterodactylus/sone/web/SearchPage.java | 11 +++++++++++ .../java/net/pterodactylus/sone/web/ViewPostPage.java | 11 ----------- .../java/net/pterodactylus/sone/web/ViewSonePage.java | 17 +++-------------- 5 files changed, 19 insertions(+), 44 deletions(-) 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); } -- 2.7.4