FIX: when a post is edited by someone other than the original author and a mention is added, the mention notification is from the person who edited
This commit is contained in:
parent
5771d2aee2
commit
091e7ef3ca
|
@ -222,6 +222,10 @@ class Post < ActiveRecord::Base
|
||||||
@acting_user = pu
|
@acting_user = pu
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_editor
|
||||||
|
self.last_editor_id ? (User.find_by_id(self.last_editor_id) || user) : user
|
||||||
|
end
|
||||||
|
|
||||||
def whitelisted_spam_hosts
|
def whitelisted_spam_hosts
|
||||||
|
|
||||||
hosts = SiteSetting
|
hosts = SiteSetting
|
||||||
|
|
|
@ -38,15 +38,24 @@ class PostAlerter
|
||||||
# mentions (users/groups)
|
# mentions (users/groups)
|
||||||
mentioned_groups, mentioned_users = extract_mentions(post)
|
mentioned_groups, mentioned_users = extract_mentions(post)
|
||||||
|
|
||||||
|
if mentioned_groups || mentioned_users
|
||||||
|
mentioned_opts = {}
|
||||||
|
if post.last_editor_id != post.user_id
|
||||||
|
# Mention comes from an edit by someone else, so notification should say who added the mention.
|
||||||
|
editor = post.last_editor
|
||||||
|
mentioned_opts = {user_id: editor.id, original_username: editor.username, display_username: editor.username}
|
||||||
|
end
|
||||||
|
|
||||||
expand_group_mentions(mentioned_groups, post) do |group, users|
|
expand_group_mentions(mentioned_groups, post) do |group, users|
|
||||||
notify_users(users - notified, :group_mentioned, post, group: group)
|
notify_users(users - notified, :group_mentioned, post, mentioned_opts.merge({group: group}))
|
||||||
notified += users
|
notified += users
|
||||||
end
|
end
|
||||||
|
|
||||||
if mentioned_users
|
if mentioned_users
|
||||||
notify_users(mentioned_users - notified, :mentioned, post)
|
notify_users(mentioned_users - notified, :mentioned, post, mentioned_opts)
|
||||||
notified += mentioned_users
|
notified += mentioned_users
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# replies
|
# replies
|
||||||
reply_to_user = post.reply_notification_target
|
reply_to_user = post.reply_notification_target
|
||||||
|
@ -232,7 +241,7 @@ class PostAlerter
|
||||||
# Make sure the user can see the post
|
# Make sure the user can see the post
|
||||||
return unless Guardian.new(user).can_see?(post)
|
return unless Guardian.new(user).can_see?(post)
|
||||||
|
|
||||||
notifier_id = opts[:user_id] || post.user_id
|
notifier_id = opts[:user_id] || post.user_id # xxxxx look at revision history
|
||||||
|
|
||||||
# apply muting here
|
# apply muting here
|
||||||
return if notifier_id && MutedUser.where(user_id: user.id, muted_user_id: notifier_id)
|
return if notifier_id && MutedUser.where(user_id: user.id, muted_user_id: notifier_id)
|
||||||
|
@ -285,7 +294,7 @@ class PostAlerter
|
||||||
end
|
end
|
||||||
|
|
||||||
original_post = post
|
original_post = post
|
||||||
original_username = opts[:display_username] || post.username
|
original_username = opts[:display_username] || post.username # xxxxx need something here too
|
||||||
|
|
||||||
if collapsed
|
if collapsed
|
||||||
post = first_unread_post(user, post.topic) || post
|
post = first_unread_post(user, post.topic) || post
|
||||||
|
|
|
@ -251,6 +251,15 @@ describe PostAlerter do
|
||||||
}.not_to change(user.notifications, :count)
|
}.not_to change(user.notifications, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "notification comes from editor is mention is added later" do
|
||||||
|
admin = Fabricate(:admin)
|
||||||
|
post = create_post_with_alerts(user: user, raw: 'No mention here.')
|
||||||
|
expect {
|
||||||
|
post.revise(admin, { raw: "Mention @eviltrout in this edit." })
|
||||||
|
}.to change(evil_trout.notifications, :count)
|
||||||
|
n = evil_trout.notifications.last
|
||||||
|
n.data_hash["original_username"].should == admin.username
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".create_notification" do
|
describe ".create_notification" do
|
||||||
|
|
Loading…
Reference in New Issue