diff --git a/app/models/comment.rb b/app/models/comment.rb index 95011d341..c6d150545 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -265,7 +265,7 @@ def deliver_notifications end def deliver_mention_notifications(notified = []) - to_notify = plaintext_comment.scan(/\B@([\w\-]+)/).flatten.uniq + to_notify = plaintext_comment.scan(/\B[@~]([\w\-]+)/).flatten.uniq (to_notify - notified).each do |mention| if notified.include? mention next diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 242f11026..aaf5937fe 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -79,20 +79,27 @@ recipient = create(:user) recipient.settings["email_notifications"] = true recipient.settings["email_mentions"] = true - # Need to save, because deliver_mention_notifications re-fetches from DB. recipient.save! sender = create(:user) - # Story under which the comment is posted. - story = create(:story) - # The comment. - c = build(:comment, story: story, user: sender, comment: "@#{recipient.username}") + c = build(:comment, user: sender, comment: "@#{recipient.username}") c.save! expect(sent_emails.size).to eq(1) expect(sent_emails[0].subject).to match(/Mention from #{sender.username}/) end + it "also sends mentions with ~username" do + recipient = create(:user) + recipient.settings["email_notifications"] = true + recipient.settings["email_mentions"] = true + recipient.save! + + c = build(:comment, comment: "~#{recipient.username}") + c.save! + expect(sent_emails.size).to eq(1) + end + it "sends only reply notification on reply with mention" do # User being mentioned and replied to. recipient = create(:user)