Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Notify when a message with alert word is received #1301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 66 additions & 5 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,25 +1978,72 @@ def test__update_topic_index(
"vary_each_msg",
"visual_notification_status",
"types_when_notify_called",
"is_muted_stream",
"is_muted_topic",
neiljp marked this conversation as resolved.
Show resolved Hide resolved
],
[
(
5140,
{"flags": ["mentioned", "wildcard_mentioned"]},
True,
[],
None,
None,
), # message_fixture sender_id is 5140
(5179, {"flags": ["mentioned"]}, False, ["stream", "private"]),
(5179, {"flags": ["wildcard_mentioned"]}, False, ["stream", "private"]),
(5179, {"flags": []}, True, ["stream", "private"]),
(5179, {"flags": []}, False, ["private"]),
(5179, {"flags": ["mentioned"]}, False, ["stream", "private"], None, None),
(
5179,
{"flags": ["wildcard_mentioned"]},
False,
["stream", "private"],
None,
None,
),
(5179, {"flags": []}, True, ["stream", "private"], None, None),
(5179, {"flags": []}, False, ["private"], None, None),
(
5179,
{"flags": ["has_alert_word"]},
False,
["stream", "private"],
True,
True,
),
(
5179,
{"flags": ["has_alert_word"]},
False,
["stream", "private"],
True,
False,
),
(
5179,
{"flags": ["has_alert_word"]},
False,
["stream", "private"],
False,
True,
),
(
5179,
{"flags": ["has_alert_word"]},
False,
["stream", "private"],
False,
False,
),
],
ids=[
"not_notified_since_self_message",
"notified_stream_and_private_since_directly_mentioned",
"notified_stream_and_private_since_wildcard_mentioned",
"notified_stream_since_stream_has_desktop_notifications",
"notified_private_since_private_message",
"not_notified_for_stream_since_topic/stream_both_muted",
"not_notified_for_stream_since_stream_muted",
"not_notified_for_stream_since_topic_muted",
"notified_for_stream_since_topic/stream_both_not_muted",
neiljp marked this conversation as resolved.
Show resolved Hide resolved
],
)
def test_notify_users_calling_msg_type(
Expand All @@ -2008,13 +2055,17 @@ def test_notify_users_calling_msg_type(
vary_each_msg,
visual_notification_status,
types_when_notify_called,
is_muted_stream: Optional[bool],
is_muted_topic: Optional[bool],
neiljp marked this conversation as resolved.
Show resolved Hide resolved
):
message_fixture.update(vary_each_msg)
model.user_id = user_id
mocker.patch(
MODEL + ".is_visual_notifications_enabled",
return_value=visual_notification_status,
)
mocker.patch.object(model, "is_muted_stream", return_value=is_muted_stream)
mocker.patch.object(model, "is_muted_topic", return_value=is_muted_topic)
notify = mocker.patch(MODULE + ".notify")

model.notify_user(message_fixture)
Expand All @@ -2031,7 +2082,17 @@ def test_notify_users_calling_msg_type(
if target is not None:
title = f"Test Organization Name:\nFoo Foo (to {target})"
# TODO: Test message content too?
notify.assert_called_once_with(title, mocker.ANY)
if message_fixture["type"] == "private":
notify.assert_called_once_with(title, mocker.ANY)
elif len(
vary_each_msg["flags"]
) == 1 and "has_alert_word" in vary_each_msg.get("flags"):
if not is_muted_topic and not is_muted_stream:
notify.assert_called_once_with(title, mocker.ANY)
else:
notify.assert_not_called()
else:
notify.assert_called_once_with(title, mocker.ANY)
neiljp marked this conversation as resolved.
Show resolved Hide resolved
else:
notify.assert_not_called()

Expand Down
7 changes: 7 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,13 @@ def notify_user(self, message: Message) -> str:
) or self.is_visual_notifications_enabled(stream_id):
recipient = "{display_recipient} -> {subject}".format(**message)

if "has_alert_word" in message["flags"]:
# Check if stream or topic is muted
topic = message.get("subject", "")
if not self.is_muted_stream(stream_id) and not self.is_muted_topic(
stream_id, topic
):
recipient = "{display_recipient} -> {subject}".format(**message)
neiljp marked this conversation as resolved.
Show resolved Hide resolved
if recipient:
if hidden_content:
text = content
Expand Down