Fix #4680: @-ing yourself sends you a DMail.
Don't send a dmail when the user @-mentions themselves, whether in an edit or in the original message.
This commit is contained in:
@@ -28,12 +28,14 @@ module Mentionable
|
||||
text_was = send(:attribute_before_last_save, message_field)
|
||||
|
||||
names = DText.parse_mentions(text) - DText.parse_mentions(text_was)
|
||||
users = names.map { |name| User.find_by_name(name) }.uniq
|
||||
users = users.without(CurrentUser.user)
|
||||
|
||||
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))
|
||||
users.each do |user|
|
||||
body = self.instance_exec(user.name, &self.class.mentionable_option(:body))
|
||||
title = self.instance_exec(user.name, &self.class.mentionable_option(:title))
|
||||
|
||||
Dmail.create_automated(to_name: name, title: title, body: body)
|
||||
Dmail.create_automated(to: user, title: title, body: body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,6 +60,12 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
should "not send a mention to yourself" do
|
||||
assert_no_difference("Dmail.count") do
|
||||
@forum_post = as(@user) { create(:forum_post, body: "hi from @#{@user.name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "that belongs to a topic with several pages of posts" do
|
||||
|
||||
Reference in New Issue
Block a user