Skip to content

Commit

Permalink
push_notifications: Remove DeviceTokenType logic.
Browse files Browse the repository at this point in the history
The syntax wasn't valid on Python 3.5, and the new code is somewhat
more readable anyway.
  • Loading branch information
timabbott committed May 16, 2017
1 parent 9d63a5a commit 0b2388b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions zerver/lib/push_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
RemotePushDeviceToken = Mock() # type: ignore # https://github.com/JukkaL/mypy/issues/1188

DeviceToken = Union[PushDeviceToken, RemotePushDeviceToken]
DeviceTokenType = Union[Type[PushDeviceToken], Type[RemotePushDeviceToken]]

# APNS error codes
ERROR_CODES = {
Expand Down Expand Up @@ -231,18 +230,17 @@ def send_android_push_notification_to_user(user_profile, data):
send_android_push_notification(devices, data)

@statsd_increment("android_push_notification")
def send_android_push_notification(devices, data):
# type: (List[DeviceToken], Dict[str, Any]) -> None
def send_android_push_notification(devices, data, remote=False):
# type: (List[DeviceToken], Dict[str, Any], bool) -> None
if not gcm:
logging.warning("Attempting to send a GCM push notification, but no API key was configured")
return
reg_ids = [device.token for device in devices]

# If we are on notification bouncer, we will get RemotePushDeviceToken
# devices otherwise we will get PushDeviceToken devices. We save the type
# of devices in DeviceTokenClass so that we can delete the tokens from
# their respective DB tables.
DeviceTokenClass = type(devices[0]) # type: DeviceTokenType
if remote:
DeviceTokenClass = RemotePushDeviceToken # nocoverage # TODO: Test this code path
else:
DeviceTokenClass = PushDeviceToken

res = gcm.json_request(registration_ids=reg_ids, data=data)

Expand Down
2 changes: 1 addition & 1 deletion zilencer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def remote_server_notify_push(request, # type: HttpRequest
))

if android_devices:
send_android_push_notification(android_devices, gcm_payload)
send_android_push_notification(android_devices, gcm_payload, remote=True)

# TODO: set badge count in a better way
if apple_devices:
Expand Down

0 comments on commit 0b2388b

Please sign in to comment.