From 9fba69cd5ba09403380655f6ca1f0884c3085d66 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 25 Oct 2011 16:26:46 -0700 Subject: [PATCH] added person stream; temp hack for photos --- app/controllers/people_controller.rb | 19 ++++--------- app/helpers/stream_helper.rb | 2 +- app/views/people/show.html.haml | 5 ++-- app/views/people/show.mobile.haml | 6 ++-- features/photos.feature | 1 - lib/stream/mention.rb | 1 - lib/stream/person.rb | 25 +++++++++++++++++ spec/controllers/people_controller_spec.rb | 32 ++++++++-------------- spec/lib/stream/followed_tag_spec.rb | 2 +- spec/lib/stream/mention_spec.rb | 2 +- spec/lib/stream/multi_spec.rb | 3 +- spec/lib/stream/person_spec.rb | 12 ++++++++ spec/lib/stream/public_spec.rb | 1 + spec/lib/stream/tag_spec.rb | 1 - 14 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 lib/stream/person.rb create mode 100644 spec/lib/stream/person_spec.rb diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 28daa5bba..36990b730 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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} } diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index d0d7d0395..6144989bb 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -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) diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 10ccd9937..7ccb346a7 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -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') diff --git a/app/views/people/show.mobile.haml b/app/views/people/show.mobile.haml index 69e902b63..414b9a875 100644 --- a/app/views/people/show.mobile.haml +++ b/app/views/people/show.mobile.haml @@ -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 diff --git a/features/photos.feature b/features/photos.feature index 43ffd0a4d..5f607c365 100644 --- a/features/photos.feature +++ b/features/photos.feature @@ -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 diff --git a/lib/stream/mention.rb b/lib/stream/mention.rb index 5bdb81079..b385f5af9 100644 --- a/lib/stream/mention.rb +++ b/lib/stream/mention.rb @@ -11,7 +11,6 @@ class Stream::Mention < Stream::Base I18n.translate("streams.mentions.title") end - # @return [ActiveRecord::Association] AR association of posts def posts @posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order) diff --git a/lib/stream/person.rb b/lib/stream/person.rb new file mode 100644 index 000000000..83cd47d4b --- /dev/null +++ b/lib/stream/person.rb @@ -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] 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 diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index ecf770ed3..650b5dee3 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -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 diff --git a/spec/lib/stream/followed_tag_spec.rb b/spec/lib/stream/followed_tag_spec.rb index 805915bff..f42859368 100644 --- a/spec/lib/stream/followed_tag_spec.rb +++ b/spec/lib/stream/followed_tag_spec.rb @@ -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 diff --git a/spec/lib/stream/mention_spec.rb b/spec/lib/stream/mention_spec.rb index f27ff8e4d..a4a9f7571 100644 --- a/spec/lib/stream/mention_spec.rb +++ b/spec/lib/stream/mention_spec.rb @@ -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 diff --git a/spec/lib/stream/multi_spec.rb b/spec/lib/stream/multi_spec.rb index 7e5f08c12..5bfa382ab 100644 --- a/spec/lib/stream/multi_spec.rb +++ b/spec/lib/stream/multi_spec.rb @@ -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 diff --git a/spec/lib/stream/person_spec.rb b/spec/lib/stream/person_spec.rb new file mode 100644 index 000000000..d8bd3585f --- /dev/null +++ b/spec/lib/stream/person_spec.rb @@ -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 diff --git a/spec/lib/stream/public_spec.rb b/spec/lib/stream/public_spec.rb index 0a9db92eb..9f0fdacf1 100644 --- a/spec/lib/stream/public_spec.rb +++ b/spec/lib/stream/public_spec.rb @@ -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) diff --git a/spec/lib/stream/tag_spec.rb b/spec/lib/stream/tag_spec.rb index 158372d33..6c33c2cba 100644 --- a/spec/lib/stream/tag_spec.rb +++ b/spec/lib/stream/tag_spec.rb @@ -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