-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from JahongirHakimjonov/dev
Dev
- Loading branch information
Showing
37 changed files
with
537 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
apps/mystories/migrations/0003_notification_message_en_notification_message_ru_and_more.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .notification import * # noqa | ||
from .posts import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
|
||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from apps.mystories.models import Notification | ||
from apps.mystories.tasks import send_notification_task | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(post_save, sender=Notification) | ||
def send_notification(sender, instance, created, **kwargs): # noqa | ||
if created: | ||
send_notification_task.delay(instance.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .notification import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logging | ||
import time | ||
|
||
from celery import shared_task | ||
from firebase_admin import messaging | ||
|
||
from apps.mystories.models import Notification | ||
from apps.users.models import ActiveSessions | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task | ||
def send_notification_task(notification_id): | ||
try: | ||
time.sleep(1) | ||
notification = Notification.objects.get(id=notification_id) | ||
fcm_tokens = ActiveSessions.objects.filter( | ||
user=notification.user, is_active=True, fcm_token__isnull=False | ||
).values_list("fcm_token", flat=True) | ||
for fcm_token in fcm_tokens: | ||
if fcm_token: | ||
message = messaging.Message( | ||
notification=messaging.Notification( | ||
title=notification.title, | ||
body=notification.message, | ||
image=( | ||
notification.banner.url | ||
if notification.banner | ||
and hasattr(notification.banner, "url") | ||
else None | ||
), | ||
), | ||
token=fcm_token, | ||
) | ||
messaging.send(message) | ||
notification.is_send = True | ||
notification.save() | ||
logger.info(f"Notification sent to user {notification.user.id}") | ||
except Notification.DoesNotExist: | ||
logger.error(f"Notification with id {notification_id} does not exist") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.