Class: Moist::ActionMailer::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/moist/action_mailer/observer.rb

Class Method Summary collapse

Class Method Details

.delivered_email(message) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/moist/action_mailer/observer.rb', line 4

def self.delivered_email(message)
  moist_enabled = ::Moist.mailer_registry.enabled?(message.mailer_class, message.mailer_action)
  return unless moist_enabled

  moist = [message.moist_user, message.moist_subscriber]
  if moist.any?(&:nil?) && moist.any?
    Rails.logger.warn("Moist was skipped, but at least one Moist variable was set.")
    Rails.logger.warn("@moist_user: #{message.moist_user.inspect}\n@moist_subscriber:#{message.moist_subscriber}")
    return
  end

  subscriber = ::Moist::CampaignSubscriber.find_by(user: message.moist_user, subscriber: message.moist_subscriber)
  mailing = ::Moist::Mailing.find_by(mailer_class: message.mailer_class, mailer_action: message.mailer_action, moist_campaign_subscriber_id: subscriber)
  mailing.update_column(:sent_at, Time.current)
end