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.

digest: Display italicized “general chat” when topic is empty.

Amit Patila7675d656cd3
diff --git a/templates/zerver/emails/email.css b/templates/zerver/emails/email.css
index 0d3b0a8e1cd..d1315d4f94a 100644
--- a/templates/zerver/emails/email.css
+++ b/templates/zerver/emails/email.css
@@ -219,6 +219,11 @@ p.digest_paragraph,
z-index: 100;
}
+/* Styling for empty topic placeholders. */
+.empty-topic-display {
+ font-style: italic;
+}
+
/* CSS for digest email content. */
.messages {
width: 600px;
diff --git a/zerver/lib/email_notifications.py b/zerver/lib/email_notifications.py
index 3f120461780..c9ae3946968 100644
--- a/zerver/lib/email_notifications.py
+++ b/zerver/lib/email_notifications.py
@@ -309,22 +309,29 @@ def build_message_list(
assert stream_id_map is not None
assert stream_id in stream_id_map
stream = stream_id_map[stream_id]
+ topic_name = message.topic_name()
+ topic_display_name = get_topic_display_name(topic_name, user.default_language)
narrow_link = topic_narrow_url(
realm=user.realm,
stream=stream,
- topic_name=message.topic_name(),
+ topic_name=topic_name,
)
channel_privacy_icon = get_channel_privacy_icon(stream)
- header = f"{channel_privacy_icon}{stream.name} > {message.topic_name()}"
+ header = f"{channel_privacy_icon}{stream.name} > {topic_display_name}"
+ topic_html: Markup = Markup.escape(topic_display_name)
+ if topic_name == "":
+ topic_html = Markup("<span class='empty-topic-display'>{topic_html}</span>").format(
+ topic_html=topic_html,
+ )
stream_link = stream_narrow_url(user.realm, stream)
header_html = Markup(
- "<a href='{stream_link}'>{channel_privacy_icon}{stream_name}</a> &gt; <a href='{narrow_link}'>{topic_name}</a>"
+ "<a href='{stream_link}'>{channel_privacy_icon}{stream_name}</a> &gt; <a href='{narrow_link}'>{topic_html}</a>"
).format(
stream_link=stream_link,
channel_privacy_icon=channel_privacy_icon,
stream_name=stream.name,
narrow_link=narrow_link,
- topic_name=message.topic_name(),
+ topic_html=topic_html,
)
return {
"plain": header,
diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py
index 400c7a15658..bc84311cbc5 100644
--- a/zerver/tests/test_digest.py
+++ b/zerver/tests/test_digest.py
@@ -678,6 +678,46 @@ class TestDigestEmailMessages(ZulipTestCase):
kwargs = mock_send_future_email.call_args[1]
self.assert_length(kwargs["context"]["hot_conversations"], 2)
+ def test_general_chat_in_digest(self) -> None:
+ othello = self.example_user("othello")
+ self.subscribe(othello, "Verona")
+
+ one_day_ago = timezone_now() - timedelta(days=1)
+ # Backdate the subscription audit log so the stream is not excluded
+ RealmAuditLog.objects.filter(
+ modified_user=othello,
+ event_type=AuditLogEventType.SUBSCRIPTION_CREATED,
+ ).update(event_time=one_day_ago)
+
+ Message.objects.all().update(date_sent=one_day_ago)
+ one_hour_ago = timezone_now() - timedelta(seconds=3600)
+
+ cutoff = time.mktime(one_hour_ago.timetuple())
+
+ # Send a message to "general chat" (empty topic)
+ self.send_stream_message(self.example_user("hamlet"), "Verona", "hello", topic_name="")
+
+ # Clear the LRU cache on the stream topics
+ get_recent_topics.cache_clear()
+
+ with (
+ mock.patch("zerver.lib.digest.enough_traffic", return_value=True),
+ mock.patch("zerver.lib.digest.send_future_email") as mock_send_future_email,
+ ):
+ bulk_handle_digest_email([othello.id], cutoff)
+
+ self.assertEqual(mock_send_future_email.call_count, 1)
+ kwargs = mock_send_future_email.call_args[1]
+
+ hot_convo = kwargs["context"]["hot_conversations"][0]
+ # Verify the header HTML contains the general chat
+ header_html = hot_convo["first_few_messages"]["header"]["html"]
+ self.assertIn("<span class='empty-topic-display'>general chat</span>", header_html)
+
+ # Verify the Plain header contains the general chat
+ header_plain = hot_convo["first_few_messages"]["header"]["plain"]
+ self.assertIn("general chat", header_plain)
+
class TestDigestContentInBrowser(ZulipTestCase):
def test_get_digest_content_in_browser(self) -> None: