push_notification: Push data from Zilencer.

This commit is contained in:
Umair Khan 2017-05-09 13:31:47 +05:00 committed by Tim Abbott
parent ab411ab7b3
commit c4e5b75ead
1 changed files with 26 additions and 0 deletions

View File

@ -79,4 +79,30 @@ def remote_server_notify_push(request, # type: HttpRequest
): ):
# type: (...) -> HttpResponse # type: (...) -> HttpResponse
validate_entity(entity) validate_entity(entity)
server = cast(RemoteZulipServer, entity)
user_id = payload['user_id']
gcm_payload = payload['gcm_payload']
apns_payload = payload['apns_payload']
android_devices = list(RemotePushDeviceToken.objects.filter(
user_id=user_id,
kind=RemotePushDeviceToken.GCM,
server=server
))
apple_devices = list(RemotePushDeviceToken.objects.filter(
user_id=user_id,
kind=RemotePushDeviceToken.APNS,
server=server
))
if android_devices:
send_android_push_notification(android_devices, gcm_payload)
# TODO: set badge count in a better way
if apple_devices:
send_apple_push_notification(user_id, apple_devices,
badge=1, zulip=apns_payload)
return json_success() return json_success()