From: David ‘Bombe’ Roden Date: Fri, 1 Apr 2011 20:44:32 +0000 (+0200) Subject: Add posts a Sone replied to to “view Sone” page. X-Git-Tag: 0.6^2~20 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ece9119924c20b12ef1c2f0908a92dc8323f8884;p=Sone.git Add posts a Sone replied to to “view Sone” page. --- diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index 0792a6f..3f4d92d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -17,11 +17,19 @@ 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 replies = sone.getReplies(); + final Map> repliedPosts = new HashMap>(); + 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 posts = new ArrayList(repliedPosts.keySet()); + Collections.sort(posts, new Comparator() { + + @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 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) { @@ -70,8 +101,11 @@ public class ViewSonePage extends SoneTemplatePage { } webInterface.getCore().markSoneKnown(sone); List posts = sone.getPosts(); + posts.addAll((List) 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); } diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index c8604cb..104d3c7 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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 index 0000000..0339b5a Binary files /dev/null and b/src/main/resources/static/images/sone-avatar.png differ diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index 4600d45..4be1bcc 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -3,10 +3,14 @@
- Avatar Image + <%if post.loaded> + Avatar Image + <%else> + Avatar Image + <%/if>
-
+ class="hidden"<%/if>> <%ifnull !post.recipient> → @@ -21,7 +25,7 @@
<% originalText>
<% parsedText>
-
+
@@ -94,6 +98,9 @@
<%/if>
+ class="hidden"<%/if>> + <%= View.Post.NotDownloaded|l10n|html> +
<%foreach post.replies reply> <%include include/viewReply.html> diff --git a/src/main/resources/templates/viewSone.html b/src/main/resources/templates/viewSone.html index 8df39e0..a180fe1 100644 --- a/src/main/resources/templates/viewSone.html +++ b/src/main/resources/templates/viewSone.html @@ -73,6 +73,19 @@ <%include include/pagination.html>
+ <%foreach repliedPosts post> + <%first> +

<%= Page.ViewSone.Replies.Title|l10n|html>

+
+ <%include include/pagination.html pagination=repliedPostPagination pageParameter==repliedPostPage> + <%/first> + <%include include/viewPost.html> + <%last> + <%include include/pagination.html pagination=repliedPostPagination pageParameter==repliedPostPage> +
+ <%/last> + <%/foreach> + <%/if> <%include include/tail.html>