mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
push_notifs: Support APNs token auth, as well as cert auth.
This will make it possible to send notifications to multiple distinct app IDs over the same connection.
This commit is contained in:
@@ -145,13 +145,17 @@ class APNsContext:
|
||||
loop: asyncio.AbstractEventLoop
|
||||
|
||||
|
||||
def apns_enabled() -> bool:
|
||||
return settings.APNS_TOKEN_KEY_FILE is not None or settings.APNS_CERT_FILE is not None
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def get_apns_context() -> Optional[APNsContext]:
|
||||
# We lazily do this import as part of optimizing Zulip's base
|
||||
# import time.
|
||||
import aioapns
|
||||
|
||||
if settings.APNS_CERT_FILE is None: # nocoverage
|
||||
if not apns_enabled(): # nocoverage
|
||||
return None
|
||||
|
||||
# NB if called concurrently, this will make excess connections.
|
||||
@@ -171,6 +175,9 @@ def get_apns_context() -> Optional[APNsContext]:
|
||||
async def make_apns() -> aioapns.APNs:
|
||||
return aioapns.APNs(
|
||||
client_cert=settings.APNS_CERT_FILE,
|
||||
key=settings.APNS_TOKEN_KEY_FILE,
|
||||
key_id=settings.APNS_TOKEN_KEY_ID,
|
||||
team_id=settings.APNS_TEAM_ID,
|
||||
topic=settings.APNS_TOPIC,
|
||||
max_connection_attempts=APNS_MAX_RETRIES,
|
||||
use_sandbox=settings.APNS_SANDBOX,
|
||||
@@ -181,10 +188,6 @@ def get_apns_context() -> Optional[APNsContext]:
|
||||
return APNsContext(apns=apns, loop=loop)
|
||||
|
||||
|
||||
def apns_enabled() -> bool:
|
||||
return settings.APNS_CERT_FILE is not None
|
||||
|
||||
|
||||
def modernize_apns_payload(data: Mapping[str, Any]) -> Mapping[str, Any]:
|
||||
"""Take a payload in an unknown Zulip version's format, and return in current format."""
|
||||
# TODO this isn't super robust as is -- if a buggy remote server
|
||||
|
||||
Reference in New Issue
Block a user