From e72d262f1a3af41d5151a95d154cf21b55123f06 Mon Sep 17 00:00:00 2001 From: IonesioJunior Date: Mon, 16 Sep 2024 16:05:31 -0300 Subject: [PATCH] ADD new logic for dispatch notification --- .../syft/service/notifier/notifier_service.py | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/service/notifier/notifier_service.py b/packages/syft/src/syft/service/notifier/notifier_service.py index d8c1da2530f..dbde4905972 100644 --- a/packages/syft/src/syft/service/notifier/notifier_service.py +++ b/packages/syft/src/syft/service/notifier/notifier_service.py @@ -22,6 +22,7 @@ from .notifier import NotifierSettings from .notifier import UserNotificationActivity from .notifier_enums import EMAIL_TYPES +from .notifier_enums import NOTIFICATION_FREQUENCY from .notifier_enums import NOTIFIERS from .notifier_stash import NotifierStash @@ -387,11 +388,31 @@ def dispatch_notification( ) } - self.stash.update(credentials=admin_key, obj=notifier).unwrap() + email_frequency = notifier.email_frequency.get( + notification.email_template.__name__, NOTIFICATION_FREQUENCY.INSTANT + ) - notifier.send_notifications( - context=context, notification=notification - ).unwrap() + if email_frequency == NOTIFICATION_FREQUENCY.INSTANT: + notifier.send_notifications( + context=context, notification=notification + ).unwrap() + else: + queue_dict = notifier.email_queue.get( + notification.email_template.__name__, {} + ) + if len(queue_dict) == 0: + notifier.email_queue[notification.email_template.__name__] = ( + queue_dict + ) + + user_queue = queue_dict.get(notification.to_user_verify_key, []) + + if len(user_queue) == 0: + queue_dict[notification.to_user_verify_key] = user_queue + + user_queue.append(notification) + + self.stash.update(credentials=admin_key, obj=notifier).unwrap() # If notifier isn't active, return None return SyftSuccess(message="Notification dispatched successfully")