From ca9b008a4666eede62da2fa45158b709d1cd24db Mon Sep 17 00:00:00 2001 From: SaadYousaf Date: Mon, 11 Sep 2023 15:52:57 +0500 Subject: [PATCH] fix: fix notification generated event to include only users with preferences enabled. --- openedx/core/djangoapps/notifications/tasks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/notifications/tasks.py b/openedx/core/djangoapps/notifications/tasks.py index d2c495ff0c..e59ff77eb1 100644 --- a/openedx/core/djangoapps/notifications/tasks.py +++ b/openedx/core/djangoapps/notifications/tasks.py @@ -98,6 +98,7 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c ) preferences = create_notification_pref_if_not_exists(user_ids, list(preferences), course_key) notifications = [] + audience = [] for preference in preferences: preference = update_user_preference(preference, preference.user, course_key) if ( @@ -115,12 +116,13 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c course_id=course_key, ) ) + audience.append(preference.user_id) # send notification to users but use bulk_create notifications_generated = Notification.objects.bulk_create(notifications) if notifications_generated: notification_content = notifications_generated[0].content notification_generated_event( - user_ids, app_name, notification_type, course_key, content_url, notification_content, + audience, app_name, notification_type, course_key, content_url, notification_content, )