display photos correctly
This commit is contained in:
parent
0c24510682
commit
6474ca9540
5 changed files with 36 additions and 21 deletions
|
|
@ -26,8 +26,7 @@ class PhotosController < ApplicationController
|
||||||
@similar_people = similar_people @contact
|
@similar_people = similar_people @contact
|
||||||
end
|
end
|
||||||
|
|
||||||
@posts = current_user.raw_visible_posts.where(
|
@posts = current_user.visible_photos.where(
|
||||||
:type => 'Photo',
|
|
||||||
:person_id => @person.id
|
:person_id => @person.id
|
||||||
).paginate(:page => params[:page])
|
).paginate(:page => params[:page])
|
||||||
|
|
||||||
|
|
@ -136,7 +135,7 @@ class PhotosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@photo = current_user.find_visible_post_by_id params[:id]
|
@photo = current_user.visible_photos.where(:id => params[:id]).first
|
||||||
if @photo
|
if @photo
|
||||||
@parent = @photo.status_message
|
@parent = @photo.status_message
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class StatusMessagesController < ApplicationController
|
||||||
@status_message.photos += photos
|
@status_message.photos += photos
|
||||||
for photo in photos
|
for photo in photos
|
||||||
photo.public = public_flag
|
photo.public = public_flag
|
||||||
|
photo.pending = false
|
||||||
photo.save
|
photo.save
|
||||||
current_user.add_to_streams(photo, aspects)
|
current_user.add_to_streams(photo, aspects)
|
||||||
current_user.dispatch_post(photo)
|
current_user.dispatch_post(photo)
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,20 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_visible_posts
|
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`.*')
|
:aspects => {:user_id => self.id}).select('DISTINCT `posts`.*')
|
||||||
end
|
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 = {} )
|
def visible_posts( opts = {} )
|
||||||
order = opts.delete(:order)
|
order = opts.delete(:order)
|
||||||
order ||= 'created_at DESC'
|
order ||= 'created_at DESC'
|
||||||
opts[:type] ||= ["StatusMessage","Photo"]
|
opts[:type] ||= ["StatusMessage", "Photo"]
|
||||||
|
|
||||||
if (aspect = opts[:by_members_of]) && opts[:by_members_of] != :all
|
if (aspect = opts[:by_members_of]) && opts[:by_members_of] != :all
|
||||||
raw_visible_posts.where(:aspects => {:id => aspect.id}).order(order)
|
raw_visible_posts.where(:aspects => {:id => aspect.id}).order(order)
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,12 @@ describe PhotosController do
|
||||||
|
|
||||||
let(:filename) { 'button.png' }
|
let(:filename) { 'button.png' }
|
||||||
let(:fixture_name) { File.join(File.dirname(__FILE__), '..', 'fixtures', filename) }
|
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(: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(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
connect_users(user1, aspect1, user2, aspect2)
|
connect_users(user1, aspect1, user2, aspect2)
|
||||||
|
photo1; photo2
|
||||||
@controller.stub!(:current_user).and_return(user1)
|
@controller.stub!(:current_user).and_return(user1)
|
||||||
sign_in :user, user1
|
sign_in :user, user1
|
||||||
end
|
end
|
||||||
|
|
@ -57,11 +58,11 @@ describe PhotosController do
|
||||||
assigns[:posts].should == [photo1]
|
assigns[:posts].should == [photo1]
|
||||||
end
|
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
|
get :index, :person_id => user2.person.id.to_s
|
||||||
|
|
||||||
assigns[:person].should == user2.person
|
assigns[:person].should == user2.person
|
||||||
assigns[:posts].should be_empty
|
assigns[:posts].should == [photo2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,21 +60,29 @@ describe StatusMessagesController do
|
||||||
old_status_message.reload.message.should == 'hello'
|
old_status_message.reload.message.should == 'hello'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dispatches all referenced photos" do
|
context 'with photos' do
|
||||||
fixture_filename = 'button.png'
|
before do
|
||||||
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
|
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)
|
@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)
|
@photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
|
||||||
|
|
||||||
photo1.save!
|
@photo1.save!
|
||||||
photo2.save!
|
@photo2.save!
|
||||||
|
|
||||||
hash = status_message_hash
|
@hash = status_message_hash
|
||||||
hash[:photos] = [photo1.id.to_s, photo2.id.to_s]
|
@hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s]
|
||||||
|
end
|
||||||
user1.should_receive(:dispatch_post).exactly(3).times
|
it "dispatches all referenced photos" do
|
||||||
post :create, hash
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue