From c0f7158378c9218f804ffe759a066c48ec5309e0 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sat, 29 Jan 2022 22:59:06 +0100 Subject: [PATCH] push_notifications: Include stream_id in the notification data. Closes #18067. Previous only the stream name was sent, which is an unstable stream identifier. --- templates/zerver/api/changelog.md | 6 ++++++ version.py | 2 +- zerver/lib/push_notifications.py | 1 + zerver/tests/test_push_notifications.py | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 83a7424ee3..0362df9b4d 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 5.0 + +**Feature level 115** + +* Mobile push notifications about stream messages now include the + `stream_id` field. + **Feature level 114** * [`GET /events`](/api/get-events): Added `rendering_only` field to diff --git a/version.py b/version.py index 18816eda0b..71905ba425 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3" # Changes should be accompanied by documentation explaining what the # new level means in templates/zerver/api/changelog.md, as well as # "**Changes**" entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 114 +API_FEATURE_LEVEL = 115 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index c23764cd2c..f08973a564 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -714,6 +714,7 @@ def get_message_payload( if message.recipient.type == Recipient.STREAM: data["recipient_type"] = "stream" data["stream"] = get_display_recipient(message.recipient) + data["stream_id"] = message.recipient.type_id data["topic"] = message.topic_name() elif message.recipient.type == Recipient.HUDDLE: data["recipient_type"] = "private" diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 720752ce88..46c6e90719 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -1717,6 +1717,7 @@ class TestGetAPNsPayload(PushNotificationTest): "sender_email": self.sender.email, "sender_id": self.sender.id, "stream": get_display_recipient(message.recipient), + "stream_id": stream.id, "topic": message.topic_name(), "server": settings.EXTERNAL_HOST, "realm_id": self.sender.realm.id, @@ -1747,6 +1748,7 @@ class TestGetAPNsPayload(PushNotificationTest): "sender_email": self.sender.email, "sender_id": self.sender.id, "stream": get_display_recipient(message.recipient), + "stream_id": stream.id, "topic": message.topic_name(), "server": settings.EXTERNAL_HOST, "realm_id": self.sender.realm.id, @@ -1780,6 +1782,7 @@ class TestGetAPNsPayload(PushNotificationTest): "sender_email": self.sender.email, "sender_id": self.sender.id, "stream": get_display_recipient(message.recipient), + "stream_id": stream.id, "topic": message.topic_name(), "server": settings.EXTERNAL_HOST, "realm_id": self.sender.realm.id, @@ -1814,6 +1817,7 @@ class TestGetAPNsPayload(PushNotificationTest): "sender_email": self.sender.email, "sender_id": self.sender.id, "stream": get_display_recipient(message.recipient), + "stream_id": stream.id, "topic": message.topic_name(), "server": settings.EXTERNAL_HOST, "realm_id": self.sender.realm.id, @@ -1901,6 +1905,7 @@ class TestGetGCMPayload(PushNotificationTest): "sender_avatar_url": absolute_avatar_url(message.sender), "recipient_type": "stream", "stream": get_display_recipient(message.recipient), + "stream_id": stream.id, "topic": message.topic_name(), } @@ -1995,6 +2000,7 @@ class TestGetGCMPayload(PushNotificationTest): "recipient_type": "stream", "topic": "Test topic", "stream": "Denmark", + "stream_id": stream.id, }, ) self.assertDictEqual( @@ -2032,6 +2038,7 @@ class TestGetGCMPayload(PushNotificationTest): "recipient_type": "stream", "topic": "Test topic", "stream": "Denmark", + "stream_id": stream.id, }, ) self.assertDictEqual(