diff --git a/app/helpers/stream_element_helper.rb b/app/helpers/stream_element_helper.rb index a023ea04b9793dd7e53e70a5761a3104d3928a93..7b7da572eec68b244f35249039217a99c55b6270 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 2860afab9fd78c727716e5f9429437d5f4469644..69c10c47704cd61543b839afdeb139470ece2efa 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 5ef3067a7d7cfbdf35aebac1d5bb7929335f8521..4aa415dddf010c811e774427cad348204ff30ee2 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 806b88d1875ea500fc27d099c1ae2c7e0ac4381c..4c5ab0cb91b35d9ad44ee3cd92757ba8f5654cc8 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 05d4e76a6d176d828dd458f25b1d64b9035bf86f..1851527503df384df38c976eeb2647103a94cd52 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 414b9a8751dcfc186c1693a3ac3ba9e7cf61e3c1..c07b90bf9190946321e7a1da124c8afdac6d50e0 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 59689c821c5b2037ee55b339b838ee46bb5f973a..1e55edeab1980eba746fd375b5852972cb5d7bdc 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 99f2dae386366f1fa532f3d6858963fad5b90385..8d8ca74d8f1edeec3feab93c8f871bc57f4873f7 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 d87643c3db5e889f0516faed202eb20253fbf625..a99d0387cab24ce70e10924d7d00674b826bd7cf 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 33cd3a662f2e0db4fd61a05dc847f06badf574be..3ddacf0ae5ba02fba407046f6be9c1224cc2c04b 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<Person>] AR association of people within stream's given aspects diff --git a/lib/stream/base.rb b/lib/stream/base.rb index a117ee996c00b615c8cf1c5580c5ae0ee7812aad..cd8076e349bc54c1246ae5ab9d01bc313e4ad611 100644 --- a/lib/stream/base.rb +++ b/lib/stream/base.rb @@ -43,7 +43,11 @@ class Stream::Base # @return [ActiveRecord::Relation<Post>] def posts - [] + Post.scoped + end + + def stream_posts + self.posts.for_a_stream(max_time, order, user) end # @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects diff --git a/lib/stream/community_spotlight.rb b/lib/stream/community_spotlight.rb index dee1ed33a747f96117cdee896ce23f4436e62adc..340bda6c0721f4d68a5332e85558260c62bd2b8c 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 b385f5af931d6b8ad35d65f5f20b82564cbfba14..83ad8b773a3d68f50c0b5c098be50a3b02367c26 100644 --- a/lib/stream/mention.rb +++ b/lib/stream/mention.rb @@ -13,7 +13,7 @@ class Stream::Mention < Stream::Base # @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) + @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 235990c9a8e9347aae2426cb5b7d9094c91c2718..75398e9022d3c1f7c070bcd0f4faed213a3c00b9 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 83cd47d4b8f6b0678f660778b1cec77c47b8949f..87c2442f3d19431c266df9be24def11b9dd284e2 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 74872a9037002bbe5100c204f7a339b810f0583a..f5b6f421aa82ace5a9f4b1493bfe84650d295ee6 100644 --- a/lib/stream/public.rb +++ b/lib/stream/public.rb @@ -13,7 +13,7 @@ class Stream::Public < Stream::Base # @return [ActiveRecord::Association<Post>] 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 48528964dd4ffe1bb676dc37ab571285cbe1c72d..375a643a95bf9b2a5402e55886cce0b7e3def480 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 650b5dee3412ca0ad5bb34602278f9d0827053ef..62305276ab0282ad34b5c24b33052373ced43e9b 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 dfb17a2f2f3ff68c1d9e5ee846a91959180663ea..613ef8485af013020a309ab103163d6b5faaf70e 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