mirror of https://github.com/zulip/zulip.git
models: Move Message.sent_by_human to Client.default_read_by_sender.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
d893ff5ba8
commit
d7d5b6c73e
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
"""
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Reference in New Issue