forked from retoor/devplacepy
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 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ from devplacepy.database import (
|
|||||||
notification_group_key,
|
notification_group_key,
|
||||||
NOTIFICATION_GROUP_KEYS,
|
NOTIFICATION_GROUP_KEYS,
|
||||||
get_silenced_uids,
|
get_silenced_uids,
|
||||||
|
count_unread_groups,
|
||||||
)
|
)
|
||||||
from devplacepy.services.background import background
|
from devplacepy.services.background import background
|
||||||
from devplacepy.utils.text import generate_uid, extract_mentions
|
from devplacepy.utils.text import generate_uid, extract_mentions
|
||||||
@@ -23,7 +24,7 @@ DEFAULT_PUSH_URL = "/notifications"
|
|||||||
_push_tasks: set[asyncio.Task] = set()
|
_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
|
from devplacepy import push
|
||||||
|
|
||||||
try:
|
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)
|
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 = {
|
payload = {
|
||||||
"title": "DevPlace",
|
"title": "DevPlace",
|
||||||
"message": message,
|
"message": message,
|
||||||
"icon": PUSH_ICON,
|
"icon": PUSH_ICON,
|
||||||
"url": target_url or DEFAULT_PUSH_URL,
|
"url": target_url or DEFAULT_PUSH_URL,
|
||||||
|
"unread": unread,
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
@@ -134,7 +138,7 @@ def _deliver_notification(
|
|||||||
)
|
)
|
||||||
clear_unread_cache(user_uid)
|
clear_unread_cache(user_uid)
|
||||||
if push:
|
if push:
|
||||||
_schedule_push(user_uid, message, target_url)
|
_schedule_push(user_uid, message, target_url, count_unread_groups(user_uid))
|
||||||
if telegram:
|
if telegram:
|
||||||
_schedule_telegram(user_uid, message)
|
_schedule_telegram(user_uid, message)
|
||||||
from devplacepy.services.audit import record as audit
|
from devplacepy.services.audit import record as audit
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "devplacepy"
|
name = "devplacepy"
|
||||||
version = "1.1.28"
|
version = "1.1.29"
|
||||||
description = "DevPlace - The Developer Social Network"
|
description = "DevPlace - The Developer Social Network"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user