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,11 +31,13 @@ module CommentsHelper
end end
end end
def commenting_disabled? def commenting_disabled?(post)
return true unless user_signed_in? return true unless user_signed_in?
if defined?(@commenting_disabled) if defined?(@commenting_disabled)
return @commenting_disabled @commenting_disabled
else elsif defined?(@stream)
!@stream.can_comment?(post)
else
false false
end end
end end

View file

@ -22,7 +22,7 @@
.likes_container .likes_container
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes_count, :target_type => "Comment" = 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 %span.like_action
= like_action(comment, current_user) = like_action(comment, current_user)

View file

@ -13,6 +13,6 @@
-else -else
= render :partial => 'comments/comment', :collection => post.comments, :locals => {:post => post} = 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_wrapper{:class => comment_form_wrapper_class(post)}
= new_comment_form(post.id, current_user) = new_comment_form(post.id, current_user)

View file

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

View file

@ -8,7 +8,7 @@
- if @post.is_a?(Photo) - if @post.is_a?(Photo)
= render 'posts/photo', :post => @post = render 'posts/photo', :post => @post
- else - 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 %br
%br %br

View file

@ -4,4 +4,4 @@
.stream .stream
= render :partial => 'shared/stream_element', = 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', = render :partial => 'shared/stream_element',
:collection => posts, :collection => posts,
:as => :post, :as => :post
:locals => { :commenting_disabled => commenting_disabled?}

View file

@ -68,7 +68,7 @@
– –
- unless commenting_disabled? - unless commenting_disabled?(post)
%span.like_action %span.like_action
= like_action(post, current_user) = like_action(post, current_user)
@ -84,4 +84,4 @@
.likes_container .likes_container
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes_count, :current_user => current_user, :target_type => "Post" = 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) Rails.application.routes.url_helpers.mentions_path(opts)
end end
def can_comment?(post)
true
end
def title def title
'a title' 'a title'
end end

View file

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