enable mention for comments #2466

This commit is contained in:
r888888888
2015-11-30 16:51:07 -08:00
parent e24d6e49bc
commit 8a63fb0f7c
6 changed files with 61 additions and 3 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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..." } %>

View File

@@ -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>