From 2066e2ba3b568525f0bec46b9dca38c8a8ac8b49 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 8 Apr 2024 19:40:01 +0530 Subject: [PATCH] feat: disable default email notifs for SLAs --- app/models/notification.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index b5834225a..087697e3d 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -162,11 +162,21 @@ class Notification < ApplicationRecord # Should we do something about the case where user subscribed to both push and email ? # In future, we could probably add condition here to enqueue the job for 30 seconds later # when push enabled and then check in email job whether notification has been read already. - Notification::EmailNotificationJob.perform_later(self) if user_subscribed_to_notification?('email') + Notification::EmailNotificationJob.perform_later(self) if should_send_email? && user_subscribed_to_notification?('email') Notification::RemoveDuplicateNotificationJob.perform_later(self) end + def should_send_email? + case notification_type + when 'sla_missed_first_response', 'sla_missed_next_response', 'sla_missed_resolution' + # we send an email digest for this anyway so no need to send individual emails + false + else + true + end + end + def user_subscribed_to_notification?(delivery_type) notification_setting = user.notification_settings.find_by(account_id: account.id) return false if notification_setting.blank?