diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 1551aa41d..192b2891a 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -31,11 +31,13 @@ module CommentsHelper end end - def commenting_disabled? + def commenting_disabled?(post) return true unless user_signed_in? if defined?(@commenting_disabled) - return @commenting_disabled - else + @commenting_disabled + elsif defined?(@stream) + !@stream.can_comment?(post) + else false end end diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 365f57c36..fd8a9834e 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -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) diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml index 857c8f796..b7df16c82 100644 --- a/app/views/comments/_comments.html.haml +++ b/app/views/comments/_comments.html.haml @@ -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) diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 27887dd22..10ccd9937 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -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') diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index bed2cdd68..effc52129 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -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 diff --git a/app/views/posts/show.mobile.haml b/app/views/posts/show.mobile.haml index 767952d8d..84d886908 100644 --- a/app/views/posts/show.mobile.haml +++ b/app/views/posts/show.mobile.haml @@ -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} diff --git a/app/views/shared/_stream.haml b/app/views/shared/_stream.haml index ee849ca11..74a06e827 100644 --- a/app/views/shared/_stream.haml +++ b/app/views/shared/_stream.haml @@ -4,6 +4,4 @@ = render :partial => 'shared/stream_element', :collection => posts, - :as => :post, - :locals => { :commenting_disabled => commenting_disabled?} - + :as => :post diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 38ddc9079..e2f3dcb1c 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -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) diff --git a/diaspora_development b/diaspora_development new file mode 100644 index 000000000..ae9b55f67 Binary files /dev/null and b/diaspora_development differ diff --git a/diaspora_test b/diaspora_test new file mode 100644 index 000000000..9bfaabec2 Binary files /dev/null and b/diaspora_test differ diff --git a/lib/base_stream.rb b/lib/base_stream.rb index d8c0cefcf..780ed6e37 100644 --- a/lib/base_stream.rb +++ b/lib/base_stream.rb @@ -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 diff --git a/lib/stream/tag_stream.rb b/lib/stream/tag_stream.rb index 772a933a0..3a96d8287 100644 --- a/lib/stream/tag_stream.rb +++ b/lib/stream/tag_stream.rb @@ -14,16 +14,12 @@ class TagStream < BaseStream # @return [ActiveRecord::Association] 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] 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