diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index dcee9b4d8f..d16eedc791 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -775,7 +775,7 @@ def create_user_messages( # automatically marked as read for yourself; scheduled # messages to yourself only are not. user_profile_id == sender_id - and message.sent_by_human() + and message.sending_client.default_read_by_sender() and not scheduled_message_to_self ) or user_profile_id in mark_as_read_user_ids diff --git a/zerver/models.py b/zerver/models.py index ad506b5153..f3d8d31d7b 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -2968,6 +2968,37 @@ class Client(models.Model): def __str__(self) -> str: return self.name + def default_read_by_sender(self) -> bool: + """Used to determine whether a message was sent by a full Zulip UI + style client (and thus whether the message should be treated + as sent by a human and automatically marked as read for the + sender). The purpose of this distinction is to ensure that + message sent to the user by e.g. a Google Calendar integration + using the user's own API key don't get marked as read + automatically. + """ + sending_client = self.name.lower() + + return ( + sending_client + in ( + "zulipandroid", + "zulipios", + "zulipdesktop", + "zulipmobile", + "zulipelectron", + "zulipterminal", + "snipe", + "website", + "ios", + "android", + ) + or "desktop app" in sending_client + # Since the vast majority of messages are sent by humans + # in Zulip, treat test suite messages as such. + or (sending_client == "test suite" and settings.TEST_SUITE) + ) + get_client_cache: Dict[str, Client] = {} @@ -3235,39 +3266,6 @@ class Message(AbstractMessage): or rendered_content_version < markdown_version ) - def sent_by_human(self) -> bool: - """Used to determine whether a message was sent by a full Zulip UI - style client (and thus whether the message should be treated - as sent by a human and automatically marked as read for the - sender). The purpose of this distinction is to ensure that - message sent to the user by e.g. a Google Calendar integration - using the user's own API key don't get marked as read - automatically. - """ - sending_client = self.sending_client.name.lower() - - return ( - ( - sending_client - in ( - "zulipandroid", - "zulipios", - "zulipdesktop", - "zulipmobile", - "zulipelectron", - "zulipterminal", - "snipe", - "website", - "ios", - "android", - ) - ) - or ("desktop app" in sending_client) - # Since the vast majority of messages are sent by humans - # in Zulip, treat test suite messages as such. - or (sending_client == "test suite" and settings.TEST_SUITE) - ) - @staticmethod def is_status_message(content: str, rendered_content: str) -> bool: """ diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py index 8868711e56..f09f907e61 100644 --- a/zerver/tests/test_digest.py +++ b/zerver/tests/test_digest.py @@ -547,7 +547,7 @@ class TestDigestEmailMessages(ZulipTestCase): self.assertEqual(stream_info["html"], []) def simulate_stream_conversation(self, stream: str, senders: List[str]) -> List[int]: - client = "website" # this makes `sent_by_human` return True + client = "website" # this makes `default_read_by_sender` return True sending_client = get_client(client) message_ids = [] # List[int] for sender_name in senders: diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.py index a7d46655a3..ed06849974 100644 --- a/zerver/tests/test_message_flags.py +++ b/zerver/tests/test_message_flags.py @@ -880,7 +880,7 @@ class GetUnreadMsgsTest(ZulipTestCase): # Check our test setup is correct--the message should # not have looked like it was sent by a human. message = Message.objects.get(id=message_id) - self.assertFalse(message.sent_by_human()) + self.assertFalse(message.sending_client.default_read_by_sender()) # And since it was not sent by a human, it should not # be read, not even by the sender (Hamlet).