From 5b8365118d77ee0b390d6354733679bae664274d Mon Sep 17 00:00:00 2001 From: Dan Hansen & Maxwell Salzberg Date: Wed, 2 Nov 2011 16:36:19 -0500 Subject: [PATCH] Stream#posts no longer needs to call for_a_stream exclude blocked users from all streams --- app/helpers/stream_element_helper.rb | 15 ++++++++++++++- app/models/status_message.rb | 3 +-- app/views/aspects/_aspect_stream.haml | 4 ++-- app/views/aspects/index.mobile.haml | 4 ++-- app/views/people/show.html.haml | 4 ++-- app/views/people/show.mobile.haml | 6 +++--- app/views/shared/_stream_element.html.haml | 6 +----- app/views/tags/show.haml | 4 ++-- app/views/tags/show.mobile.haml | 4 ++-- lib/stream/aspect.rb | 2 +- lib/stream/base.rb | 6 +++++- lib/stream/community_spotlight.rb | 2 +- lib/stream/mention.rb | 2 +- lib/stream/multi.rb | 2 +- lib/stream/person.rb | 4 ++-- lib/stream/public.rb | 2 +- lib/stream/tag.rb | 2 +- spec/controllers/people_controller_spec.rb | 2 +- .../controllers/tag_followings_controller_spec.rb | 1 + 19 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/helpers/stream_element_helper.rb b/app/helpers/stream_element_helper.rb index a023ea04b..7b7da572e 100644 --- a/app/helpers/stream_element_helper.rb +++ b/app/helpers/stream_element_helper.rb @@ -1,7 +1,20 @@ module StreamElementHelper def block_user_control(author) if user_signed_in? - button_to "block a mofo", blocks_path(:block => {:person_id => author.id}), :class => "block_button" + link_to image_tag('deletelabel.png'), blocks_path(:block => {:person_id => author.id}), + :class => 'block_button stream_element_delete', + :confirm => t('are_you_sure'), + :title => 'block user', + :method => :post + + end + end + + def delete_or_hide_button(post) + if user_signed_in? && current_user.owns?(post) + link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete') + else + link_to image_tag('deletelabel.png'), share_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete vis_hide", :title => t('.hide_and_mute') end end end \ No newline at end of file diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 2860afab9..69c10c477 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -37,8 +37,7 @@ class StatusMessage < Post def self.tag_stream(user, tag_array, max_time, order) owned_or_visible_by_user(user). - joins(:tags).where(:tags => {:name => tag_array}). - for_a_stream(max_time, order) + joins(:tags).where(:tags => {:name => tag_array}) end def text(opts = {}) diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 5ef3067a7..4aa415ddd 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -19,8 +19,8 @@ #gs-shim{:title => "3. #{t('.stay_updated')}", 'data-content' => t('.stay_updated_explanation')} #main_stream.stream{:data => {:guids => stream.aspect_ids.join(','), :time_for_scroll => time_for_scroll(stream.ajax_stream?, stream)}} - - if !stream.ajax_stream? && stream.posts.length > 0 - = render 'shared/stream', :posts => stream.posts + - if !stream.ajax_stream? && stream.stream_posts.length > 0 + = render 'shared/stream', :posts => stream.stream_posts #pagination =link_to(t('more'), next_page_path(:ajax_stream => stream.ajax_stream?), :class => 'paginate') diff --git a/app/views/aspects/index.mobile.haml b/app/views/aspects/index.mobile.haml index 806b88d18..4c5ab0cb9 100644 --- a/app/views/aspects/index.mobile.haml +++ b/app/views/aspects/index.mobile.haml @@ -9,8 +9,8 @@ = @stream.aspect #main_stream.stream - = render 'shared/stream', :posts => @stream.posts - -if @stream.posts.length > 0 + = render 'shared/stream', :posts => @stream.stream_posts + -if @stream.stream_posts.length > 0 #pagination %a.more-link.paginate{:href => next_page_path} %h1 diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 05d4e76a6..185152750 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -27,12 +27,12 @@ = render 'people/sub_header', :person => @person, :contact => @contact / hackity hack until we get a photo stream - - if (@posts && @posts.length > 0) || (defined?(@stream) && @stream.posts.length > 0) + - if (@posts && @posts.length > 0) || @stream.stream_posts.length > 0 -if @post_type == :photos = render 'photos/index', :photos => @posts - else #main_stream.stream - = render 'shared/stream', :posts => @stream.posts + = render 'shared/stream', :posts => @stream.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 414b9a875..c07b90bf9 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 @stream.posts.length > 0 +- if @stream.stream_posts.length > 0 -if @post_type == :photos - = render 'photos/index', :photos => @stream.posts + = render 'photos/index', :photos => @stream.stream_posts - else #main_stream.stream - = render 'shared/stream', :posts => @stream.posts + = render 'shared/stream', :posts => @stream.stream_posts #pagination =link_to(t('more'), next_page_path, :class => 'paginate') - else diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 59689c821..1e55edeab 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -5,11 +5,7 @@ .stream_element{:id => post.guid, :class => from_group(post)} .right.controls - - if current_user && post.author.owner_id == current_user.id - = link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete') - - else - = link_to image_tag('deletelabel.png'), share_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete vis_hide", :title => t('.hide_and_mute') - + = delete_or_hide_button(post) = block_user_control(post.author) = image_tag 'ajax-loader.gif', :class => "hide_loader hidden" diff --git a/app/views/tags/show.haml b/app/views/tags/show.haml index 99f2dae38..8d8ca74d8 100644 --- a/app/views/tags/show.haml +++ b/app/views/tags/show.haml @@ -67,8 +67,8 @@ %hr #main_stream.stream - - if @stream.posts.length > 0 - = render 'shared/stream', :posts => @stream.posts + - if @stream.stream_posts.length > 0 + = render 'shared/stream', :posts => @stream.stream_posts #pagination =link_to(t('more'), next_page_path, :class => 'paginate') - else diff --git a/app/views/tags/show.mobile.haml b/app/views/tags/show.mobile.haml index d87643c3d..a99d0387c 100644 --- a/app/views/tags/show.mobile.haml +++ b/app/views/tags/show.mobile.haml @@ -6,8 +6,8 @@ = @stream.display_tag_name #main_stream.stream - = render 'shared/stream', :posts => @stream.posts - -if @stream.posts.length > 0 + = render 'shared/stream', :posts => @stream.stream_posts + -if @stream.stream_posts.length > 0 #pagination %a.more-link.paginate{:href => next_page_path} %h1 diff --git a/lib/stream/aspect.rb b/lib/stream/aspect.rb index 33cd3a662..3ddacf0ae 100644 --- a/lib/stream/aspect.rb +++ b/lib/stream/aspect.rb @@ -43,7 +43,7 @@ class Stream::Aspect < Stream::Base :type => TYPES_OF_POST_IN_STREAM, :order => "#{order} DESC", :max_time => max_time - ).for_a_stream(max_time, order, user) + ) end # @return [ActiveRecord::Association] AR association of people within stream's given aspects diff --git a/lib/stream/base.rb b/lib/stream/base.rb index a117ee996..cd8076e34 100644 --- a/lib/stream/base.rb +++ b/lib/stream/base.rb @@ -43,7 +43,11 @@ class Stream::Base # @return [ActiveRecord::Relation] def posts - [] + Post.scoped + end + + def stream_posts + self.posts.for_a_stream(max_time, order, user) end # @return [ActiveRecord::Association] AR association of people within stream's given aspects diff --git a/lib/stream/community_spotlight.rb b/lib/stream/community_spotlight.rb index dee1ed33a..340bda6c0 100644 --- a/lib/stream/community_spotlight.rb +++ b/lib/stream/community_spotlight.rb @@ -20,7 +20,7 @@ class Stream::CommunitySpotlight < Stream::Base end def posts - Post.all_public.where(:author_id => people.map{|x| x.id}).for_a_stream(max_time, order) + Post.all_public.where(:author_id => people.map{|x| x.id}) end def people diff --git a/lib/stream/mention.rb b/lib/stream/mention.rb index b385f5af9..83ad8b773 100644 --- a/lib/stream/mention.rb +++ b/lib/stream/mention.rb @@ -13,7 +13,7 @@ class Stream::Mention < Stream::Base # @return [ActiveRecord::Association] AR association of 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) end def contacts_title diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index 235990c9a..75398e902 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -19,7 +19,7 @@ class Stream::Multi < Stream::Base @posts ||= lambda do post_ids = aspects_post_ids + followed_tags_post_ids + mentioned_post_ids post_ids += community_spotlight_post_ids if include_community_spotlight? - Post.where(:id => post_ids).for_a_stream(max_time, order, user) + Post.where(:id => post_ids) end.call end diff --git a/lib/stream/person.rb b/lib/stream/person.rb index 83cd47d4b..87c2442f3 100644 --- a/lib/stream/person.rb +++ b/lib/stream/person.rb @@ -15,9 +15,9 @@ class Stream::Person < Stream::Base def posts @posts ||= lambda do if user - posts = self.user.posts_from(@person).for_a_stream(max_time, order) + posts = self.user.posts_from(@person) else - posts = @person.posts.where(:public => true).for_a_stream(max_time, order) + posts = @person.posts.where(:public => true) end posts end.call diff --git a/lib/stream/public.rb b/lib/stream/public.rb index 74872a903..f5b6f421a 100644 --- a/lib/stream/public.rb +++ b/lib/stream/public.rb @@ -13,7 +13,7 @@ class Stream::Public < Stream::Base # @return [ActiveRecord::Association] AR association of posts def posts - @posts ||= Post.all_public.for_a_stream(max_time, order) + @posts ||= Post.all_public end diff --git a/lib/stream/tag.rb b/lib/stream/tag.rb index 48528964d..375a643a9 100644 --- a/lib/stream/tag.rb +++ b/lib/stream/tag.rb @@ -52,6 +52,6 @@ class Stream::Tag < Stream::Base else posts = posts.all_public end - posts.tagged_with(tag_name).for_a_stream(max_time, 'created_at') + posts.tagged_with(tag_name) end end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 650b5dee3..62305276a 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -242,7 +242,7 @@ describe PeopleController do it 'is sorted by created_at desc' do get :show, :id => @person.id - assigns[:stream].posts.should == @public_posts.sort_by{|p| p.created_at}.reverse + assigns[:stream].stream_posts.should == @public_posts.sort_by{|p| p.created_at}.reverse end end diff --git a/spec/controllers/tag_followings_controller_spec.rb b/spec/controllers/tag_followings_controller_spec.rb index dfb17a2f2..613ef8485 100644 --- a/spec/controllers/tag_followings_controller_spec.rb +++ b/spec/controllers/tag_followings_controller_spec.rb @@ -13,6 +13,7 @@ describe TagFollowingsController do before do @tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent") sign_in :user, bob + bob.followed_tags.create(:name => "testing") end describe 'index' do