Use ActiveJob to send comment mails
This commit is contained in:
parent
8392fca0dc
commit
3391d09549
4 changed files with 20 additions and 12 deletions
11
app/jobs/event_comment_mail_job.rb
Normal file
11
app/jobs/event_comment_mail_job.rb
Normal 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
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
class Mailbot < ActionMailer::Base
|
class Mailbot < ActionMailer::Base
|
||||||
|
|
||||||
def registration_mail(conference, user)
|
def registration_mail(conference, user)
|
||||||
mail(to: user.email,
|
mail(to: user.email,
|
||||||
from: conference.contact.email,
|
from: conference.contact.email,
|
||||||
|
|
@ -81,19 +82,15 @@ class Mailbot < ActionMailer::Base
|
||||||
conference.email_settings.cfp_dates_updated_body))
|
conference.email_settings.cfp_dates_updated_body))
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_notification_email_for_comment(comment)
|
def event_comment_mail(comment, user)
|
||||||
@comment = comment
|
@comment = comment
|
||||||
@event = @comment.commentable
|
@event = @comment.commentable
|
||||||
@conference = @event.program.conference
|
@conference = @event.program.conference
|
||||||
recipients = User.comment_notifiable(@conference) # with scope
|
@user = user
|
||||||
recipients.each do |user|
|
|
||||||
@user = user
|
mail(to: @user.email,
|
||||||
mail(to: @user.email,
|
from: @conference.contact.email,
|
||||||
from: @conference.contact.email,
|
template_name: 'comment_template',
|
||||||
reply_to: @conference.contact.email,
|
subject: "New comment has been posted for #{@event.title}")
|
||||||
template_path: 'admin/emails',
|
|
||||||
template_name: 'comment_template',
|
|
||||||
subject: "New comment has been posted for #{@event.title}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,6 @@ class Comment < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def send_notification
|
def send_notification
|
||||||
Mailbot.send_notification_email_for_comment(self).deliver_later
|
EventCommentMailJob.perform_later(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue