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.
This commit is contained in:
Umair Khan 2017-05-08 16:47:18 +05:00 committed by Tim Abbott
parent 112a67097b
commit 329b377e6a
1 changed files with 6 additions and 2 deletions

View File

@ -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,