Skip to content

Commit

Permalink
Use ActiveJob to send comment mails
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Apr 22, 2016
1 parent 8392fca commit 3391d09
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
11 changes: 11 additions & 0 deletions app/jobs/event_comment_mail_job.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 8 additions & 11 deletions app/mailers/mailbot.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Mailbot < ActionMailer::Base

def registration_mail(conference, user)
mail(to: user.email,
from: conference.contact.email,
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.

0 comments on commit 3391d09

Please sign in to comment.