diff --git a/zilencer/views.py b/zilencer/views.py index a01f405c2e..4ae2443431 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -79,4 +79,30 @@ def remote_server_notify_push(request, # type: HttpRequest ): # type: (...) -> HttpResponse 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()