Add posts a Sone replied to to “view Sone” page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Apr 2011 20:44:32 +0000 (22:44 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Apr 2011 20:44:32 +0000 (22:44 +0200)
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/static/images/sone-avatar.png [new file with mode: 0644]
src/main/resources/templates/include/viewPost.html
src/main/resources/templates/viewSone.html

index 0792a6f..3f4d92d 100644 (file)
 
 package net.pterodactylus.sone.web;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 
@@ -57,12 +65,35 @@ public class ViewSonePage extends SoneTemplatePage {
                String soneId = request.getHttpRequest().getParam("sone");
                Sone sone = webInterface.getCore().getSone(soneId, false);
                templateContext.set("sone", sone);
+               Set<Reply> replies = sone.getReplies();
+               final Map<Post, List<Reply>> repliedPosts = new HashMap<Post, List<Reply>>();
+               for (Reply reply : replies) {
+                       Post post = reply.getPost();
+                       if (repliedPosts.containsKey(post) || sone.equals(post.getSone())) {
+                               continue;
+                       }
+                       repliedPosts.put(post, webInterface.getCore().getReplies(post));
+               }
+               List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
+               Collections.sort(posts, new Comparator<Post>() {
+
+                       @Override
+                       public int compare(Post leftPost, Post rightPost) {
+                               return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, repliedPosts.get(rightPost).get(0).getTime() - repliedPosts.get(leftPost).get(0).getTime()));
+                       }
+
+               });
+
+               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) {
@@ -70,8 +101,11 @@ public class ViewSonePage extends SoneTemplatePage {
                }
                webInterface.getCore().markSoneKnown(sone);
                List<Post> posts = sone.getPosts();
+               posts.addAll((List<Post>) templateContext.get("repliedPosts"));
                for (Post post : posts) {
-                       webInterface.getCore().markPostKnown(post);
+                       if (post.getSone() != null) {
+                               webInterface.getCore().markPostKnown(post);
+                       }
                        for (Reply reply : webInterface.getCore().getReplies(post)) {
                                webInterface.getCore().markReplyKnown(reply);
                        }
index c8604cb..104d3c7 100644 (file)
@@ -125,6 +125,7 @@ Page.ViewSone.PostList.Title=Posts by {sone}
 Page.ViewSone.PostList.Text.NoPostYet=This Sone has not yet posted anything.
 Page.ViewSone.Profile.Title=Profile
 Page.ViewSone.Profile.Label.Name=Name
+Page.ViewSone.Replies.Title=Replies to Posts
 
 Page.ViewPost.Title=View Post - Sone
 Page.ViewPost.Page.Title=View Post by {sone}
@@ -222,6 +223,7 @@ View.Post.Reply.DeleteLink=Delete
 View.Post.LikeLink=Like
 View.Post.UnlikeLink=Unlike
 View.Post.ShowSource=Toggle Parser
+View.Post.NotDownloaded=This post has not yet been downloaded, or it has been deleted.
 
 View.UpdateStatus.Text.ChooseSenderIdentity=Choose the sender identity
 
diff --git a/src/main/resources/static/images/sone-avatar.png b/src/main/resources/static/images/sone-avatar.png
new file mode 100644 (file)
index 0000000..0339b5a
Binary files /dev/null and b/src/main/resources/static/images/sone-avatar.png differ
index 4600d45..4be1bcc 100644 (file)
@@ -3,10 +3,14 @@
        <div class="post-time hidden"><% post.time|html></div>
        <div class="post-author hidden"><% post.sone.id|html></div>
        <div class="avatar">
-               <img src="/WebOfTrust/GetIdenticon?identity=<% post.sone.id|html>&amp;width=48&height=48" width="48" height="48" alt="Avatar Image" />
+               <%if post.loaded>
+                       <img src="/WebOfTrust/GetIdenticon?identity=<% post.sone.id|html>&amp;width=48&height=48" width="48" height="48" alt="Avatar Image" />
+               <%else>
+                       <img src="images/sone-avatar.png" width="48" height="48" alt="Avatar Image" />
+               <%/if>
        </div>
        <div class="inner-part">
-               <div>
+               <div<%if !post.loaded> class="hidden"<%/if>>
                        <div class="author profile-link"><a href="viewSone.html?sone=<% post.sone.id|html>"><% post.sone.niceName|html></a></div>
                        <%ifnull !post.recipient>
                                <span class="recipient-to">→</span>
@@ -21,7 +25,7 @@
                        <div class="post-text raw-text<%if !raw> hidden<%/if>"><% originalText></div>
                        <div class="post-text text<%if raw> hidden<%/if>"><% parsedText></div>
                </div>
-               <div class="post-status-line status-line">
+               <div class="post-status-line status-line<%if !post.loaded> hidden<%/if>">
                        <div class="bookmarks">
                                <form class="unbookmark<%if !post.bookmarked> hidden<%/if>" action="unbookmark.html" method="post">
                                        <input type="hidden" name="formPassword" value="<% formPassword|html>" />
@@ -94,6 +98,9 @@
                                </form>
                        <%/if>
                </div>
+               <div<%if post.loaded> class="hidden"<%/if>>
+                       <%= View.Post.NotDownloaded|l10n|html>
+               </div>
                <div class="replies">
                        <%foreach post.replies reply>
                                <%include include/viewReply.html>
index 8df39e0..a180fe1 100644 (file)
                        <%include include/pagination.html>
                </div>
 
+               <%foreach repliedPosts post>
+                       <%first>
+                               <h2><%= Page.ViewSone.Replies.Title|l10n|html></h2>
+                               <div id="replied-posts">
+                                       <%include include/pagination.html pagination=repliedPostPagination pageParameter==repliedPostPage>
+                       <%/first>
+                       <%include include/viewPost.html>
+                       <%last>
+                                       <%include include/pagination.html pagination=repliedPostPagination pageParameter==repliedPostPage>
+                               </div>
+                       <%/last>
+               <%/foreach>
+
        <%/if>
 
 <%include include/tail.html>