Repository: zulip/zulip

Issue:
Include stream ID in push notifications for stream messages
Currently our push notifications include user IDs for all the users involved, but for the stream of a stream message they only include the stream name -- not the stream ID:

https://github.com/zulip/zulip/blob/4dacbfdc823ce7347979683e917eabb390c8ae07/zerver/lib/push_notifications.py#L670-L674

We should add a field `stream_id` which has the numeric stream ID, so that it's possible for clients to interpret the data in a way that's robust to the stream's name changing.



Discussion:
@mateuszmandera want to just do this?  It seems really quick.
Bump. It'd be nice to get this in, because if we have it in 5.0 then that will shorten the period that we have to have fallback code in the client for using the stream name instead (and hoping that e.g. it hasn't been renamed.)


Resolving patch:
diff --git a/version.py b/version.py
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@
 # 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
--- 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"


Test patch:
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -1717,6 +1717,7 @@ def test_get_message_payload_apns_stream_message(self) -> None:
                     "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 @@ def test_get_message_payload_apns_stream_mention(self) -> None:
                     "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 @@ def test_get_message_payload_apns_user_group_mention(self) -> None:
                     "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 @@ def test_get_message_payload_apns_stream_wildcard_mention(self) -> None:
                     "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 @@ def _test_get_message_payload_gcm_mentions(
             "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 @@ def test_get_message_payload_gcm_stream_notifications(self) -> None:
                 "recipient_type": "stream",
                 "topic": "Test topic",
                 "stream": "Denmark",
+                "stream_id": stream.id,
             },
         )
         self.assertDictEqual(
@@ -2032,6 +2038,7 @@ def test_get_message_payload_gcm_redacted_content(self) -> None:
                 "recipient_type": "stream",
                 "topic": "Test topic",
                 "stream": "Denmark",
+                "stream_id": stream.id,
             },
         )
         self.assertDictEqual(