Esempio n. 1
0
def push_task(notification_pk):
    """A Celery task to send push notifications related with a given Notification
    model."""
    from snitch.helpers import get_notification_model

    Notification = get_notification_model()

    try:
        notification = Notification.objects.get(pk=notification_pk)
    except Notification.DoesNotExist:
        return False
    notification.send(send_async=False)
Esempio n. 2
0
def send_notification_task(notification_pk: int) -> Optional[bool]:
    """A Celery task to send push notifications related with a given Notification
    model."""

    Notification = get_notification_model()

    try:
        notification = Notification.objects.get(pk=notification_pk)
    except Notification.DoesNotExist:
        return False
    notification.send(send_async=False)
    return None
Esempio n. 3
0
 def notify(self):
     """If the event is not ephemeral, creates a notification fot each user in the
     audience. In other case, only sends the notification, but doesn't save
     into the database.
     """
     if not self.ephemeral:
         # Creates a notification
         Notification = get_notification_model()
         for user in self.audience():
             notification = Notification(event=self.event, user=user)
             notification.save()
     else:
         # Only sends the event to the user
         for user in self.audience():
             send_event_to_user(event=self.event, user=user)
Esempio n. 4
0
 def notify(self):
     """Creates a notification fot each user in the audience."""
     Notification = get_notification_model()
     for user in self.audience():
         notification = Notification(event=self.event, user=user)
         notification.save()