Use ActiveJob to send comment mails

This commit is contained in:
Henne Vogelsang 2016-04-22 11:29:38 +02:00
parent 8392fca0dc
commit 3391d09549
4 changed files with 20 additions and 12 deletions

View file

@ -0,0 +1,11 @@
class EventCommentMailJob < ActiveJob::Base
queue_as :default
def perform(comment)
conference = comment.commentable.program.conference
User.comment_notifiable(conference).each do |user|
Mailbot.event_comment_mail(comment, user).deliver_now
end
end
end

View file

@ -1,4 +1,5 @@
class Mailbot < ActionMailer::Base
def registration_mail(conference, user)
mail(to: user.email,
from: conference.contact.email,
@ -81,19 +82,15 @@ class Mailbot < ActionMailer::Base
conference.email_settings.cfp_dates_updated_body))
end
def send_notification_email_for_comment(comment)
def event_comment_mail(comment, user)
@comment = comment
@event = @comment.commentable
@conference = @event.program.conference
recipients = User.comment_notifiable(@conference) # with scope
recipients.each do |user|
@user = user
mail(to: @user.email,
from: @conference.contact.email,
reply_to: @conference.contact.email,
template_path: 'admin/emails',
template_name: 'comment_template',
subject: "New comment has been posted for #{@event.title}")
end
@user = user
mail(to: @user.email,
from: @conference.contact.email,
template_name: 'comment_template',
subject: "New comment has been posted for #{@event.title}")
end
end

View file

@ -56,6 +56,6 @@ class Comment < ActiveRecord::Base
private
def send_notification
Mailbot.send_notification_email_for_comment(self).deliver_later
EventCommentMailJob.perform_later(self)
end
end