Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete user webpush subscription if delivery fails #1364

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions ephios/core/services/notifications/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import mail_admins
from django.utils.translation import gettext_lazy as _
from pywebpush import WebPushException
from webpush import send_user_notification

from ephios.core.models.users import Notification
Expand Down Expand Up @@ -162,14 +163,17 @@ class WebPushNotificationBackend(AbstractNotificationBackend):

@classmethod
def send(cls, notification):
payload = {
"head": str(notification.subject),
"body": notification.body,
"icon": "/static/ephios/img/ephios-symbol-red.svg",
}
if actions := notification.get_actions():
payload["url"] = actions[0][1]
send_user_notification(user=notification.user, payload=payload, ttl=1000)
try:
payload = {
"head": str(notification.subject),
"body": notification.body,
"icon": "/static/ephios/img/ephios-symbol-red.svg",
}
if actions := notification.get_actions():
payload["url"] = actions[0][1]
send_user_notification(user=notification.user, payload=payload, ttl=1000)
except WebPushException:
notification.user.webpush_info.all().delete()
felixrindt marked this conversation as resolved.
Show resolved Hide resolved


CORE_NOTIFICATION_BACKENDS = [EmailNotificationBackend, WebPushNotificationBackend]