diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index c0599b4c8..c08143c36 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -10,9 +10,21 @@ class PostsController < ApplicationController skip_before_filter :set_grammatical_gender def index - @posts = StatusMessage.joins(:author).where(Person.arel_table[:owner_id].not_eq(nil)).where(:public => true, :pending => false - ).includes(:comments, :photos - ).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC') + if current_user + @posts = StatusMessage.joins(:aspects, :author).where(:pending => false + ).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true)) + ).select('DISTINCT `posts`.*') + else + @posts = StatusMessage.joins(:author).where(:public => true, :pending => false) + end + + if params[:tag] + @posts = @posts.tagged_with(params[:tag]) + else + @posts = @posts.where(Person.arel_table[:owner_id].not_eq(nil)) + end + + @posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC') @fakes = PostsFake.new(@posts) @commenting_disabled = true diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index fe836c60b..8e3362f36 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -10,7 +10,10 @@ = include_javascripts :home %h1 - = t('.whatup', :pod => @pod_url) + - if params[:tag] + = t('.posts_tagged_with', :tag => params[:tag]) + - else + = t('.whatup', :pod => @pod_url) .span-15 #main_stream.stream diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 662c63d5b..0aaec96a9 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -426,6 +426,7 @@ en: posts: index: whatup: "What's happening on %{pod}" + posts_tagged_with: "Posts tagged with #%{tag}" requests: manage_aspect_contacts: manage_within: "Manage contacts within" diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 32878bdab..d72b23a1c 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -19,17 +19,50 @@ describe PostsController do get :index response.status.should == 200 end + it "shows the signed in user's posts" do + posts = [] + 2.times do + posts << @user.post(:status_message, :message => "#what", :to => 'all') + end + eve.post(:status_message, :message => "#what", :to => 'all') + + get :index + assigns[:posts].should =~ posts + end + it "shows any posts that the user can see" do + posts = [] + 2.times do + posts << bob.post(:status_message, :message => "#what", :to => 'all') + end + eve.post(:status_message, :message => "#what", :to => 'all') + + get :index + assigns[:posts].should =~ posts + end + end + it 'restricts the posts by tag' do + posts = [] + 2.times do + posts << @user.post(:status_message, :message => "#what", :public => true, :to => 'all') + end + 2.times do + @user.post(:status_message, :message => "#hello", :public => true, :to => 'all') + end + + get :index, :tag => 'what' + assigns[:posts].should =~ posts + end it 'shows the most recent public posts' do posts = [] - 10.times do + 3.times do posts << @user.post(:status_message, :message => "hello", :public => true, :to => 'all') end get :index assigns[:posts].should =~ posts end it' shows only local posts' do - 10.times do + 3.times do @user.post(:status_message, :message => "hello", :public => true, :to => 'all') end @user.person.update_attributes(:owner_id => nil)