Email support for watching first post

This commit is contained in:
Robin Ward 2016-07-07 12:23:19 -04:00
parent 2005565c9c
commit 5f91919663
5 changed files with 48 additions and 9 deletions

View File

@ -192,6 +192,10 @@ class UserNotifications < ActionMailer::Base
notification_email(user, opts)
end
def user_watching_first_post(user, opts)
user_posted(user, opts)
end
def mailing_list_notify(user, post)
opts = {
post: post,

View File

@ -32,6 +32,10 @@ class UserEmailObserver < ActiveRecord::Observer
enqueue :user_linked
end
def watching_first_post
enqueue :user_watching_first_post
end
def private_message
enqueue_private(:user_private_message)
end

View File

@ -2312,6 +2312,17 @@ en:
%{respond_instructions}
user_watching_first_post:
subject_template: "[%{site_name}] %{topic_title}"
text_body_template: |
%{header_instructions}
%{message}
%{context}
%{respond_instructions}
user_posted_pm:
subject_template: "[%{site_name}] [PM] %{topic_title}"
text_body_template: |

View File

@ -482,6 +482,14 @@ describe UserNotifications do
end
end
describe "watching first post" do
include_examples "notification email building" do
let(:notification_type) { :invited_to_topic }
include_examples "no reply by email"
include_examples "sets user locale"
end
end
# notification emails derived from templates are translated into the user's locale
shared_examples "notification derived from template" do
let(:user) { Fabricate(:user, locale: locale) }

View File

@ -8,7 +8,11 @@ describe UserEmailObserver do
# something is off with fabricator
def create_notification(type, user=nil)
user ||= Fabricate(:user)
Notification.create(data: "{\"a\": 1}", user: user, notification_type: type, topic: topic, post_number: post.post_number)
Notification.create(data: "{\"a\": 1}",
user: user,
notification_type: Notification.types[type],
topic: topic,
post_number: post.post_number)
end
shared_examples "enqueue" do
@ -82,7 +86,7 @@ describe UserEmailObserver do
context 'user_mentioned' do
let(:type) { :user_mentioned }
let(:delay) { SiteSetting.email_time_window_mins.minutes }
let!(:notification) { create_notification(1) }
let!(:notification) { create_notification(:mentioned) }
include_examples "enqueue_public"
@ -97,7 +101,7 @@ describe UserEmailObserver do
context 'user_replied' do
let(:type) { :user_replied }
let(:delay) { SiteSetting.email_time_window_mins.minutes }
let!(:notification) { create_notification(2) }
let!(:notification) { create_notification(:replied) }
include_examples "enqueue_public"
end
@ -105,7 +109,7 @@ describe UserEmailObserver do
context 'user_quoted' do
let(:type) { :user_quoted }
let(:delay) { SiteSetting.email_time_window_mins.minutes }
let!(:notification) { create_notification(3) }
let!(:notification) { create_notification(:quoted) }
include_examples "enqueue_public"
end
@ -113,7 +117,7 @@ describe UserEmailObserver do
context 'user_linked' do
let(:type) { :user_linked }
let(:delay) { SiteSetting.email_time_window_mins.minutes }
let!(:notification) { create_notification(11) }
let!(:notification) { create_notification(:linked) }
include_examples "enqueue_public"
end
@ -121,7 +125,7 @@ describe UserEmailObserver do
context 'user_posted' do
let(:type) { :user_posted }
let(:delay) { SiteSetting.email_time_window_mins.minutes }
let!(:notification) { create_notification(9) }
let!(:notification) { create_notification(:posted) }
include_examples "enqueue_public"
end
@ -129,7 +133,7 @@ describe UserEmailObserver do
context 'user_private_message' do
let(:type) { :user_private_message }
let(:delay) { SiteSetting.private_email_time_window_seconds }
let!(:notification) { create_notification(6) }
let!(:notification) { create_notification(:private_message) }
include_examples "enqueue_private"
@ -144,7 +148,7 @@ describe UserEmailObserver do
context 'user_invited_to_private_message' do
let(:type) { :user_invited_to_private_message }
let(:delay) { SiteSetting.private_email_time_window_seconds }
let!(:notification) { create_notification(7) }
let!(:notification) { create_notification(:invited_to_private_message) }
include_examples "enqueue_public"
end
@ -152,7 +156,15 @@ describe UserEmailObserver do
context 'user_invited_to_topic' do
let(:type) { :user_invited_to_topic }
let(:delay) { SiteSetting.private_email_time_window_seconds }
let!(:notification) { create_notification(13) }
let!(:notification) { create_notification(:invited_to_topic) }
include_examples "enqueue_public"
end
context 'watching the first post' do
let(:type) { :user_watching_first_post }
let(:delay) { SiteSetting.email_time_window_mins.minutes }
let!(:notification) { create_notification(:watching_first_post) }
include_examples "enqueue_public"
end