mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
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
3 changed files with 31 additions and 9 deletions
|
@ -222,6 +222,10 @@ class Post < ActiveRecord::Base
|
|||
@acting_user = pu
|
||||
end
|
||||
|
||||
def last_editor
|
||||
self.last_editor_id ? (User.find_by_id(self.last_editor_id) || user) : user
|
||||
end
|
||||
|
||||
def whitelisted_spam_hosts
|
||||
|
||||
hosts = SiteSetting
|
||||
|
|
|
@ -38,14 +38,23 @@ class PostAlerter
|
|||
# mentions (users/groups)
|
||||
mentioned_groups, mentioned_users = extract_mentions(post)
|
||||
|
||||
expand_group_mentions(mentioned_groups, post) do |group, users|
|
||||
notify_users(users - notified, :group_mentioned, post, group: group)
|
||||
notified += users
|
||||
end
|
||||
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
|
||||
|
||||
if mentioned_users
|
||||
notify_users(mentioned_users - notified, :mentioned, post)
|
||||
notified += mentioned_users
|
||||
expand_group_mentions(mentioned_groups, post) do |group, users|
|
||||
notify_users(users - notified, :group_mentioned, post, mentioned_opts.merge({group: group}))
|
||||
notified += users
|
||||
end
|
||||
|
||||
if mentioned_users
|
||||
notify_users(mentioned_users - notified, :mentioned, post, mentioned_opts)
|
||||
notified += mentioned_users
|
||||
end
|
||||
end
|
||||
|
||||
# replies
|
||||
|
@ -232,7 +241,7 @@ class PostAlerter
|
|||
# Make sure the user can see the 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
|
||||
return if notifier_id && MutedUser.where(user_id: user.id, muted_user_id: notifier_id)
|
||||
|
@ -285,7 +294,7 @@ class PostAlerter
|
|||
end
|
||||
|
||||
original_post = post
|
||||
original_username = opts[:display_username] || post.username
|
||||
original_username = opts[:display_username] || post.username # xxxxx need something here too
|
||||
|
||||
if collapsed
|
||||
post = first_unread_post(user, post.topic) || post
|
||||
|
|
|
@ -251,6 +251,15 @@ describe PostAlerter do
|
|||
}.not_to change(user.notifications, :count)
|
||||
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
|
||||
|
||||
describe ".create_notification" do
|
||||
|
|
Loading…
Reference in a new issue