Send emails to users who are watching topics

This commit is contained in:
Robin Ward 2013-02-27 15:38:44 -05:00
parent 37175c264a
commit 7c1ae451fe
5 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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}."

View File

@ -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) }