This commit is contained in:
maxwell 2011-10-03 22:46:34 -07:00 committed by Maxwell Salzberg
parent c2bb483b21
commit eef054dc5e
12 changed files with 31 additions and 21 deletions

View file

@ -31,10 +31,12 @@ module CommentsHelper
end
end
def commenting_disabled?
def commenting_disabled?(post)
return true unless user_signed_in?
if defined?(@commenting_disabled)
return @commenting_disabled
@commenting_disabled
elsif defined?(@stream)
!@stream.can_comment?(post)
else
false
end

View file

@ -22,7 +22,7 @@
.likes_container
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes_count, :target_type => "Comment"
- unless commenting_disabled?
- unless commenting_disabled?(post)
%span.like_action
= like_action(comment, current_user)

View file

@ -13,6 +13,6 @@
-else
= render :partial => 'comments/comment', :collection => post.comments, :locals => {:post => post}
- unless commenting_disabled?
- unless commenting_disabled?(post)
.new_comment_form_wrapper{:class => comment_form_wrapper_class(post)}
= new_comment_form(post.id, current_user)

View file

@ -31,7 +31,7 @@
= render 'photos/index', :photos => @posts
- else
#main_stream.stream
= render 'shared/stream', :posts => @posts, :commenting_disabled => commenting_disabled?
= render 'shared/stream', :posts => @posts
#pagination
=link_to(t('more'), next_page_path, :class => 'paginate')

View file

@ -8,7 +8,7 @@
- if @post.is_a?(Photo)
= render 'posts/photo', :post => @post
- else
= render 'shared/stream_element', :post => @post, :commenting_disabled => commenting_disabled?
= render 'shared/stream_element', :post => @post, :commenting_disabled => commenting_disabled?(@post)
%br
%br
%br

View file

@ -4,4 +4,4 @@
.stream
= render :partial => 'shared/stream_element',
:locals => {:post => @post, :commenting_disabled => commenting_disabled?, :expanded_info => true}
:locals => {:post => @post, :commenting_disabled => commenting_disabled?(@post), :expanded_info => true}

View file

@ -4,6 +4,4 @@
= render :partial => 'shared/stream_element',
:collection => posts,
:as => :post,
:locals => { :commenting_disabled => commenting_disabled?}
:as => :post

View file

@ -68,7 +68,7 @@
–
- unless commenting_disabled?
- unless commenting_disabled?(post)
%span.like_action
= like_action(post, current_user)
@ -84,4 +84,4 @@
.likes_container
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes_count, :current_user => current_user, :target_type => "Post"
= render "comments/comments", :post => post, :current_user => current_user, :commenting_disabled => commenting_disabled?
= render "comments/comments", :post => post, :current_user => current_user, :commenting_disabled => commenting_disabled?(post)

BIN
diaspora_development Normal file

Binary file not shown.

BIN
diaspora_test Normal file

Binary file not shown.

View file

@ -14,6 +14,10 @@ class BaseStream
Rails.application.routes.url_helpers.mentions_path(opts)
end
def can_comment?(post)
true
end
def title
'a title'
end

View file

@ -14,16 +14,12 @@ class TagStream < BaseStream
# @return [ActiveRecord::Association<Post>] AR association of posts
def posts
if tag_string.empty?
[]
else
@posts ||= StatusMessage.owned_or_visible_by_user(user).
joins(:tags).where(:tags => {:name => tag_array}).
for_a_stream(@max_time, @order)
end
return [] if tag_string.empty?
@posts ||= StatusMessage.owned_or_visible_by_user(user).
joins(:tags).where(:tags => {:name => tag_array}).
for_a_stream(@max_time, @order)
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= posts.map{|p| p.author}.uniq
end
@ -32,6 +28,16 @@ class TagStream < BaseStream
I18n.translate('streams.tags.contacts_title')
end
def can_comment_on?(post)
@can_comment_cache ||= {}
@can_comment_cache[post.id] ||= contacts_in_stream.find{|contact| contact.person_id == post.author.id}.present?
@can_comment_cache[post.id]
end
def contacts_in_stream
@contacts_in_stream ||= Contact.where(:user => user, :person => people).all
end
private
def tag_string