forked from retoor/devplacepy
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:
@@ -230,6 +230,13 @@ def _dead_before(response: httpx.Response) -> str | None:
|
|||||||
return 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):
|
class ApnsProvider(PushProvider):
|
||||||
name = "apns"
|
name = "apns"
|
||||||
label = PROVIDER_LABEL
|
label = PROVIDER_LABEL
|
||||||
@@ -323,16 +330,20 @@ class ApnsProvider(PushProvider):
|
|||||||
return fields
|
return fields
|
||||||
|
|
||||||
def prepare(self, payload: dict[str, Any]) -> str:
|
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(
|
return json.dumps(
|
||||||
{
|
{
|
||||||
"aps": {
|
"aps": aps,
|
||||||
"alert": {
|
|
||||||
"title": payload.get("title") or "DevPlace",
|
|
||||||
"body": payload.get("message") or "",
|
|
||||||
},
|
|
||||||
"sound": "default",
|
|
||||||
"thread-id": THREAD_ID,
|
|
||||||
},
|
|
||||||
"url": payload.get("url") or DEFAULT_PUSH_URL,
|
"url": payload.get("url") or DEFAULT_PUSH_URL,
|
||||||
"icon": payload.get("icon") or PUSH_ICON,
|
"icon": payload.get("icon") or PUSH_ICON,
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "devplacepy"
|
name = "devplacepy"
|
||||||
version = "1.1.29"
|
version = "1.1.30"
|
||||||
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