APNs maps the unread count to aps.badge

The shared payload key unread becomes aps.badge when it is a
non-negative integer. A missing or invalid value leaves the key out, so
the welcome probe and any older caller keep their previous body.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 04:03:29 +01:00
co-authored by Claude Sonnet 5.5
parent 376c6ba99d
commit d815fbe9f8
2 changed files with 20 additions and 9 deletions
+19 -8
View File
@@ -230,6 +230,13 @@ def _dead_before(response: httpx.Response) -> str | None:
return None
def _badge(payload: dict[str, Any]) -> int | None:
unread = payload.get("unread")
if isinstance(unread, bool) or not isinstance(unread, int) or unread < 0:
return None
return unread
class ApnsProvider(PushProvider):
name = "apns"
label = PROVIDER_LABEL
@@ -323,16 +330,20 @@ class ApnsProvider(PushProvider):
return fields
def prepare(self, payload: dict[str, Any]) -> str:
aps: dict[str, Any] = {
"alert": {
"title": payload.get("title") or "DevPlace",
"body": payload.get("message") or "",
},
"sound": "default",
"thread-id": THREAD_ID,
}
badge = _badge(payload)
if badge is not None:
aps["badge"] = badge
return json.dumps(
{
"aps": {
"alert": {
"title": payload.get("title") or "DevPlace",
"body": payload.get("message") or "",
},
"sound": "default",
"thread-id": THREAD_ID,
},
"aps": aps,
"url": payload.get("url") or DEFAULT_PUSH_URL,
"icon": payload.get("icon") or PUSH_ICON,
}
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "devplacepy"
version = "1.1.29"
version = "1.1.30"
description = "DevPlace - The Developer Social Network"
requires-python = ">=3.12"
dependencies = [