diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 1717dff17..aee396324 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -18,22 +18,6 @@ } } - Danbooru.Comment.quote_message = function(data) { - var blocks = data["body"].match(/\[\/?quote\]|.|\n|\r/gm); - var n = 0; - var stripped_body = ""; - $.each(blocks, function(i, block) { - if (block === "[quote]") { - n += 1; - } else if (block == "[/quote]") { - n -= 1; - } else if (n === 0) { - stripped_body += block; - } - }); - return "[quote]\n" + data["creator_name"] + " said:\n\n" + stripped_body + "\n[/quote]\n\n"; - } - Danbooru.Comment.quote = function(e) { $.get( "/comments/" + $(e.target).data('comment-id') + ".json", @@ -41,7 +25,7 @@ var $link = $(e.target); var $div = $link.closest("div.comments-for-post").find(".new-comment"); var $textarea = $div.find("textarea"); - var msg = Danbooru.Comment.quote_message(data); + var msg = data["quoted_response"]; if ($textarea.val().length > 0) { msg = $textarea.val() + "\n\n" + msg; } diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 86a97ddb9..0f59a2b9f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -48,7 +48,7 @@ class CommentsController < ApplicationController def show @comment = Comment.find(params[:id]) - respond_with(@comment) + respond_with(@comment, methods: [:quoted_response]) end def destroy diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 2a22293d6..a41e6fd98 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -12,6 +12,11 @@ class DText CGI.escapeHTML(string) end + def self.quote(message, creator_name) + stripped_body = DText.strip_blocks(message, "quote") + "[quote]\n#{creator_name} said:\n\n#{stripped_body}\n[/quote]\n\n" + end + def self.strip_blocks(string, tag) n = 0 stripped = "" diff --git a/app/models/comment.rb b/app/models/comment.rb index b4652eb7c..c48acfb7c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -249,6 +249,10 @@ class Comment < ActiveRecord::Base def undelete! update({ :is_deleted => false }, :as => CurrentUser.role) end + + def quoted_response + DText.quote(body, creator_name) + end end Comment.connection.extend(PostgresExtensions) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 5e299b75e..a6b47c852 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -234,8 +234,7 @@ class ForumPost < ActiveRecord::Base end def quoted_response - stripped_body = DText.strip_blocks(body, "quote") - "[quote]\n#{creator_name} said:\n\n#{stripped_body}\n[/quote]\n\n" + DText.quote(body, creator_name) end def forum_topic_page