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: Exclude bots with sender.is_bot, not sent_by_human.

Anders Kaseorgd893ff5ba80a
diff --git a/zerver/lib/digest.py b/zerver/lib/digest.py
index d0e91cdf783..12413ac9431 100644
--- a/zerver/lib/digest.py
+++ b/zerver/lib/digest.py
@@ -56,7 +56,7 @@ class DigestTopic:
if len(self.sample_messages) < 2:
self.sample_messages.append(message)
- if message.sent_by_human():
+ if not message.sender.is_bot:
self.human_senders.add(message.sender.full_name)
self.num_human_messages += 1
@@ -195,12 +195,15 @@ def get_recent_topics(
.select_related(
"recipient", # build_message_list looks up recipient.type
"sender", # we need the sender's full name
- "sending_client", # for Message.sent_by_human
)
.defer(
- # This construction, to only fetch the sender's full_name,
+ # This construction, to only fetch the sender's full_name and is_bot,
# is because `.only()` doesn't work with select_related tables.
- *{f"sender__{f.name}" for f in UserProfile._meta.fields if f.name not in {"full_name"}}
+ *{
+ f"sender__{f.name}"
+ for f in UserProfile._meta.fields
+ if f.name not in {"full_name", "is_bot"}
+ }
)
)
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 6be8b861d2d..9cf8d2acac9 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -602,7 +602,6 @@ Output:
desdemona="[email protected]",
webhook_bot="[email protected]",
- welcome_bot="[email protected]",
outgoing_webhook_bot="[email protected]",
default_bot="[email protected]",
)
diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py
index c70f859781c..8868711e56c 100644
--- a/zerver/tests/test_digest.py
+++ b/zerver/tests/test_digest.py
@@ -27,7 +27,6 @@ from zerver.lib.message import get_last_message_id
from zerver.lib.streams import create_stream_if_needed
from zerver.lib.test_classes import ZulipTestCase
from zerver.models import (
- Client,
Message,
Realm,
RealmAuditLog,
@@ -578,24 +577,22 @@ class TestDigestTopics(ZulipTestCase):
bot_messages: int,
realm: Realm,
) -> None:
- def send_messages(client: Client, users: int, messages: int) -> None:
+ for is_bot, users, messages in [
+ (False, humans, human_messages),
+ (True, bots, bot_messages),
+ ]:
messages_sent = 0
while messages_sent < messages:
for index, username in enumerate(self.example_user_map, start=1):
- topic.add_message(
- Message(
- sender=self.example_user(username), sending_client=client, realm=realm
- )
- )
+ if self.example_user(username).is_bot != is_bot:
+ continue
+ topic.add_message(Message(sender=self.example_user(username), realm=realm))
messages_sent += 1
if messages_sent == messages:
break
if index == users:
break
- send_messages(Client(name="zulipmobile"), humans, human_messages)
- send_messages(Client(name="bot"), bots, bot_messages)
-
def test_get_hot_topics(self) -> None:
realm = get_realm("zulip")
denmark = get_stream("Denmark", realm)