Merge branch 'comment_on_tagged_psts'
This commit is contained in:
commit
6f00b047b1
18 changed files with 96 additions and 38 deletions
|
|
@ -9,7 +9,6 @@ class TagFollowingsController < ApplicationController
|
||||||
before_filter :save_sort_order, :only => :index
|
before_filter :save_sort_order, :only => :index
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@commenting_disabled = true
|
|
||||||
@stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
|
@stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
|
||||||
if params[:only_posts]
|
if params[:only_posts]
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
ContentUpdater.addCommentToPost("<%= @comment.post.guid %>",
|
ContentUpdater.addCommentToPost("<%= @comment.post.guid %>",
|
||||||
"<%= @comment.guid%>",
|
"<%= @comment.guid%>",
|
||||||
"<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person}))%>");
|
"<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person, :post => @comment.post}))%>");
|
||||||
|
|
|
||||||
|
|
@ -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')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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}
|
||||||
|
|
|
||||||
|
|
@ -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?}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
BIN
diaspora_development
Normal file
Binary file not shown.
BIN
diaspora_test
Normal file
BIN
diaspora_test
Normal file
Binary file not shown.
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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,17 @@ class TagStream < BaseStream
|
||||||
I18n.translate('streams.tags.contacts_title')
|
I18n.translate('streams.tags.contacts_title')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_comment?(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] ||= user.person.id == post.author.id
|
||||||
|
@can_comment_cache[post.id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def contacts_in_stream
|
||||||
|
@contacts_in_stream ||= Contact.where(:user_id => user.id, :person_id => people.map{|x| x.id}).all
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def tag_string
|
def tag_string
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jQuery("abbr.timeago").timeago();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,42 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe CommentsHelper do
|
describe CommentsHelper do
|
||||||
before do
|
describe '.new_comment_form' do
|
||||||
@user = alice
|
before do
|
||||||
@aspect = @user.aspects.first
|
@user = alice
|
||||||
@post = @user.post(:status_message, :text => "hi", :to => @aspect.id)
|
@aspect = @user.aspects.first
|
||||||
end
|
@post = @user.post(:status_message, :text => "hi", :to => @aspect.id)
|
||||||
it 'renders a new comment form' do
|
end
|
||||||
new_comment_form(@post.id, @user).should ==
|
it 'renders a new comment form' do
|
||||||
@controller.render_to_string(:partial => 'comments/new_comment',
|
new_comment_form(@post.id, @user).should ==
|
||||||
:locals => {:post_id => @post.id, :current_user => @user})
|
@controller.render_to_string(:partial => 'comments/new_comment',
|
||||||
end
|
:locals => {:post_id => @post.id, :current_user => @user})
|
||||||
it 'renders it fast the second time' do
|
end
|
||||||
new_comment_form(@post.id, @user)
|
it 'renders it fast the second time' do
|
||||||
time = Benchmark.realtime{
|
|
||||||
new_comment_form(@post.id, @user)
|
new_comment_form(@post.id, @user)
|
||||||
}
|
time = Benchmark.realtime{
|
||||||
(time*1000).should < 1
|
new_comment_form(@post.id, @user)
|
||||||
|
}
|
||||||
|
(time*1000).should < 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'commenting_disabled?' do
|
||||||
|
it 'returns true if @commenting_disabled is set' do
|
||||||
|
@commenting_disabled = true
|
||||||
|
commenting_disabled?(stub).should_be true
|
||||||
|
@commenting_disabled = false
|
||||||
|
commenting_disabled?(stub).should_be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns @stream.can_comment? if @stream is set' do
|
||||||
|
post = stub
|
||||||
|
@stream = stub
|
||||||
|
@stream.should_receive(:can_comment?).with(post).and_return(true)
|
||||||
|
commenting_disabled?(post).should_be true
|
||||||
|
|
||||||
|
@stream.should_receive(:can_comment?).with(post).and_return(false)
|
||||||
|
commenting_disabled?(post).should_be false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,26 @@ describe TagStream do
|
||||||
describe 'shared behaviors' do
|
describe 'shared behaviors' do
|
||||||
it_should_behave_like 'it is a stream'
|
it_should_behave_like 'it is a stream'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.can_comment?' do
|
||||||
|
before do
|
||||||
|
@stream = TagStream.new(alice)
|
||||||
|
@stream.stub(:people).and_return([bob.person])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true if user is a contact of the post author' do
|
||||||
|
post = Factory(:status_message, :author => bob.person)
|
||||||
|
@stream.can_comment?(post).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true if a user is the author of the post' do
|
||||||
|
post = Factory(:status_message, :author => alice.person)
|
||||||
|
@stream.can_comment?(post).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false otherwise' do
|
||||||
|
post = Factory(:status_message, :author => eve.person)
|
||||||
|
@stream.can_comment?(post).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ describe 'Streams' do
|
||||||
@stream.order=nil
|
@stream.order=nil
|
||||||
@stream.order.should == 'created_at'
|
@stream.order.should == 'created_at'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should have can_comment?(post)' do
|
||||||
|
@stream.can_comment?(Factory(:status_message)).should_not be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue