From 3391d095493410a59cf4690c679f8bf1575b2ad9 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Fri, 22 Apr 2016 11:29:38 +0200 Subject: [PATCH] Use ActiveJob to send comment mails --- app/jobs/event_comment_mail_job.rb | 11 +++++++++++ app/mailers/mailbot.rb | 19 ++++++++----------- app/models/comment.rb | 2 +- .../comment_template.text.erb | 0 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 app/jobs/event_comment_mail_job.rb rename app/views/{admin/emails => mailbot}/comment_template.text.erb (100%) diff --git a/app/jobs/event_comment_mail_job.rb b/app/jobs/event_comment_mail_job.rb new file mode 100644 index 0000000000..28564a1d22 --- /dev/null +++ b/app/jobs/event_comment_mail_job.rb @@ -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 diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index e0259298ac..3f8cda14b5 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -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 @@ def conference_cfp_update_mail(conference, user) 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 diff --git a/app/models/comment.rb b/app/models/comment.rb index 7449b05103..1f501c3ffa 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -56,6 +56,6 @@ def self.find_commentable(commentable_str, commentable_id) private def send_notification - Mailbot.send_notification_email_for_comment(self).deliver_later + EventCommentMailJob.perform_later(self) end end diff --git a/app/views/admin/emails/comment_template.text.erb b/app/views/mailbot/comment_template.text.erb similarity index 100% rename from app/views/admin/emails/comment_template.text.erb rename to app/views/mailbot/comment_template.text.erb