diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 4669b30b4..c01e46b5b 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -26,8 +26,7 @@ class PhotosController < ApplicationController @similar_people = similar_people @contact end - @posts = current_user.raw_visible_posts.where( - :type => 'Photo', + @posts = current_user.visible_photos.where( :person_id => @person.id ).paginate(:page => params[:page]) @@ -136,7 +135,7 @@ class PhotosController < ApplicationController end def show - @photo = current_user.find_visible_post_by_id params[:id] + @photo = current_user.visible_photos.where(:id => params[:id]).first if @photo @parent = @photo.status_message diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 84f0f0a8c..69a06b6c1 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -27,6 +27,7 @@ class StatusMessagesController < ApplicationController @status_message.photos += photos for photo in photos photo.public = public_flag + photo.pending = false photo.save current_user.add_to_streams(photo, aspects) current_user.dispatch_post(photo) diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 86c738285..e910bda29 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -11,14 +11,20 @@ module Diaspora end def raw_visible_posts - Post.joins(:post_visibilities => :aspect).where(:pending => false, + Post.joins(:aspects).where(:pending => false, :aspects => {:user_id => self.id}).select('DISTINCT `posts`.*') end + def visible_photos + p = Post.arel_table + Post.joins(:aspects).where(p[:status_message_id].not_eq(nil).or(p[:pending].eq(false)) + ).where(:aspects => {:user_id => self.id}).select('DISTINCT `posts`.*').order("posts.updated_at DESC") + end + def visible_posts( opts = {} ) order = opts.delete(:order) order ||= 'created_at DESC' - opts[:type] ||= ["StatusMessage","Photo"] + opts[:type] ||= ["StatusMessage", "Photo"] if (aspect = opts[:by_members_of]) && opts[:by_members_of] != :all raw_visible_posts.where(:aspects => {:id => aspect.id}).order(order) diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 869511ad8..23b0f8f7a 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -15,11 +15,12 @@ describe PhotosController do let(:filename) { 'button.png' } let(:fixture_name) { File.join(File.dirname(__FILE__), '..', 'fixtures', filename) } - let!(:photo1) { user1.post(:photo, :user_file => File.open(fixture_name), :to => aspect1.id) } - let!(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) } + let(:photo1) { user1.post(:photo, :user_file => File.open(fixture_name), :to => aspect1.id) } + let(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) } before do connect_users(user1, aspect1, user2, aspect2) + photo1; photo2 @controller.stub!(:current_user).and_return(user1) sign_in :user, user1 end @@ -57,11 +58,11 @@ describe PhotosController do assigns[:posts].should == [photo1] end - it 'sets the person to a contact if person_id is set' do + it "displays another person's pictures" do get :index, :person_id => user2.person.id.to_s assigns[:person].should == user2.person - assigns[:posts].should be_empty + assigns[:posts].should == [photo2] end end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index a7ee9d07f..789c71d13 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -60,21 +60,29 @@ describe StatusMessagesController do old_status_message.reload.message.should == 'hello' end - it "dispatches all referenced photos" do - fixture_filename = 'button.png' - fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) + context 'with photos' do + before do + fixture_filename = 'button.png' + fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) - photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) - photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) + @photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) + @photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) - photo1.save! - photo2.save! + @photo1.save! + @photo2.save! - hash = status_message_hash - hash[:photos] = [photo1.id.to_s, photo2.id.to_s] - - user1.should_receive(:dispatch_post).exactly(3).times - post :create, hash + @hash = status_message_hash + @hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s] + end + it "dispatches all referenced photos" do + user1.should_receive(:dispatch_post).exactly(3).times + post :create, @hash + end + it "sets the pending bit of referenced photos" do + post :create, @hash + @photo1.reload.pending.should be_false + @photo2.reload.pending.should be_false + end end end