Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
digest: Replace dict[str, Any] with DigestTeaserData dataclass.
Rocker810ab04daf35ef3
diff --git a/zerver/lib/digest.py b/zerver/lib/digest.pyindex 43987e5f3bc..c5313256357 100644--- a/zerver/lib/digest.py+++ b/zerver/lib/digest.py@@ -3,6 +3,7 @@ import heapqimport loggingfrom collections import defaultdictfrom collections.abc import Collection, Iterator+from dataclasses import dataclassfrom datetime import datetime, timedelta, timezonefrom typing import Any, TypeAlias@@ -16,6 +17,7 @@ from markupsafe import Markupfrom confirmation.models import one_click_unsubscribe_linkfrom zerver.context_processors import common_contextfrom zerver.lib.email_notifications import (+ MessageListPayload,build_message_list,get_channel_privacy_icon,message_content_allowed_in_missedmessage_emails,@@ -48,6 +50,13 @@ MAX_HOT_TOPICS_TO_BE_INCLUDED_IN_DIGEST = 4TopicKey: TypeAlias = tuple[int, str]+@dataclass+class DigestTeaserData:+ participants: list[str]+ count: int+ first_few_messages: MessageListPayload++class DigestTopic:def __init__(self, topic_key: TopicKey) -> None:self.topic_key = topic_key@@ -73,18 +82,18 @@ class DigestTopic:def diversity(self) -> int:return len(self.human_senders)- def teaser_data(self, user: UserProfile, stream_id_map: dict[int, Stream]) -> dict[str, Any]:+ def teaser_data(self, user: UserProfile, stream_id_map: dict[int, Stream]) -> DigestTeaserData:teaser_count = self.num_human_messages - len(self.sample_messages)first_few_messages = build_message_list(user=user,messages=self.sample_messages,stream_id_map=stream_id_map,)- return {- "participants": sorted(self.human_senders),- "count": teaser_count,- "first_few_messages": first_few_messages,- }+ return DigestTeaserData(+ participants=sorted(self.human_senders),+ count=teaser_count,+ first_few_messages=first_few_messages,+ )# Digests accumulate 2 types of interesting traffic for a user:diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.pyindex 3e6b11bc959..ee8d553f903 100644--- a/zerver/tests/test_digest.py+++ b/zerver/tests/test_digest.py@@ -75,9 +75,9 @@ class TestDigestEmailMessages(ZulipTestCase):expected_participants = {self.example_user(sender).full_name for sender in senders}- self.assertEqual(set(hot_convo["participants"]), expected_participants)- self.assertEqual(hot_convo["count"], 5 - 2) # 5 messages, but 2 shown- teaser_messages = hot_convo["first_few_messages"].senders+ self.assertEqual(set(hot_convo.participants), expected_participants)+ self.assertEqual(hot_convo.count, 5 - 2) # 5 messages, but 2 shown+ teaser_messages = hot_convo.first_few_messages.sendersself.assertIn("some content", teaser_messages[0].content[0].plain)self.assertIn(teaser_messages[0].sender, expected_participants)@@ -276,9 +276,9 @@ class TestDigestEmailMessages(ZulipTestCase):hot_convo = hot_conversations[0]expected_participants = {self.example_user(sender).full_name for sender in senders}- self.assertEqual(set(hot_convo["participants"]), expected_participants)- self.assertEqual(hot_convo["count"], 5 - 2) # 5 messages, but 2 shown- teaser_messages = hot_convo["first_few_messages"].senders+ self.assertEqual(set(hot_convo.participants), expected_participants)+ self.assertEqual(hot_convo.count, 5 - 2) # 5 messages, but 2 shown+ teaser_messages = hot_convo.first_few_messages.sendersself.assertIn("some content", teaser_messages[0].content[0].plain)self.assertIn(teaser_messages[0].sender, expected_participants)@@ -714,11 +714,11 @@ class TestDigestEmailMessages(ZulipTestCase):hot_convo = kwargs["context"]["hot_conversations"][0]# Verify the header HTML contains the general chat- header_html = hot_convo["first_few_messages"].header.html+ header_html = hot_convo.first_few_messages.header.htmlself.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+ header_plain = hot_convo.first_few_messages.header.plainself.assertIn("general chat", header_plain)