mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
Send emails to users who are watching topics
This commit is contained in:
parent
37175c264a
commit
7c1ae451fe
@ -76,5 +76,6 @@ class UserNotifications < ActionMailer::Base
|
||||
alias :user_replied :notification_template
|
||||
alias :user_quoted :notification_template
|
||||
alias :user_mentioned :notification_template
|
||||
alias :user_posted :notification_template
|
||||
|
||||
end
|
||||
|
@ -85,6 +85,8 @@ class PostAlertObserver < ActiveRecord::Observer
|
||||
|
||||
# Don't notify the same user about the same notification on the same post
|
||||
return if user.notifications.exists?(notification_type: type, topic_id: post.topic_id, post_number: post.post_number)
|
||||
|
||||
# Create the notification
|
||||
user.notifications.create(notification_type: type,
|
||||
topic_id: post.topic_id,
|
||||
post_number: post.post_number,
|
||||
|
@ -20,6 +20,15 @@ class UserEmailObserver < ActiveRecord::Observer
|
||||
notification_id: notification.id)
|
||||
end
|
||||
|
||||
def email_user_posted(notification)
|
||||
return unless notification.user.email_direct?
|
||||
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
||||
:user_email,
|
||||
type: :user_posted,
|
||||
user_id: notification.user_id,
|
||||
notification_id: notification.id)
|
||||
end
|
||||
|
||||
def email_user_quoted(notification)
|
||||
return unless notification.user.email_direct?
|
||||
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
||||
|
@ -666,6 +666,16 @@ en:
|
||||
---
|
||||
Please visit this link to respond: %{base_url}%{url}
|
||||
|
||||
user_posted:
|
||||
subject_template: "[%{site_name}] %{username} posted in '%{topic_title}'"
|
||||
text_body_template: |
|
||||
%{username} posted in '%{topic_title}' on %{site_name}:
|
||||
|
||||
---
|
||||
%{message}
|
||||
|
||||
---
|
||||
Please visit this link to respond: %{base_url}%{url}
|
||||
|
||||
digest:
|
||||
why: "Here's a brief summary of what happened on %{site_link} since we last saw you on %{last_seen_at}."
|
||||
|
@ -20,6 +20,24 @@ describe UserEmailObserver do
|
||||
|
||||
end
|
||||
|
||||
context 'posted' do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let!(:notification) { Fabricate(:notification, user: user) }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_posted, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).email_user_posted(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_posted)).never
|
||||
UserEmailObserver.send(:new).email_user_posted(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'user_replied' do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
Loading…
Reference in New Issue
Block a user