added person stream; temp hack for photos
This commit is contained in:
parent
2cbb61be75
commit
9fba69cd5b
14 changed files with 65 additions and 47 deletions
|
|
@ -2,6 +2,8 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, "lib", 'stream', "person")
|
||||
|
||||
class PeopleController < ApplicationController
|
||||
before_filter :authenticate_user!, :except => [:show]
|
||||
|
||||
|
|
@ -86,7 +88,9 @@ class PeopleController < ApplicationController
|
|||
@aspect = :profile
|
||||
@share_with = (params[:share_with] == 'true')
|
||||
|
||||
max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
|
||||
@stream = Stream::Person.new(current_user, @person,
|
||||
:max_time => max_time)
|
||||
|
||||
@profile = @person.profile
|
||||
|
||||
unless params[:format] == "json" # hovercard
|
||||
|
|
@ -104,22 +108,11 @@ class PeopleController < ApplicationController
|
|||
@contacts_of_contact_count = 0
|
||||
@contacts_of_contact = []
|
||||
end
|
||||
|
||||
if (@person != current_user.person) && !@contact.persisted?
|
||||
@commenting_disabled = true
|
||||
else
|
||||
@commenting_disabled = false
|
||||
end
|
||||
@posts = current_user.posts_from(@person).where(:type => ["StatusMessage", "Reshare", "ActivityStreams::Photo"]).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time))
|
||||
else
|
||||
@commenting_disabled = true
|
||||
@posts = @person.posts.where(:type => ["StatusMessage", "Reshare", "ActivityStreams::Photo"], :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC')
|
||||
end
|
||||
@posts.includes(:author => :profile)
|
||||
end
|
||||
|
||||
if params[:only_posts]
|
||||
render :partial => 'shared/stream', :locals => {:posts => @posts}
|
||||
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
||||
else
|
||||
respond_to do |format|
|
||||
format.all { respond_with @person, :locals => {:post_type => :all} }
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ module StreamHelper
|
|||
elsif controller.instance_of?(AppsController)
|
||||
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
|
||||
elsif controller.instance_of?(PeopleController)
|
||||
person_path(@person, :max_time => @posts.last.created_at.to_i)
|
||||
person_path(@person, :max_time => time_for_scroll(opts[:ajax_stream], @stream))
|
||||
elsif controller.instance_of?(TagFollowingsController)
|
||||
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
||||
elsif controller.instance_of?(CommunitySpotlightController)
|
||||
|
|
|
|||
|
|
@ -26,12 +26,13 @@
|
|||
.stream_container
|
||||
= render 'people/sub_header', :person => @person, :contact => @contact
|
||||
|
||||
- if @posts.length > 0
|
||||
/ hackity hack until we get a photo stream
|
||||
- if (@posts && @posts.length > 0) || @stream.posts.length > 0
|
||||
-if @post_type == :photos
|
||||
= render 'photos/index', :photos => @posts
|
||||
- else
|
||||
#main_stream.stream
|
||||
= render 'shared/stream', :posts => @posts
|
||||
= render 'shared/stream', :posts => @stream.posts
|
||||
#pagination
|
||||
=link_to(t('more'), next_page_path, :class => 'paginate')
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@
|
|||
= link_to t('.return_to_aspects'), aspects_manage_path
|
||||
= t('.to_accept_or_ignore')
|
||||
|
||||
- if @posts.length > 0
|
||||
- if @stream.posts.length > 0
|
||||
-if @post_type == :photos
|
||||
= render 'photos/index', :photos => @posts
|
||||
= render 'photos/index', :photos => @stream.posts
|
||||
- else
|
||||
#main_stream.stream
|
||||
= render 'shared/stream', :posts => @posts
|
||||
= render 'shared/stream', :posts => @stream.posts
|
||||
#pagination
|
||||
=link_to(t('more'), next_page_path, :class => 'paginate')
|
||||
- else
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ Feature: photos
|
|||
And I follow "edit_photo_toggle"
|
||||
And I preemptively confirm the alert
|
||||
And I press "Delete Photo"
|
||||
And I wait for the ajax to finish
|
||||
And I go to the home page
|
||||
|
||||
Then I should see 0 posts
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ class Stream::Mention < Stream::Base
|
|||
I18n.translate("streams.mentions.title")
|
||||
end
|
||||
|
||||
|
||||
# @return [ActiveRecord::Association<Post>] AR association of posts
|
||||
def posts
|
||||
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
|
||||
|
|
|
|||
25
lib/stream/person.rb
Normal file
25
lib/stream/person.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class Stream::Person < Stream::Base
|
||||
|
||||
attr_accessor :person
|
||||
|
||||
def initialize(user, person, opts={})
|
||||
self.person = person
|
||||
super(user, opts)
|
||||
end
|
||||
|
||||
# @return [ActiveRecord::Association<Post>] AR association of posts
|
||||
def posts
|
||||
@posts ||= lambda do
|
||||
if user
|
||||
posts = self.user.posts_from(@person).for_a_stream(max_time, order)
|
||||
else
|
||||
posts = @person.posts.where(:public => true).for_a_stream(max_time, order)
|
||||
end
|
||||
posts
|
||||
end.call
|
||||
end
|
||||
end
|
||||
|
|
@ -185,7 +185,7 @@ describe PeopleController do
|
|||
@user.post(:status_message, :text => "public", :to => 'all', :public => true)
|
||||
@user.reload.posts.length.should == 3
|
||||
get :show, :id => @user.person.to_param
|
||||
assigns(:posts).map(&:id).should =~ @user.posts.map(&:id)
|
||||
assigns(:stream).posts.map(&:id).should =~ @user.posts.map(&:id)
|
||||
end
|
||||
|
||||
it "renders the comments on the user's posts" do
|
||||
|
|
@ -232,17 +232,17 @@ describe PeopleController do
|
|||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:posts].map{|x| x.id}.should include(reshare.id)
|
||||
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
||||
it "assigns only public posts" do
|
||||
get :show, :id => @person.id
|
||||
assigns[:posts].map(&:id).should =~ @public_posts.map(&:id)
|
||||
assigns[:stream].posts.map(&:id).should =~ @public_posts.map(&:id)
|
||||
end
|
||||
|
||||
it 'is sorted by created_at desc' do
|
||||
get :show, :id => @person.id
|
||||
assigns[:posts].should == @public_posts.sort_by{|p| p.created_at}.reverse
|
||||
assigns[:stream].posts.should == @public_posts.sort_by{|p| p.created_at}.reverse
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -281,18 +281,13 @@ describe PeopleController do
|
|||
bob.reload.posts.length.should == 4
|
||||
|
||||
get :show, :id => @person.id
|
||||
assigns(:posts).map(&:id).should =~ posts_user_can_see.map(&:id)
|
||||
assigns(:stream).posts.map(&:id).should =~ posts_user_can_see.map(&:id)
|
||||
end
|
||||
|
||||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:posts].map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
||||
it 'sets @commenting_disabled to true' do
|
||||
get :show, :id => @person.id
|
||||
assigns(:commenting_disabled).should == false
|
||||
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -319,18 +314,13 @@ describe PeopleController do
|
|||
eve.reload.posts.length.should == 3
|
||||
|
||||
get :show, :id => @person.id
|
||||
assigns[:posts].map(&:id).should =~ [public_post].map(&:id)
|
||||
assigns[:stream].posts.map(&:id).should =~ [public_post].map(&:id)
|
||||
end
|
||||
|
||||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:posts].map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
||||
it 'sets @commenting_disabled to true' do
|
||||
get :show, :id => @person.id
|
||||
assigns(:commenting_disabled).should == true
|
||||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
|||
|
||||
describe Stream::FollowedTag do
|
||||
before do
|
||||
@stream = Stream::FollowedTag.new(Factory(:user), :max_time => Time.now, :order => 'updated_at')
|
||||
@stream = Stream::FollowedTag.new(alice, :max_time => Time.now, :order => 'updated_at')
|
||||
@stream.stub(:tag_string).and_return("foo")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
|||
|
||||
describe Stream::Mention do
|
||||
before do
|
||||
@stream = Stream::Mention.new(Factory(:user), :max_time => Time.now, :order => 'updated_at')
|
||||
@stream = Stream::Mention.new(alice, :max_time => Time.now, :order => 'updated_at')
|
||||
end
|
||||
|
||||
describe 'shared behaviors' do
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
|||
|
||||
describe Stream::Multi do
|
||||
before do
|
||||
@stream = Stream::Multi.new(Factory(:user), :max_time => Time.now, :order => 'updated_at')
|
||||
@stream = Stream::Multi.new(alice, :max_time => Time.now, :order => 'updated_at')
|
||||
end
|
||||
|
||||
|
||||
describe 'shared behaviors' do
|
||||
it_should_behave_like 'it is a stream'
|
||||
end
|
||||
|
|
|
|||
12
spec/lib/stream/person_spec.rb
Normal file
12
spec/lib/stream/person_spec.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require 'spec_helper'
|
||||
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||
|
||||
describe Stream::Person do
|
||||
before do
|
||||
@stream = Stream::Person.new(alice, bob.person, :max_time => Time.now, :order => 'updated_at')
|
||||
end
|
||||
|
||||
describe 'shared behaviors' do
|
||||
it_should_behave_like 'it is a stream'
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||
|
||||
describe Stream::Public do
|
||||
before do
|
||||
@stream = Stream::Public.new(stub)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ describe Stream::Tag do
|
|||
Factory(:comment, :text => "#what", :post => other_post)
|
||||
@stream.posts.should == [other_post]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'without a user' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue