enable mention for comments #2466
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.initialize_mention_autocomplete = function() {
|
||||
var $fields = $("#forum_post_body");
|
||||
var $fields = $("#forum_post_body,.comment-form textarea");
|
||||
$fields.autocomplete({
|
||||
delay: 500,
|
||||
minLength: 2,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
include Mentionable
|
||||
|
||||
validate :validate_creator_is_not_limited, :on => :create
|
||||
validates_format_of :body, :with => /\S/, :message => 'has no content'
|
||||
belongs_to :post
|
||||
@@ -10,6 +12,12 @@ class Comment < ActiveRecord::Base
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_destroy :update_last_commented_at_on_destroy
|
||||
attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:user_field => :creator_id,
|
||||
:title => "You were mentioned in a comment",
|
||||
:body => lambda {|rec, user_name| "You were mentioned in a \"comment\":http://#{Danbooru.config.hostname}/posts/#{rec.post_id}#comment-#{rec.id}\n\n---\n\n[i]#{rec.creator.name} said:[/i]\n\n#{ActionController::Base.helpers.excerpt(rec.body, user_name)}"}
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
def recent
|
||||
|
||||
@@ -22,7 +22,7 @@ class ForumPost < ActiveRecord::Base
|
||||
:message_field => :body,
|
||||
:user_field => :creator_id,
|
||||
:title => "You were mentioned in a forum topic",
|
||||
:body => lambda {|rec, user_name| "You were mentioned in the forum topic \"#{rec.topic.title}\":http://#{Danbooru.config.hostname}/forum_topics/#{rec.topic_id}?page=#{rec.forum_topic_page}\n\n---\n\n#{ActionController::Base.helpers.excerpt(rec.body, user_name)}"}
|
||||
:body => lambda {|rec, user_name| "You were mentioned in the forum topic \"#{rec.topic.title}\":http://#{Danbooru.config.hostname}/forum_topics/#{rec.topic_id}?page=#{rec.forum_topic_page}\n\n---\n\n[i]#{rec.creator.name} said:[/i]\n\n#{ActionController::Base.helpers.excerpt(rec.body, user_name)}"}
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="comment-preview dtext dtext-preview">
|
||||
</div>
|
||||
|
||||
<%= form_tag(comments_path, :class => "simple_form") do %>
|
||||
<%= form_tag(comments_path, :class => "simple_form comment-form") do %>
|
||||
<%= hidden_field "comment", "post_id", :value => post.id %>
|
||||
<%= dtext_field "comment", "body", :input_id => "comment_response_for_#{post.id}", :preview_id => "dtext-preview-for-#{post.id}" %>
|
||||
<%= submit_tag "Post", :data => { :disable_with => "Submitting..." } %>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<% if CurrentUser.is_moderator? || !comment.is_deleted? %>
|
||||
<a name="comment-<%= comment.id %>"></a>
|
||||
<article class="comment" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator.name %>">
|
||||
<div class="author">
|
||||
<h1>
|
||||
|
||||
@@ -14,6 +14,55 @@ class CommentTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
|
||||
context "that mentions a user" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
Danbooru.config.stubs(:member_comment_limit).returns(100)
|
||||
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
||||
end
|
||||
|
||||
context "in a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user, :created_at => 2.weeks.ago)
|
||||
end
|
||||
|
||||
should "not create a dmail" do
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 1) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "outside a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@comment = FactoryGirl.build(:comment, :post_id => @post.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
end
|
||||
|
||||
should "create a dmail" do
|
||||
assert_difference("Dmail.count", 1) do
|
||||
@comment.save
|
||||
end
|
||||
|
||||
dmail = Dmail.last
|
||||
assert_equal("You were mentioned in a \"comment\":http://#{Danbooru.config.hostname}/posts/#{@comment.post_id}#comment-#{@comment.id}\n\n---\n\n[i]#{CurrentUser.name} said:[/i]\n\nHey @#{@user2.name} check this out!", dmail.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "created by a limited user" do
|
||||
setup do
|
||||
Danbooru.config.stubs(:member_comment_limit).returns(5)
|
||||
|
||||
Reference in New Issue
Block a user