diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index b334bcd0a..cfb18b30c 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -18,14 +18,22 @@ class CommentsController < ApplicationController if @comment.save(:safe => true) raise 'MongoMapper failed to catch a failed save' unless @comment.id Rails.logger.info("event=comment_create user=#{current_user.diaspora_handle} status=success comment=#{@comment.id}") - current_user.dispatch_comment(@comment) respond_to do |format| - format.js{ render :json => { :post_id => @comment.post_id, + format.js{ + json = { :post_id => @comment.post_id, :comment_id => @comment.id, - :html => render_to_string(:partial => type_partial(@comment), :locals => {:comment => @comment, :person => current_user, :current_user => current_user})}, - :status => 201 } + :html => render_to_string( + :partial => 'comments/comment', + :locals => { + :comment => @comment, + :person => current_user, + } + ) + } + render(:json => json, :status => 201) + } format.html{ render :nothing => true, :status => 201 } end else diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index a0109425d..430264fee 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -27,7 +27,7 @@ module SocketsHelper elsif object.is_a? Person v = render_to_string(:partial => type_partial(object), :locals => {:single_aspect_form => opts[:single_aspect_form], :person => object, :aspects => user.aspects, :current_user => user}) elsif object.is_a? Comment - v = render_to_string(:partial => type_partial(object), :locals => {:comment => object, :person => object.person, :current_user => user}) + v = render_to_string(:partial => 'comments/comment', :locals => {:comment => object, :person => object.person}) else v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction end diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index ee01ba670..629afa4cd 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -3,23 +3,11 @@ -# the COPYRIGHT file. %li.comment{:data=>{:guid=>comment.id}} - /-start=Time.now %a{:href => "/people/#{person.id}"} %img{:src => image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id} - /- post_image_link=Time.now .content .from %a{:href => "/people/#{person.id}"}=person.real_name - /- post_person_link=Time.now = markdownify(comment.text, :youtube_maps => comment[:youtube_titles]) - /- markdownified=Time.now %div.time - = "#{time_ago_in_words(comment.updated_at)} #{t('ago')}" - /- time_agoed=Time.now -/- log_string = "event=comment_partial im_link=#{(post_image_link - start)*1000} " -/- log_string << "pr_link=#{(post_person_link - post_image_link)*1000} " -/- log_string << "markdown=#{(markdownified - post_person_link)*1000} " -/- log_string << "time_agoed=#{(time_agoed - markdownified)*1000} " -/- log_string << "total=#{(time_agoed - start)*1000} " -/- log_string << "comment_id=#{comment.id}" -/- Rails.logger.info(log_string) + = comment.created_at ? "#{time_ago_in_words(comment.created_at)} #{t('ago')}" : time_ago_in_words(Time.now) diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 0cafb34d6..28ecf77f1 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -2,7 +2,7 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= form_tag( comments_path, :id => "new_comment_on_#{post_id}" , :remote => true) do += form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do %p = label_tag "comment_text_on_#{post_id}", t('.comment') = text_area_tag :text, nil, :rows => 1, :class => "comment_box",:id => "comment_text_on_#{post_id}" diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index a1ac1fd06..992dd37cf 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -30,6 +30,7 @@ describe CommentsController do it 'responds to format js' do post :create, comment_hash.merge(:format => 'js') response.code.should == '201' + response.body.should match comment_hash[:text] end end