From 329b377e6a6fd5a2248df93e7980f1d2b7738d2c Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Mon, 8 May 2017 16:47:18 +0500 Subject: [PATCH] push_notification: Add uses_notification_bouncer(). This function abstracts the logic to ascertain if we are using notification bouncer service or not. Makes our code more maintainable. --- zerver/lib/push_notifications.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index 0da000dfde..9b1ce6205d 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -59,6 +59,10 @@ dbx_connection = None # `APNS_SANDBOX` should be a bool assert isinstance(settings.APNS_SANDBOX, bool) +def uses_notification_bouncer(): + # type: () -> bool + return settings.PUSH_NOTIFICATION_BOUNCER_URL is not None + def get_apns_key(identifer): # type: (SupportsInt) -> str return 'apns:' + str(identifer) @@ -363,7 +367,7 @@ def add_push_device_token(user_profile, token_str, kind, ios_app_id=None): # If we're sending things to the push notification bouncer # register this user with them here - if settings.PUSH_NOTIFICATION_BOUNCER_URL is not None: + if uses_notification_bouncer(): post_data = { 'server_uuid': settings.ZULIP_ORG_ID, 'user_id': user_profile.id, @@ -396,7 +400,7 @@ def remove_push_device_token(user_profile, token_str, kind): # If we're sending things to the push notification bouncer # register this user with them here - if settings.PUSH_NOTIFICATION_BOUNCER_URL is not None: + if uses_notification_bouncer(): # TODO: Make this a remove item post_data = { 'server_uuid': settings.ZULIP_ORG_ID,