mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-12 08:17:30 +00:00
added notification for top leaderboard junior, added related celery task, created method to send notification to multiple users
This commit is contained in:
@ -115,6 +115,39 @@ def send_push(user, data):
|
||||
)
|
||||
|
||||
|
||||
def send_multiple_push(queryset, data):
|
||||
""" used to send same notification to multiple users """
|
||||
FCMDevice.objects.filter(user__in=queryset, active=True).send_message(
|
||||
Message(notification=FirebaseNotification(data['title'], data['body']), data=data)
|
||||
)
|
||||
|
||||
|
||||
@shared_task()
|
||||
def send_notification_multiple_user(notification_type, from_user_id, from_user_type,
|
||||
to_user_list: list = [], extra_data: dict = {}):
|
||||
"""
|
||||
used to send notification to multiple user for the given notification type
|
||||
"""
|
||||
push_data = NOTIFICATION_DICT[notification_type].copy()
|
||||
notification_data = push_data.copy()
|
||||
points = extra_data.get('points', None)
|
||||
from_user_name, from_user_image, from_user = get_from_user_details(from_user_id, from_user_type)
|
||||
push_data['body'] = push_data['body'].format(from_user=from_user_name, points=points)
|
||||
notification_data['body'] = notification_data['body'].format(from_user=from_user_name,
|
||||
points=points)
|
||||
notification_data['from_user'] = from_user_name
|
||||
notification_data['from_user_image'] = from_user_image
|
||||
notification_list = []
|
||||
for user in to_user_list:
|
||||
notification_list.append(Notification(notification_type=notification_type,
|
||||
notification_to=user,
|
||||
notification_from=from_user,
|
||||
data=notification_data))
|
||||
Notification.objects.bulk_create(notification_list)
|
||||
|
||||
send_multiple_push(to_user_list, push_data)
|
||||
|
||||
|
||||
@shared_task()
|
||||
def send_notification_to_guardian(notification_type, from_user_id, to_user_id, extra_data):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user