From ece9119924c20b12ef1c2f0908a92dc8323f8884 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Apr 2011 22:44:32 +0200 Subject: [PATCH] =?utf8?q?Add=20posts=20a=20Sone=20replied=20to=20to=20?= =?utf8?q?=E2=80=9Cview=20Sone=E2=80=9D=20page.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/web/ViewSonePage.java | 36 ++++++++++++++++++++- src/main/resources/i18n/sone.en.properties | 2 ++ src/main/resources/static/images/sone-avatar.png | Bin 0 -> 1965 bytes src/main/resources/templates/include/viewPost.html | 13 ++++++-- src/main/resources/templates/viewSone.html | 13 ++++++++ 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/static/images/sone-avatar.png 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 0000000000000000000000000000000000000000..0339b5af82f2c1c4e51e3fa89c6dca2ba87bfaaa GIT binary patch literal 1965 zcmV;e2U7TnP);M1&8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H12P#QKK~!jg)tY;3RL2>`e{=V)-v+NSHpVtKk4S(pgvPW9D%gRl zG&CiJhPE&=1a2I|BfB%7mM!I0400msgPC+gC(B1MN~^I%SK*d~{;Q_d=RJ(P?* zh3dq^k;J$6!0tL|>4erUaJscq(x0wQxz1%N1hEkE9BzsYa@9u|Hdtl?Mw?;g`@n+a} zToKTyuu>}2iPgZ}s?dg);ZP$43~Nlc!Hj~qw1&l{P6a8MZ>H1+B%4(9>qp_h$Lb5} zHu&iZSTrkUjS-PI!OD4Lie=2L1`di6;A>{O#|^vRQZLe*;`jb2F|lTpO@=iV1<>Lx zv5bq=K!EQ7!c0H+4qUim?KIiqi*jN6521LHHFm=N70bl6K1L;9S9RRlW#v@j=N7B) zUNq>o;GKWy?qDAZc>mhJa@u-xo}%G2Rd$QXK)5^qtF2fLAyxmU?eN{Fpm#87I#n=^41V?4+>37)U-Xofg=-X3IjsqpIc4lZ z{_q^!w+9YB0gfaU*itgsZ)9KkbojQu7kVDZJ2|+pGFnc|?*lWZzs zF;TrY$ScIjK7W?amXmL!=j8d*91j1)lIfm;1&f9NJkqYWd5Vh+#DZ8g#bw}*8Nrb- zOts&MX86u-IP}Y)2}43hkFpB^?i2>x3^-eZjAkRP@eDaDH=sMF#G`uzF~1f*vJAd? zyE=CAJlwl0fi+y^iFpQ?*9If$4I2m#ML2vZ&Ec*BLDi5uPs7fVT3^8UUq z`VPOyz|lX&DrdCMcpA?ufuF1ZTbQhd3s8SHe17VTg``ZIrw$qhgC8Hn*VPt}r1(!3 zw%rfUJ`AOk)p7T5_*`L6CGUaVVNC?C_t5|DA0UpCl7x;%HmroB+hJ9O;;kv#1=F*F zCQ8ed@!?CS8T{mM%>5;Df@b&(+m)%4ZT{NL@MeRN(bytW+g(z3UX!}>n$TQ^!!FS* z8zMrCnpn3B*Be{#UN+4+De+#tK;|7QlV{+%k@?wy{^hQE_gy)shUU+58yTbZQtp3$ zAsxo@KpZi#uLf`1nK7|IkD_i5gJ=dkf9bvF)aK5|ml%kopTueDS>#pkq-Wn&JZ+=9 zq`&uz;5rc2LA3M{F5tu7_N~^JIv(%bRCz1Jj|fQ5Vp8=E?D^A2xIkYQ{(oOpHMgwp zaKZxBm!BE>%rk3da%4uvz>(MRxtyb-GA3f1pgc3SyjCdki6cNSem5_Dk8daK*p4xp0L#S%{}q zv}FYRQafYj^xUGjgocB^_Y1XnO(SjgVjSQ8nL1H$q`ju{Emg>3K$A3@xr_zNNexqc zjTgG3kequSC2!qMw9Fhu3*kis9t)dqCZtBAWxvyGI96|>@15uHv^F6F34DUNDaWQ` zn^=IJTZk>Ui0q}+=o2locC@{eKXz_eZkZJ!@v&+rKYcPg&Fec0l&TW^*PINuegcV@ z&{Ie)osT`gET%dKc&dGC)f15#D8JAY@2FoU(B4OJM)YMtNU^JZTjf@%sDDDCEG0U& zE~^KAe@m1_$DkDA`_65ZHPOUFgle=PKYOEuodiENe+du<@MjxZc}GoUZOmEGKC@2y z?Xg9Mkgp4vGhT^d;F5y3g`xefecRFqM*?cZ^jCw5KmOC+-Q~U=L4_1lAZ0mWzFtOw zA4w;gxFRGSNRGD8?rxB4*Css5iT&B*e+d5pIZ=rz)a)b400000NkvXXu0mjfi0rM; literal 0 HcmV?d00001 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> -- 2.7.4