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);
}
}
+
}
}
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);
}
}
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);
+ }
+ }
}
//
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);
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;
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);
}