push: Pass apple alert via the zulip dict.

This completes the process of simplifying the interface of the
send_*_push_notification functions, so that they can effectively
support a push notification forwarding workflow.
This commit is contained in:
Tim Abbott
2017-03-05 18:30:56 -08:00
parent fc192d6b3b
commit 410c0626a6

View File

@@ -149,14 +149,15 @@ def _do_push_to_apns_service(user_id, message, apns_connection):
def send_apple_push_notification_to_user(user, alert, **extra_data):
# type: (UserProfile, Text, **Any) -> None
devices = PushDeviceToken.objects.filter(user=user, kind=PushDeviceToken.APNS)
send_apple_push_notification(user.id, devices, alert, **extra_data)
send_apple_push_notification(user.id, devices, zulip=dict(alert=alert),
**extra_data)
# Send a push notification to the desired clients
# extra_data is a dict that will be passed to the
# mobile app
@statsd_increment("apple_push_notification")
def send_apple_push_notification(user_id, devices, alert, **extra_data):
# type: (int, List[PushDeviceToken], Text, **Any) -> None
def send_apple_push_notification(user_id, devices, **extra_data):
# type: (int, List[PushDeviceToken], **Any) -> None
if not connection and not dbx_connection:
logging.error("Attempting to send push notification, but no connection was found. "
"This may be because we could not find the APNS Certificate file.")
@@ -175,7 +176,9 @@ def send_apple_push_notification(user_id, devices, alert, **extra_data):
if valid_tokens:
logging.info("APNS: Sending apple push notification "
"to devices: %s" % (valid_devices,))
zulip_message = APNsMessage(user_id, valid_tokens, alert=alert, **extra_data)
zulip_message = APNsMessage(user_id, valid_tokens,
alert=extra_data['zulip']['alert'],
**extra_data)
_do_push_to_apns_service(user_id, zulip_message, conn)
else:
logging.warn("APNS: Not sending notification because "
@@ -296,8 +299,11 @@ def handle_push_notification(user_profile_id, missed_message):
alert = "New Zulip mentions and private messages from %s" % (sender_str,)
if apple_devices:
apple_extra_data = {'message_ids': [message.id]}
send_apple_push_notification(user_profile.id, apple_devices, alert,
apple_extra_data = {
'alert': alert,
'message_ids': [message.id],
}
send_apple_push_notification(user_profile.id, apple_devices,
badge=1, zulip=apple_extra_data)
if android_devices: