Merge branch 'release-0.9.6'
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ViewPostPage.java
index 3bc3b36..56bac8d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - ViewPostPage.java - Copyright © 2010 David Roden
+ * Sone - ViewPostPage.java - Copyright © 2010–2016 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
 
 package net.pterodactylus.sone.web;
 
+import java.net.URI;
+
+import com.google.common.base.Optional;
+
 import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
 
 /**
  * This page lets the user view a post and all its replies.
@@ -48,23 +54,36 @@ public class ViewPostPage extends SoneTemplatePage {
         * {@inheritDoc}
         */
        @Override
-       protected void processTemplate(Request request, Template template) throws RedirectException {
-               super.processTemplate(request, template);
+       protected String getPageTitle(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId);
-               template.set("post", post);
+               Optional<Post> post = webInterface.getCore().getPost(postId);
+               String title = "";
+               if (post.isPresent()) {
+                       title = post.get().getText().substring(0, Math.min(20, post.get().getText().length())) + "…";
+                       title += " - " + SoneAccessor.getNiceName(post.get().getSone()) + " - ";
+               }
+               title += webInterface.getL10n().getString("Page.ViewPost.Title");
+               return title;
        }
 
        /**
         * {@inheritDoc}
         */
        @Override
-       protected void postProcess(Request request, Template template) {
-               Post post = (Post) template.get("post");
-               webInterface.getCore().markPostKnown(post);
-               for (Reply reply : webInterface.getCore().getReplies(post)) {
-                       webInterface.getCore().markReplyKnown(reply);
-               }
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               String postId = request.getHttpRequest().getParam("post");
+               boolean raw = request.getHttpRequest().getParam("raw").equals("true");
+               Optional<Post> post = webInterface.getCore().getPost(postId);
+               templateContext.set("post", post.orNull());
+               templateContext.set("raw", raw);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isLinkExcepted(URI link) {
+               return true;
        }
 
 }