dont create dmails when mentioned in a quote block #2466
This commit is contained in:
@@ -16,10 +16,32 @@ module Mentionable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def strip_quote_blocks(str)
|
||||||
|
stripped = ""
|
||||||
|
str.gsub!(/\s*\[quote\](?!\])\s*/m, "\n\n[quote]\n\n")
|
||||||
|
str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n")
|
||||||
|
str.gsub!(/(?:\r?\n){3,}/, "\n\n")
|
||||||
|
str.strip!
|
||||||
|
nest = 0
|
||||||
|
str.split(/\n{2}/).each do |block|
|
||||||
|
if block == "[quote]"
|
||||||
|
nest += 1
|
||||||
|
|
||||||
|
elsif block == "[/quote]"
|
||||||
|
nest -= 1
|
||||||
|
|
||||||
|
elsif nest == 0
|
||||||
|
stripped << "#{block}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stripped
|
||||||
|
end
|
||||||
|
|
||||||
def queue_mention_messages
|
def queue_mention_messages
|
||||||
title = self.class.mentionable_option(:title)
|
title = self.class.mentionable_option(:title)
|
||||||
from_id = read_attribute(self.class.mentionable_option(:user_field))
|
from_id = read_attribute(self.class.mentionable_option(:user_field))
|
||||||
text = read_attribute(self.class.mentionable_option(:message_field))
|
text = strip_quote_blocks(read_attribute(self.class.mentionable_option(:message_field)))
|
||||||
|
|
||||||
text.scan(DText::MENTION_REGEXP).each do |mention|
|
text.scan(DText::MENTION_REGEXP).each do |mention|
|
||||||
mention.gsub!(/(?:^\s*@)|(?:[:;,.!?\)\]<>]$)/, "")
|
mention.gsub!(/(?:^\s*@)|(?:[:;,.!?\)\]<>]$)/, "")
|
||||||
|
|||||||
@@ -15,18 +15,44 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "that mentions a user" do
|
context "that mentions a user" do
|
||||||
setup do
|
context "in a quote block" do
|
||||||
@user2 = FactoryGirl.create(:user)
|
setup do
|
||||||
@post = FactoryGirl.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
|
@user2 = FactoryGirl.create(:user)
|
||||||
end
|
|
||||||
|
|
||||||
should "create a dmail" do
|
|
||||||
assert_difference("Dmail.count", 1) do
|
|
||||||
@post.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
dmail = Dmail.last
|
should "not create a dmail" do
|
||||||
assert_equal("You were mentioned in the forum topic \"#{@topic.title}\":#{Danbooru.config.hostname}/forum_topics/#{@topic.id}?page=1\n\n---\n\nHey @#{@user2.name} check this out!", dmail.body)
|
assert_difference("Dmail.count", 0) do
|
||||||
|
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_difference("Dmail.count", 0) do
|
||||||
|
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_difference("Dmail.count", 0) do
|
||||||
|
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_difference("Dmail.count", 1) do
|
||||||
|
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "outside a quote block" do
|
||||||
|
setup do
|
||||||
|
@user2 = FactoryGirl.create(:user)
|
||||||
|
@post = FactoryGirl.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "create a dmail" do
|
||||||
|
assert_difference("Dmail.count", 1) do
|
||||||
|
@post.save
|
||||||
|
end
|
||||||
|
|
||||||
|
dmail = Dmail.last
|
||||||
|
assert_equal("You were mentioned in the forum topic \"#{@topic.title}\":http://#{Danbooru.config.hostname}/forum_topics/#{@topic.id}?page=1\n\n---\n\nHey @#{@user2.name} check this out!", dmail.body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user