Commit 5b836511 authored by Dan Hansen & Maxwell Salzberg's avatar Dan Hansen & Maxwell Salzberg Committed by danielgrippi
Browse files

Stream#posts no longer needs to call for_a_stream

exclude blocked users from all streams
parent 0eb33b37
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
......@@ -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 = {})
......
......@@ -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')
......
......@@ -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
......
......@@ -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')
......
......@@ -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
......
......@@ -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"
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment