mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -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,18 +42,24 @@ class UserEmailObserver < ActiveRecord::Observer
|
|||
|
||||
private
|
||||
|
||||
EMAILABLE_POST_TYPES ||= Set.new [Post.types[:regular], Post.types[:whisper]]
|
||||
|
||||
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,
|
||||
:user_email,
|
||||
type: type,
|
||||
user_id: notification.user_id,
|
||||
notification_id: notification.id)
|
||||
:user_email,
|
||||
type: type,
|
||||
user_id: notification.user_id,
|
||||
notification_id: notification.id)
|
||||
end
|
||||
|
||||
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,
|
||||
:user_email,
|
||||
|
|
|
@ -2,10 +2,13 @@ require 'rails_helper'
|
|||
|
||||
describe UserEmailObserver do
|
||||
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
# something is off with fabricator
|
||||
def create_notification(type, user=nil)
|
||||
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
|
||||
|
||||
shared_examples "enqueue" do
|
||||
|
@ -32,6 +35,16 @@ describe UserEmailObserver do
|
|||
|
||||
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
|
||||
|
||||
shared_examples "enqueue_public" do
|
||||
|
|
Loading…
Reference in a new issue