Repository: zulip/zulip

Issue:
Reformat stream retention policy change notification
We should change the format of the stream retention policy notification message to be consistent with other stream notifications added in #20289 (cf. #20723).

Current format:
![Screen Shot 2022-01-28 at 2 16 55 PM](https://user-images.githubusercontent.com/2090066/151629150-ecb507e3-e89b-452f-9e28-f1d9e056313c.png)

Updated format:
@ Desdemona has changed the [message retention period](/help/message-retention-policy) for this stream:

* **Old retention period**: Forever
* **New retention period**: 15 days

Messages will be automatically deleted after 15 days.


Discussion:
Hello @zulip/server-streams members, this issue was labeled with the "area: stream settings" label, so you may want to check it out!

<!-- areaLabelAddition -->


Resolving patch:
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -5429,25 +5429,29 @@ def send_change_stream_message_retention_days_notification(
 
     with override_language(stream.realm.default_language):
         if old_value == Stream.MESSAGE_RETENTION_SPECIAL_VALUES_MAP["unlimited"]:
-            notification_string = _(
-                "{user} has changed the [message retention period](/help/message-retention-policy) for this stream from "
-                "**Forever** to **{new_value} days**. Messages will be automatically deleted after {new_value} days."
-            )
-            notification_string = notification_string.format(user=user_mention, new_value=new_value)
+            old_retention_period = _("Forever")
+            new_retention_period = f"{new_value} days"
+            summary_line = f"Messages in this stream will now be automatically deleted {new_value} days after they are sent."
         elif new_value == Stream.MESSAGE_RETENTION_SPECIAL_VALUES_MAP["unlimited"]:
-            notification_string = _(
-                "{user} has changed the [message retention period](/help/message-retention-policy) for this stream from "
-                "**{old_value} days** to **Forever**."
-            )
-            notification_string = notification_string.format(user=user_mention, old_value=old_value)
+            old_retention_period = f"{old_value} days"
+            new_retention_period = _("Forever")
+            summary_line = _("Messages in this stream will now be retained forever.")
         else:
-            notification_string = _(
-                "{user} has changed the [message retention period](/help/message-retention-policy) for this stream from "
-                "**{old_value} days** to **{new_value} days**. Messages will be automatically deleted after {new_value} days."
-            )
-            notification_string = notification_string.format(
-                user=user_mention, old_value=old_value, new_value=new_value
-            )
+            old_retention_period = f"{old_value} days"
+            new_retention_period = f"{new_value} days"
+            summary_line = f"Messages in this stream will now be automatically deleted {new_value} days after they are sent."
+        notification_string = _(
+            "{user} has changed the [message retention period](/help/message-retention-policy) for this stream:\n"
+            "* **Old retention period**: {old_retention_period}\n"
+            "* **New retention period**: {new_retention_period}\n\n"
+            "{summary_line}"
+        )
+        notification_string = notification_string.format(
+            user=user_mention,
+            old_retention_period=old_retention_period,
+            new_retention_period=new_retention_period,
+            summary_line=summary_line,
+        )
         internal_send_stream_message(
             sender, stream, Realm.STREAM_EVENTS_NOTIFICATION_TOPIC, notification_string
         )


Test patch:
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -1781,9 +1781,10 @@ def test_change_stream_message_retention_days_notifications(self) -> None:
         messages = get_topic_messages(user_profile, stream, "stream events")
         self.assert_length(messages, 1)
         expected_notification = (
-            f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) "
-            "for this stream from **Forever** to **2 days**. Messages will be automatically "
-            "deleted after 2 days."
+            f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this stream:\n"
+            "* **Old retention period**: Forever\n"
+            "* **New retention period**: 2 days\n\n"
+            "Messages in this stream will now be automatically deleted 2 days after they are sent."
         )
         self.assertEqual(messages[0].content, expected_notification)
         realm_audit_log = RealmAuditLog.objects.filter(
@@ -1803,9 +1804,10 @@ def test_change_stream_message_retention_days_notifications(self) -> None:
         messages = get_topic_messages(user_profile, stream, "stream events")
         self.assert_length(messages, 2)
         expected_notification = (
-            f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) "
-            "for this stream from **2 days** to **8 days**. Messages will be automatically "
-            "deleted after 8 days."
+            f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this stream:\n"
+            "* **Old retention period**: 2 days\n"
+            "* **New retention period**: 8 days\n\n"
+            "Messages in this stream will now be automatically deleted 8 days after they are sent."
         )
         self.assertEqual(messages[1].content, expected_notification)
         realm_audit_log = RealmAuditLog.objects.filter(
@@ -1826,8 +1828,10 @@ def test_change_stream_message_retention_days_notifications(self) -> None:
         messages = get_topic_messages(user_profile, stream, "stream events")
         self.assert_length(messages, 3)
         expected_notification = (
-            f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) "
-            "for this stream from **8 days** to **Forever**."
+            f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this stream:\n"
+            "* **Old retention period**: 8 days\n"
+            "* **New retention period**: Forever\n\n"
+            "Messages in this stream will now be retained forever."
         )
         self.assertEqual(messages[2].content, expected_notification)
         realm_audit_log = RealmAuditLog.objects.filter(