Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

zilencer: Truncate APNS notifications correctly.

Alex Vandiver1b395b6403a2
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index a8c299fffe1..367b7932d99 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -302,7 +302,10 @@ class PushBouncerNotificationTest(BouncerTestCase):
payload = {
"user_id": hamlet.id,
"gcm_payload": {"event": "remove", "zulip_message_ids": many_ids},
- "apns_payload": {"event": "remove", "zulip_message_ids": many_ids},
+ "apns_payload": {
+ "badge": 0,
+ "custom": {"zulip": {"event": "remove", "zulip_message_ids": many_ids}},
+ },
"gcm_options": {},
}
with mock.patch(
@@ -335,7 +338,15 @@ class PushBouncerNotificationTest(BouncerTestCase):
apple_push.assert_called_once_with(
hamlet.id,
[apple_token],
- {"event": "remove", "zulip_message_ids": ",".join(str(i) for i in range(50, 250))},
+ {
+ "badge": 0,
+ "custom": {
+ "zulip": {
+ "event": "remove",
+ "zulip_message_ids": ",".join(str(i) for i in range(50, 250)),
+ }
+ },
+ },
remote=server,
)
android_push.assert_called_once_with(
diff --git a/zilencer/views.py b/zilencer/views.py
index 50a5808d458..f7d65a6d3ae 100644
--- a/zilencer/views.py
+++ b/zilencer/views.py
@@ -250,7 +250,10 @@ def remote_server_notify_push(
user_id, android_devices, gcm_payload, gcm_options, remote=server
)
- apns_payload = truncate_payload(apns_payload)
+ if isinstance(apns_payload.get("custom"), dict) and isinstance(
+ apns_payload["custom"].get("zulip"), dict
+ ):
+ apns_payload["custom"]["zulip"] = truncate_payload(apns_payload["custom"]["zulip"])
send_apple_push_notification(user_id, apple_devices, apns_payload, remote=server)
return json_success(