Mark all elements as known in the processing method, not after rendering.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 7 Apr 2011 09:13:12 +0000 (11:13 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 7 Apr 2011 09:13:12 +0000 (11:13 +0200)
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
src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java
src/main/java/net/pterodactylus/sone/web/SearchPage.java
src/main/java/net/pterodactylus/sone/web/ViewPostPage.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java

index 2d85e02..db48314 100644 (file)
@@ -77,21 +77,15 @@ public class IndexPage extends SoneTemplatePage {
                Pagination<Post> pagination = new Pagination<Post>(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<Post> posts = (List<Post>) 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);
                        }
                }
+
        }
 
 }
index c0e6364..6b1b4e3 100644 (file)
@@ -62,17 +62,9 @@ public class KnownSonesPage extends SoneTemplatePage {
                Pagination<Sone> sonePagination = new Pagination<Sone>(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<Sone> sones = (List<Sone>) templateContext.get("knownSones");
-               for (Sone sone : sones) {
+               /* mark Sones as known. */
+               for (Sone sone : sonePagination.getItems()) {
                        webInterface.getCore().markSoneKnown(sone);
                }
        }
index 2b854f3..73673ab 100644 (file)
@@ -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);
+                       }
+               }
        }
 
        //
index e528709..fe63b34 100644 (file)
@@ -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);
index c7edc32..82284d5 100644 (file)
@@ -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<Post> repliedPostPagination = new Pagination<Post>(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<Post> posts = (List<Post>) templateContext.get("posts");
-               posts.addAll((List<Post>) templateContext.get("repliedPosts"));
-               for (Post post : posts) {
+               for (Post post : new ListBuilder<Post>().addAll(postPagination.getItems()).addAll(repliedPostPagination.getItems()).get()) {
                        if (post.getSone() != null) {
                                webInterface.getCore().markPostKnown(post);
                        }