mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 03:25:31 -05:00
FIX: only send email notifications for regular and whisper type of posts
This commit is contained in:
parent
02d9ec5bde
commit
61cc776fdd
2 changed files with 26 additions and 7 deletions
|
@ -42,8 +42,12 @@ class UserEmailObserver < ActiveRecord::Observer
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
EMAILABLE_POST_TYPES ||= Set.new [Post.types[:regular], Post.types[:whisper]]
|
||||||
|
|
||||||
def enqueue(type, delay=default_delay)
|
def enqueue(type, delay=default_delay)
|
||||||
return unless notification.user.email_direct? && (notification.user.active? || notification.user.staged?)
|
return unless notification.user.email_direct?
|
||||||
|
return unless notification.user.active? || notification.user.staged?
|
||||||
|
return unless EMAILABLE_POST_TYPES.include? notification.post.try(:post_type)
|
||||||
|
|
||||||
Jobs.enqueue_in(delay,
|
Jobs.enqueue_in(delay,
|
||||||
:user_email,
|
:user_email,
|
||||||
|
@ -53,7 +57,9 @@ class UserEmailObserver < ActiveRecord::Observer
|
||||||
end
|
end
|
||||||
|
|
||||||
def enqueue_private(type, delay=default_delay)
|
def enqueue_private(type, delay=default_delay)
|
||||||
return unless notification.user.email_private_messages? && (notification.user.active? || notification.user.staged?)
|
return unless notification.user.email_private_messages?
|
||||||
|
return unless notification.user.active? || notification.user.staged?
|
||||||
|
return unless EMAILABLE_POST_TYPES.include? notification.post.try(:post_type)
|
||||||
|
|
||||||
Jobs.enqueue_in(delay,
|
Jobs.enqueue_in(delay,
|
||||||
:user_email,
|
:user_email,
|
||||||
|
|
|
@ -2,10 +2,13 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe UserEmailObserver do
|
describe UserEmailObserver do
|
||||||
|
|
||||||
|
let(:topic) { Fabricate(:topic) }
|
||||||
|
let(:post) { Fabricate(:post, topic: topic) }
|
||||||
|
|
||||||
# something is off with fabricator
|
# something is off with fabricator
|
||||||
def create_notification(type, user=nil)
|
def create_notification(type, user=nil)
|
||||||
user ||= Fabricate(:user)
|
user ||= Fabricate(:user)
|
||||||
Notification.create(data: '', user: user, notification_type: type)
|
Notification.create(data: '', user: user, notification_type: type, topic: topic, post_number: post.post_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "enqueue" do
|
shared_examples "enqueue" do
|
||||||
|
@ -32,6 +35,16 @@ describe UserEmailObserver do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "small action" do
|
||||||
|
|
||||||
|
it "doesn't enqueue a job" do
|
||||||
|
Post.any_instance.expects(:post_type).returns(Post.types[:small_action])
|
||||||
|
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
|
||||||
|
UserEmailObserver.send(:new).after_commit(notification)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "enqueue_public" do
|
shared_examples "enqueue_public" do
|
||||||
|
|
Loading…
Reference in a new issue