Show posts of Sone and friends on index page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 08:34:20 +0000 (10:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 08:34:20 +0000 (10:34 +0200)
src/main/java/net/pterodactylus/sone/web/IndexPage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/index.html

index 0e72938..3965aee 100644 (file)
 
 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;
 
 /**
@@ -45,6 +52,33 @@ public class IndexPage extends SoneTemplatePage {
         * {@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;
        }
index 4bde225..d56627f 100644 (file)
@@ -46,6 +46,8 @@ Page.Index.Title=Your Sone - Sone
 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
index 154ff3e..7aa558b 100644 (file)
                </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