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
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require File.join(Rails.root, "lib", 'stream', "person")
|
||||||
|
|
||||||
class PeopleController < ApplicationController
|
class PeopleController < ApplicationController
|
||||||
before_filter :authenticate_user!, :except => [:show]
|
before_filter :authenticate_user!, :except => [:show]
|
||||||
|
|
||||||
|
|
@ -86,7 +88,9 @@ class PeopleController < ApplicationController
|
||||||
@aspect = :profile
|
@aspect = :profile
|
||||||
@share_with = (params[:share_with] == 'true')
|
@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
|
@profile = @person.profile
|
||||||
|
|
||||||
unless params[:format] == "json" # hovercard
|
unless params[:format] == "json" # hovercard
|
||||||
|
|
@ -104,22 +108,11 @@ class PeopleController < ApplicationController
|
||||||
@contacts_of_contact_count = 0
|
@contacts_of_contact_count = 0
|
||||||
@contacts_of_contact = []
|
@contacts_of_contact = []
|
||||||
end
|
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
|
end
|
||||||
@posts.includes(:author => :profile)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:only_posts]
|
if params[:only_posts]
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @posts}
|
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.all { respond_with @person, :locals => {:post_type => :all} }
|
format.all { respond_with @person, :locals => {:post_type => :all} }
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module StreamHelper
|
||||||
elsif controller.instance_of?(AppsController)
|
elsif controller.instance_of?(AppsController)
|
||||||
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
|
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
|
||||||
elsif controller.instance_of?(PeopleController)
|
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)
|
elsif controller.instance_of?(TagFollowingsController)
|
||||||
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
||||||
elsif controller.instance_of?(CommunitySpotlightController)
|
elsif controller.instance_of?(CommunitySpotlightController)
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,13 @@
|
||||||
.stream_container
|
.stream_container
|
||||||
= render 'people/sub_header', :person => @person, :contact => @contact
|
= 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
|
-if @post_type == :photos
|
||||||
= render 'photos/index', :photos => @posts
|
= render 'photos/index', :photos => @posts
|
||||||
- else
|
- else
|
||||||
#main_stream.stream
|
#main_stream.stream
|
||||||
= render 'shared/stream', :posts => @posts
|
= render 'shared/stream', :posts => @stream.posts
|
||||||
#pagination
|
#pagination
|
||||||
=link_to(t('more'), next_page_path, :class => 'paginate')
|
=link_to(t('more'), next_page_path, :class => 'paginate')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@
|
||||||
= link_to t('.return_to_aspects'), aspects_manage_path
|
= link_to t('.return_to_aspects'), aspects_manage_path
|
||||||
= t('.to_accept_or_ignore')
|
= t('.to_accept_or_ignore')
|
||||||
|
|
||||||
- if @posts.length > 0
|
- if @stream.posts.length > 0
|
||||||
-if @post_type == :photos
|
-if @post_type == :photos
|
||||||
= render 'photos/index', :photos => @posts
|
= render 'photos/index', :photos => @stream.posts
|
||||||
- else
|
- else
|
||||||
#main_stream.stream
|
#main_stream.stream
|
||||||
= render 'shared/stream', :posts => @posts
|
= render 'shared/stream', :posts => @stream.posts
|
||||||
#pagination
|
#pagination
|
||||||
=link_to(t('more'), next_page_path, :class => 'paginate')
|
=link_to(t('more'), next_page_path, :class => 'paginate')
|
||||||
- else
|
- else
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ Feature: photos
|
||||||
And I follow "edit_photo_toggle"
|
And I follow "edit_photo_toggle"
|
||||||
And I preemptively confirm the alert
|
And I preemptively confirm the alert
|
||||||
And I press "Delete Photo"
|
And I press "Delete Photo"
|
||||||
And I wait for the ajax to finish
|
|
||||||
And I go to the home page
|
And I go to the home page
|
||||||
|
|
||||||
Then I should see 0 posts
|
Then I should see 0 posts
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ class Stream::Mention < Stream::Base
|
||||||
I18n.translate("streams.mentions.title")
|
I18n.translate("streams.mentions.title")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# @return [ActiveRecord::Association<Post>] AR association of posts
|
# @return [ActiveRecord::Association<Post>] AR association of posts
|
||||||
def posts
|
def posts
|
||||||
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
|
@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.post(:status_message, :text => "public", :to => 'all', :public => true)
|
||||||
@user.reload.posts.length.should == 3
|
@user.reload.posts.length.should == 3
|
||||||
get :show, :id => @user.person.to_param
|
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
|
end
|
||||||
|
|
||||||
it "renders the comments on the user's posts" do
|
it "renders the comments on the user's posts" do
|
||||||
|
|
@ -232,17 +232,17 @@ describe PeopleController do
|
||||||
it "posts include reshares" do
|
it "posts include reshares" do
|
||||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||||
get :show, :id => @user.person.id
|
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
|
end
|
||||||
|
|
||||||
it "assigns only public posts" do
|
it "assigns only public posts" do
|
||||||
get :show, :id => @person.id
|
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
|
end
|
||||||
|
|
||||||
it 'is sorted by created_at desc' do
|
it 'is sorted by created_at desc' do
|
||||||
get :show, :id => @person.id
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -281,18 +281,13 @@ describe PeopleController do
|
||||||
bob.reload.posts.length.should == 4
|
bob.reload.posts.length.should == 4
|
||||||
|
|
||||||
get :show, :id => @person.id
|
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
|
end
|
||||||
|
|
||||||
it "posts include reshares" do
|
it "posts include reshares" do
|
||||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||||
get :show, :id => @user.person.id
|
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 'sets @commenting_disabled to true' do
|
|
||||||
get :show, :id => @person.id
|
|
||||||
assigns(:commenting_disabled).should == false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -319,18 +314,13 @@ describe PeopleController do
|
||||||
eve.reload.posts.length.should == 3
|
eve.reload.posts.length.should == 3
|
||||||
|
|
||||||
get :show, :id => @person.id
|
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
|
end
|
||||||
|
|
||||||
it "posts include reshares" do
|
it "posts include reshares" do
|
||||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||||
get :show, :id => @user.person.id
|
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 'sets @commenting_disabled to true' do
|
|
||||||
get :show, :id => @person.id
|
|
||||||
assigns(:commenting_disabled).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||||
|
|
||||||
describe Stream::FollowedTag do
|
describe Stream::FollowedTag do
|
||||||
before 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")
|
@stream.stub(:tag_string).and_return("foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||||
|
|
||||||
describe Stream::Mention do
|
describe Stream::Mention do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
describe 'shared behaviors' do
|
describe 'shared behaviors' do
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,9 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||||
|
|
||||||
describe Stream::Multi do
|
describe Stream::Multi do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'shared behaviors' do
|
describe 'shared behaviors' do
|
||||||
it_should_behave_like 'it is a stream'
|
it_should_behave_like 'it is a stream'
|
||||||
end
|
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 'spec_helper'
|
||||||
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||||
|
|
||||||
describe Stream::Public do
|
describe Stream::Public do
|
||||||
before do
|
before do
|
||||||
@stream = Stream::Public.new(stub)
|
@stream = Stream::Public.new(stub)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ describe Stream::Tag do
|
||||||
Factory(:comment, :text => "#what", :post => other_post)
|
Factory(:comment, :text => "#what", :post => other_post)
|
||||||
@stream.posts.should == [other_post]
|
@stream.posts.should == [other_post]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without a user' do
|
context 'without a user' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue