package net.pterodactylus.sone.web;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.template.Template;
/**
* {@inheritDoc}
*/
@Override
+ protected void processTemplate(Request request, Template template) throws RedirectException {
+ super.processTemplate(request, template);
+ Sone sone = getCurrentSone(request.getToadletContext());
+ List<Post> allPosts = new ArrayList<Post>();
+ allPosts.addAll(sone.getPosts());
+ for (Sone friendSone : sone.getFriendSones()) {
+ allPosts.addAll(friendSone.getPosts());
+ }
+ Collections.sort(allPosts, new Comparator<Post>() {
+
+ @Override
+ public int compare(Post leftPost, Post rightPost) {
+ return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
+ }
+
+ });
+ template.set("posts", allPosts);
+ }
+
+ //
+ // SONETEMPLATEPAGE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
protected boolean requiresLogin() {
return true;
}
Page.Index.Page.Title=Your Sone
Page.Index.Label.Text=Post text:
Page.Index.Button.Post=Post!
+Page.Index.PostList.Title=Posts by you and your friends
+Page.Index.PostList.Text.NoPostYet=Nobody has written any posts yet. You should probably start it right now!
Page.EditProfile.Title=Edit Profile - Sone
Page.EditProfile.Page.Title=Edit Profile
</form>
</div>
+ <h1><%= Page.Index.PostList.Title|l10n|html></h1>
+
+ <div>
+ <%foreach posts post>
+ <div>
+ <div class="author"><% post.sone.name|html></div>
+ <div class="text"><% post.text|html></div>
+ <div class="time"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></div>
+ </div>
+ <%foreachelse>
+ <div><%= Page.Index.PostList.Text.NoPostYet|l10n|html></div>
+ <%/foreach>
+ </div>
+
</div>
\ No newline at end of file