Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept apns_topic as an option on each NotificationRequest #52

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aioapns/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NotificationRequest:
"priority",
"collapse_key",
"push_type",
"apns_topic",
)

def __init__(
Expand All @@ -37,6 +38,8 @@ def __init__(
priority: Optional[int] = None,
collapse_key: Optional[str] = None,
push_type: Optional[PushType] = None,
*,
apns_topic: Optional[str] = None,
) -> None:
self.device_token = device_token
self.message = message
Expand All @@ -45,6 +48,7 @@ def __init__(
self.priority = priority
self.collapse_key = collapse_key
self.push_type = push_type
self.apns_topic = apns_topic


class NotificationResult:
Expand Down
6 changes: 5 additions & 1 deletion aioapns/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ async def send_notification(
(":path", "/3/device/%s" % request.device_token),
("host", self.APNS_SERVER),
("apns-id", request.notification_id),
("apns-topic", self.apns_topic),
]
if request.apns_topic is not None:
apns_topic = request.apns_topic
else:
apns_topic = self.apns_topic
headers.append(("apns-topic", apns_topic))
if request.time_to_live is not None:
expiration = int(time.time()) + request.time_to_live
headers.append(("apns-expiration", str(expiration)))
Expand Down
Loading