From 376c6ba99dbefd4c43626e5b290cc906376def87 Mon Sep 17 00:00:00 2001 From: retoor Date: Sun, 15 Nov 2026 04:03:10 +0100 Subject: [PATCH] Push payload carries the recipient's unread notification count The notification funnel computes count_unread_groups right after the in-app insert and adds it to the shared push payload as unread, only when a push is actually sent. Providers decide how to present it. Co-Authored-By: Claude Sonnet 5.5 --- devplacepy/utils/notifications.py | 10 +++++++--- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/devplacepy/utils/notifications.py b/devplacepy/utils/notifications.py index 953a39e0..9ac684e1 100644 --- a/devplacepy/utils/notifications.py +++ b/devplacepy/utils/notifications.py @@ -10,6 +10,7 @@ from devplacepy.database import ( notification_group_key, NOTIFICATION_GROUP_KEYS, get_silenced_uids, + count_unread_groups, ) from devplacepy.services.background import background from devplacepy.utils.text import generate_uid, extract_mentions @@ -23,7 +24,7 @@ DEFAULT_PUSH_URL = "/notifications" _push_tasks: set[asyncio.Task] = set() -async def _safe_notify(user_uid: str, payload: dict[str, str]) -> None: +async def _safe_notify(user_uid: str, payload: dict[str, str | int]) -> None: from devplacepy import push try: @@ -32,12 +33,15 @@ async def _safe_notify(user_uid: str, payload: dict[str, str]) -> None: logger.warning("Push delivery failed for %s: %s", user_uid, e) -def _schedule_push(user_uid: str, message: str, target_url: str | None) -> None: +def _schedule_push( + user_uid: str, message: str, target_url: str | None, unread: int +) -> None: payload = { "title": "DevPlace", "message": message, "icon": PUSH_ICON, "url": target_url or DEFAULT_PUSH_URL, + "unread": unread, } try: loop = asyncio.get_running_loop() @@ -134,7 +138,7 @@ def _deliver_notification( ) clear_unread_cache(user_uid) if push: - _schedule_push(user_uid, message, target_url) + _schedule_push(user_uid, message, target_url, count_unread_groups(user_uid)) if telegram: _schedule_telegram(user_uid, message) from devplacepy.services.audit import record as audit diff --git a/pyproject.toml b/pyproject.toml index 3a875e42..ffe6cd94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "devplacepy" -version = "1.1.28" +version = "1.1.29" description = "DevPlace - The Developer Social Network" requires-python = ">=3.12" dependencies = [