mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
digest: Exclude bots with sender.is_bot, not sent_by_human.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
92c1dfc248
commit
d893ff5ba8
@@ -56,7 +56,7 @@ class DigestTopic:
|
|||||||
if len(self.sample_messages) < 2:
|
if len(self.sample_messages) < 2:
|
||||||
self.sample_messages.append(message)
|
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.human_senders.add(message.sender.full_name)
|
||||||
self.num_human_messages += 1
|
self.num_human_messages += 1
|
||||||
|
|
||||||
@@ -195,12 +195,15 @@ def get_recent_topics(
|
|||||||
.select_related(
|
.select_related(
|
||||||
"recipient", # build_message_list looks up recipient.type
|
"recipient", # build_message_list looks up recipient.type
|
||||||
"sender", # we need the sender's full name
|
"sender", # we need the sender's full name
|
||||||
"sending_client", # for Message.sent_by_human
|
|
||||||
)
|
)
|
||||||
.defer(
|
.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.
|
# 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"}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -602,7 +602,6 @@ Output:
|
|||||||
desdemona="desdemona@zulip.com",
|
desdemona="desdemona@zulip.com",
|
||||||
shiva="shiva@zulip.com",
|
shiva="shiva@zulip.com",
|
||||||
webhook_bot="webhook-bot@zulip.com",
|
webhook_bot="webhook-bot@zulip.com",
|
||||||
welcome_bot="welcome-bot@zulip.com",
|
|
||||||
outgoing_webhook_bot="outgoing-webhook@zulip.com",
|
outgoing_webhook_bot="outgoing-webhook@zulip.com",
|
||||||
default_bot="default-bot@zulip.com",
|
default_bot="default-bot@zulip.com",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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.streams import create_stream_if_needed
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
Client,
|
|
||||||
Message,
|
Message,
|
||||||
Realm,
|
Realm,
|
||||||
RealmAuditLog,
|
RealmAuditLog,
|
||||||
@@ -578,24 +577,22 @@ class TestDigestTopics(ZulipTestCase):
|
|||||||
bot_messages: int,
|
bot_messages: int,
|
||||||
realm: Realm,
|
realm: Realm,
|
||||||
) -> None:
|
) -> 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
|
messages_sent = 0
|
||||||
while messages_sent < messages:
|
while messages_sent < messages:
|
||||||
for index, username in enumerate(self.example_user_map, start=1):
|
for index, username in enumerate(self.example_user_map, start=1):
|
||||||
topic.add_message(
|
if self.example_user(username).is_bot != is_bot:
|
||||||
Message(
|
continue
|
||||||
sender=self.example_user(username), sending_client=client, realm=realm
|
topic.add_message(Message(sender=self.example_user(username), realm=realm))
|
||||||
)
|
|
||||||
)
|
|
||||||
messages_sent += 1
|
messages_sent += 1
|
||||||
if messages_sent == messages:
|
if messages_sent == messages:
|
||||||
break
|
break
|
||||||
if index == users:
|
if index == users:
|
||||||
break
|
break
|
||||||
|
|
||||||
send_messages(Client(name="zulipmobile"), humans, human_messages)
|
|
||||||
send_messages(Client(name="bot"), bots, bot_messages)
|
|
||||||
|
|
||||||
def test_get_hot_topics(self) -> None:
|
def test_get_hot_topics(self) -> None:
|
||||||
realm = get_realm("zulip")
|
realm = get_realm("zulip")
|
||||||
denmark = get_stream("Denmark", realm)
|
denmark = get_stream("Denmark", realm)
|
||||||
|
|||||||
Reference in New Issue
Block a user