Skip to content

Push notifications - #242

Merged
jaksia merged 8 commits into
masterfrom
notifications
Oct 30, 2026
Merged

jaksia merged 8 commits into
masterfrom
notifications

Conversation

@Stanko2

@Stanko2 Stanko2 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Receive notifications via web push API. Need to setup

VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
VAPID_ADMIN_EMAIL=

In .env - values can be generated via def generate_vapid_keys() -> tuple[str, str]: in push.py. Need to be constant in production, if not present they are generated automatically. Tested on firefox, notifications works there. Need to test in other browsers - at least chrome.

@Aiq0 Aiq0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vyzera to dobre, vyzera ze to aj funguje, ale teda pozri komentare nizsie...

Comment on lines +116 to +133
push_user_ids = [
user.id for user in users if NotificationChannel.PUSH in channels_map[user.id]
]
if push_user_ids:
subscribed_ids = set(
PushSubscription.objects.filter(user_id__in=push_user_ids)
.values_list("user_id", flat=True)
.distinct()
)
for user_id in subscribed_ids:
push_notification.delay(
user_id=user_id,
contest_id=contest.id,
title=title,
content=content,
link=link,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join a dat to do cyklu vyssie?

return public, private

if not settings.DEBUG:
return "", ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mozno by som bral radsej exception

Comment on lines +43 to +45
public, private = generate_vapid_keys()
_DEV_KEY_PATH.write_text(json.dumps({"public_key": public, "private_key": private}))
return public, private

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trochu nerozumiem na co je .vapid.json, ak len preto, aby si si to mohol precitat, nechces to radsej vypisat na stdout?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mam pocit ze toto nie je potrebne, ak si teda rebasnes tieto veci (teda tam som to dal to tej parent migracie)

potom by to ale teda chcelo fixnut tu dalsiu migraciu...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment thread seminare/users/views.py
Comment on lines +151 to +160
class ServiceWorkerView(View):
def get(self, request: HttpRequest) -> FileResponse:
path = finders.find("push/sw.js")
if not path:
raise Http404

response = FileResponse(open(path, "rb"), content_type="application/javascript")
response["Cache-Control"] = "no-cache"
response["Service-Worker-Allowed"] = "/"
return response

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nestaci to len dat do rootu staticu a dobre bude?

ze returnut FileResponse je trochu hlupe, najma ked pred tym je Caddy, ktora to via poriesit sama ked ju pekne poprosis...

Comment thread .env.example Outdated
Comment on lines +11 to +14
# Web Push. Leave empty in development to generate seminare/.vapid.json.
VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
VAPID_ADMIN_EMAIL=web@trojsten.sk

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do env examplu by som kludne dal nejake fixne testovacie kluce, s komentarom, ze v produkcii zmen

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ked tak nad tym rozmyslam, mozno by nebolo zle cele notify dat ako @job, lebo tie .delay insertuju veci do db po jednom...

@jaksia
jaksia merged commit ff0d23f into master Oct 30, 2026
1 check passed
@jaksia
jaksia deleted the notifications branch October 30, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants