notification: add notification history
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import requests
|
||||
from firebase_admin import messaging
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from core.apps.notifications.models import Notification
|
||||
from core.apps.notifications.tasks.create_notification_history import create_history
|
||||
|
||||
|
||||
EXPO_API_URL = "https://exp.host/--/api/v2/push/send"
|
||||
|
||||
|
||||
def send_notification(token, title, body, data=None):
|
||||
tokens = list(Notification.objects.exclude(token=token).values_list("token", flat=True))
|
||||
users = list(Notification.objects.exclude(token=token).values_list("user", flat=True))
|
||||
create_history.delay(users, title, body, data)
|
||||
if not tokens:
|
||||
return {"error": "No tokens found"}
|
||||
|
||||
|
||||
messages = [
|
||||
{
|
||||
"to": token,
|
||||
@@ -38,6 +40,8 @@ def send_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))
|
||||
users = list(Notification.objects.exclude(token=token).values_list("user", flat=True))
|
||||
create_history.delay(users, title, body, data)
|
||||
if not tokens:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user