git
This commit is contained in:
@@ -7,9 +7,10 @@ from core.apps.accounts.models import User
|
|||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def create_history(users, title, body, data=None):
|
def create_history(user_ids, title, body, data=None):
|
||||||
histories = []
|
histories = []
|
||||||
for user in users:
|
for user_id in user_ids:
|
||||||
|
user = get_object_or_404(User, id=user_id)
|
||||||
histories.append(NotificationHistory(
|
histories.append(NotificationHistory(
|
||||||
title=title,
|
title=title,
|
||||||
user=user,
|
user=user,
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ EXPO_API_URL = "https://exp.host/--/api/v2/push/send"
|
|||||||
def send_notification(token, title, body, data=None):
|
def send_notification(token, title, body, data=None):
|
||||||
tokens = list(Notification.objects.exclude(token=token).values_list("token", flat=True))
|
tokens = list(Notification.objects.exclude(token=token).values_list("token", flat=True))
|
||||||
users = list(Notification.objects.exclude(token=token).values_list("user", flat=True))
|
users = list(Notification.objects.exclude(token=token).values_list("user", flat=True))
|
||||||
create_history.delay(users, title, body, data)
|
user_ids = []
|
||||||
|
for user in users:
|
||||||
|
user_ids.append(user.id)
|
||||||
|
create_history.delay(user_ids, title, body, data)
|
||||||
if not tokens:
|
if not tokens:
|
||||||
return {"error": "No tokens found"}
|
return {"error": "No tokens found"}
|
||||||
|
|
||||||
@@ -41,7 +44,10 @@ def send_notification(token, title, body, data=None):
|
|||||||
def send_web_notification(token, title, body, data=None):
|
def send_web_notification(token, title, body, data=None):
|
||||||
tokens = list(Notification.objects.exclude(token=token).values_list('token', flat=True))
|
tokens = list(Notification.objects.exclude(token=token).values_list('token', flat=True))
|
||||||
users = list(Notification.objects.exclude(token=token).values_list("user", flat=True))
|
users = list(Notification.objects.exclude(token=token).values_list("user", flat=True))
|
||||||
create_history.delay(users, title, body, data)
|
user_ids = []
|
||||||
|
for user in users:
|
||||||
|
user_ids.append(user.id)
|
||||||
|
create_history.delay(user_ids, title, body, data)
|
||||||
if not tokens:
|
if not tokens:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user