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;
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) {
}
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);
}
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}
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
<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>&width=48&height=48" width="48" height="48" alt="Avatar Image" />
+ <%if post.loaded>
+ <img src="/WebOfTrust/GetIdenticon?identity=<% post.sone.id|html>&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>
<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>" />
</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>