2020-05-01 09:23:43 +00:00
|
|
|
class Notification::EmailNotificationService
|
|
|
|
pattr_initialize [:notification!]
|
|
|
|
|
|
|
|
def perform
|
2020-05-05 18:40:56 +00:00
|
|
|
# don't send emails if user read the push notification already
|
|
|
|
return if notification.read_at.present?
|
2020-05-01 09:23:43 +00:00
|
|
|
return unless user_subscribed_to_notification?
|
|
|
|
|
|
|
|
# TODO : Clean up whatever happening over here
|
2020-05-05 18:40:56 +00:00
|
|
|
# Segregate the mailers properly
|
2020-05-01 09:23:43 +00:00
|
|
|
AgentNotifications::ConversationNotificationsMailer.public_send(notification
|
2020-05-05 18:40:56 +00:00
|
|
|
.notification_type.to_s, notification.primary_actor, notification.user).deliver_now
|
2020-05-01 09:23:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_subscribed_to_notification?
|
|
|
|
notification_setting = notification.user.notification_settings.find_by(account_id: notification.account.id)
|
|
|
|
return true if notification_setting.public_send("email_#{notification.notification_type}?")
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|