Skip to content

Commit

Permalink
support mentions with ~username to match 9fff6ae
Browse files Browse the repository at this point in the history
  • Loading branch information
pushcx committed Mar 11, 2024
1 parent 8f55be4 commit 1e79910
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/comment.rb
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions spec/models/comment_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 1e79910

Please sign in to comment.