mentions: include mentioner in subject line.

The template looks like this:

Subject:

    #{creator_name} mentioned you in a comment on post ##{post_id}

Body:

    @#{creator_name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:

    [quote]
    #{DText.excerpt(body, "@"+user_name)}
    [/quote]
This commit is contained in:
evazion 2017-02-25 22:28:21 -06:00
parent 6994231801
commit 46280f2227
6 changed files with 31 additions and 12 deletions

View File

@ -381,5 +381,12 @@ class DText
})
)
end
# extract the first paragraph `needle` occurs in.
def self.excerpt(dtext, needle)
dtext = dtext.gsub(/\r\n|\r|\n/, "\n")
excerpt = ActionController::Base.helpers.excerpt(dtext, needle, separator: "\n\n", radius: 1, omission: "")
excerpt
end
end

View File

@ -39,17 +39,17 @@ module Mentionable
end
def queue_mention_messages
title = self.class.mentionable_option(:title)
from_id = read_attribute(self.class.mentionable_option(:user_field))
text = strip_quote_blocks(read_attribute(self.class.mentionable_option(:message_field)))
bodies = {}
text.scan(DText::MENTION_REGEXP).each do |mention|
names = text.scan(DText::MENTION_REGEXP).map do |mention|
mention.gsub!(/(?:^\s*@)|(?:[:;,.!?\)\]<>]$)/, "")
bodies[mention] = self.class.mentionable_option(:body).call(self, mention)
end
bodies.each do |name, text|
names.uniq.each do |name|
body = self.instance_exec(name, &self.class.mentionable_option(:body))
title = self.instance_exec(name, &self.class.mentionable_option(:title))
Dmail.create_automated(to_name: name, title: title, body: body)
end
end

View File

@ -23,9 +23,9 @@ class Comment < ActiveRecord::Base
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\":/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)}"}
)
:title => lambda {|user_name| "#{creator_name} mentioned you in a comment on post ##{post_id}"},
:body => lambda {|user_name| "@#{creator_name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n"},
)
module SearchMethods
def recent

View File

@ -28,8 +28,8 @@ class ForumPost < ActiveRecord::Base
mentionable(
: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}\":/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)}"}
:title => lambda {|user_name| %{#{creator_name} mentioned you in topic ##{topic_id} (#{topic.title})}},
:body => lambda {|user_name| %{@#{creator_name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n}},
)
module SearchMethods

View File

@ -57,7 +57,13 @@ class CommentTest < ActiveSupport::TestCase
end
dmail = Dmail.last
assert_equal("You were mentioned in a \"comment\":/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)
assert_equal(<<-EOS.strip_heredoc, dmail.body)
@#{CurrentUser.name} mentioned you in a \"comment\":/posts/#{@comment.post_id}#comment-#{@comment.id} on post ##{@comment.post_id}:
[quote]
Hey @#{@user2.name} check this out!
[/quote]
EOS
end
end
end

View File

@ -51,7 +51,13 @@ class ForumPostTest < ActiveSupport::TestCase
end
dmail = Dmail.last
assert_equal("You were mentioned in the forum topic \"#{@topic.title}\":/forum_topics/#{@topic.id}?page=1\n\n---\n\n[i]#{@user.name} said:[/i]\n\nHey @#{@user2.name} check this out!", dmail.body)
assert_equal(<<-EOS.strip_heredoc, dmail.body)
@#{CurrentUser.name} mentioned you in topic ##{@topic.id} (\"#{@topic.title}\":[/forum_topics/#{@topic.id}?page=1]):
[quote]
Hey @#{@user2.name} check this out!
[/quote]
EOS
end
end
end