notification: add notification history

This commit is contained in:
behruz-dev
2025-10-30 16:17:25 +05:00
parent 22b1d37a1a
commit af8d212b3e
10 changed files with 146 additions and 5 deletions

View File

@@ -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