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.

push_notification: Remove obsolete fields from APNs payload.

Prakhar Pratyush1a5cab130d62
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 5c823237954..3d706554d20 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 11.0
+**Feature level 413**
+
+* Mobile push notification payloads for APNs no longer contain the
+ `server` and `realm_id` fields, which were unused.
+
**Feature level 412**
* [`POST /register`](/api/register-queue),
@@ -43,7 +48,7 @@ format used by the Zulip server that they are interacting with.
* [`POST /register`](/api/register-queue): Added
`max_channel_folder_name_length` and
`max_channel_folder_description_length` fields to the response.
-- Mobile push notification payloads for APNs no longer contain the
+* Mobile push notification payloads for APNs no longer contain the
`time` field, which was unused.
**Feature level 409**
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py
index eb3677bbe17..92ea7be5082 100644
--- a/zerver/lib/push_notifications.py
+++ b/zerver/lib/push_notifications.py
@@ -977,6 +977,14 @@ def get_base_payload(user_profile: UserProfile) -> dict[str, Any]:
return data
+def remove_obsolete_fields_apns(payload: dict[str, Any]) -> None:
+ # These fields are not used by iOS clients. The legacy
+ # app requires these in FCM messages, even though we don't
+ # end up doing anything with them.
+ payload.pop("server")
+ payload.pop("realm_id")
+
+
def get_message_payload(
user_profile: UserProfile,
message: Message,
@@ -1127,6 +1135,7 @@ def get_message_payload_apns(
zulip_data.update(
message_ids=[message.id],
)
+ remove_obsolete_fields_apns(zulip_data)
assert message.rendered_content is not None
with override_language(user_profile.default_language):
@@ -1208,6 +1217,7 @@ def get_remove_payload_apns(user_profile: UserProfile, message_ids: list[int]) -
event="remove",
zulip_message_ids=",".join(str(id) for id in message_ids),
)
+ remove_obsolete_fields_apns(zulip_data)
apns_data = {
"badge": get_apns_badge_count(user_profile, message_ids),
"custom": {"zulip": zulip_data},
diff --git a/zerver/tests/test_handle_push_notification.py b/zerver/tests/test_handle_push_notification.py
index f51352924c9..8463f732fad 100644
--- a/zerver/tests/test_handle_push_notification.py
+++ b/zerver/tests/test_handle_push_notification.py
@@ -637,8 +637,6 @@ class HandlePushNotificationTest(PushNotificationTestCase):
"badge": 0,
"custom": {
"zulip": {
- "server": "testserver",
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": "http://zulip.testserver",
"realm_url": "http://zulip.testserver",
@@ -737,8 +735,6 @@ class HandlePushNotificationTest(PushNotificationTestCase):
"badge": 0,
"custom": {
"zulip": {
- "server": "testserver",
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": "http://zulip.testserver",
"realm_url": "http://zulip.testserver",
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 8ce1114effe..8c24da09750 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -1468,8 +1468,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"recipient_type": "private",
"sender_email": self.sender.email,
"sender_id": self.sender.id,
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1510,8 +1508,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"recipient_type": "private",
"sender_email": self.sender.email,
"sender_id": self.sender.id,
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1554,8 +1550,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
),
"sender_email": self.sender.email,
"sender_id": self.sender.id,
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1595,8 +1589,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"stream": stream.name,
"stream_id": stream.id,
"topic": topic_display_name,
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1639,8 +1631,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"stream": stream.name,
"stream_id": stream.id,
"topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1677,8 +1667,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"stream": stream.name,
"stream_id": stream.id,
"topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1716,8 +1704,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"stream": stream.name,
"stream_id": stream.id,
"topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.url,
"realm_url": self.sender.realm.url,
@@ -1786,8 +1772,6 @@ class TestGetAPNsPayload(PushNotificationTestCase):
"stream": stream.name,
"stream_id": stream.id,
"topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": hamlet.realm.id,
"realm_name": hamlet.realm.name,
"realm_uri": hamlet.realm.url,
"realm_url": hamlet.realm.url,