Skip to content

Commit 9d53f9e

Browse files
model/test_model: Notify user of alert-word.
In the notify_user function a condition of "has_alert_word" is added which also checks if stream/topic is muted(unlike mentions,wild-card_mentions). Changed the existing test function test_notify_users_calling_msg_type. Added the case for notificaiton for all private messages. Apart from that added two parameters is_topic_muted and is_stream_muted.
1 parent 3081df9 commit 9d53f9e

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

tests/model/test_model.py

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,25 +1978,72 @@ def test__update_topic_index(
19781978
"vary_each_msg",
19791979
"visual_notification_status",
19801980
"types_when_notify_called",
1981+
"is_muted_stream",
1982+
"is_muted_topic",
19811983
],
19821984
[
19831985
(
19841986
5140,
19851987
{"flags": ["mentioned", "wildcard_mentioned"]},
19861988
True,
19871989
[],
1990+
None,
1991+
None,
19881992
), # message_fixture sender_id is 5140
1989-
(5179, {"flags": ["mentioned"]}, False, ["stream", "private"]),
1990-
(5179, {"flags": ["wildcard_mentioned"]}, False, ["stream", "private"]),
1991-
(5179, {"flags": []}, True, ["stream", "private"]),
1992-
(5179, {"flags": []}, False, ["private"]),
1993+
(5179, {"flags": ["mentioned"]}, False, ["stream", "private"], None, None),
1994+
(
1995+
5179,
1996+
{"flags": ["wildcard_mentioned"]},
1997+
False,
1998+
["stream", "private"],
1999+
None,
2000+
None,
2001+
),
2002+
(5179, {"flags": []}, True, ["stream", "private"], None, None),
2003+
(5179, {"flags": []}, False, ["private"], None, None),
2004+
(
2005+
5179,
2006+
{"flags": ["has_alert_word"]},
2007+
False,
2008+
["stream", "private"],
2009+
True,
2010+
True,
2011+
),
2012+
(
2013+
5179,
2014+
{"flags": ["has_alert_word"]},
2015+
False,
2016+
["stream", "private"],
2017+
True,
2018+
False,
2019+
),
2020+
(
2021+
5179,
2022+
{"flags": ["has_alert_word"]},
2023+
False,
2024+
["stream", "private"],
2025+
False,
2026+
True,
2027+
),
2028+
(
2029+
5179,
2030+
{"flags": ["has_alert_word"]},
2031+
False,
2032+
["stream", "private"],
2033+
False,
2034+
False,
2035+
),
19932036
],
19942037
ids=[
19952038
"not_notified_since_self_message",
19962039
"notified_stream_and_private_since_directly_mentioned",
19972040
"notified_stream_and_private_since_wildcard_mentioned",
19982041
"notified_stream_since_stream_has_desktop_notifications",
19992042
"notified_private_since_private_message",
2043+
"not_notified_for_stream_since_topic/stream_both_muted",
2044+
"not_notified_for_stream_since_stream_muted",
2045+
"not_notified_for_stream_since_topic_muted",
2046+
"notified_for_stream_since_topic/stream_both_not_muted",
20002047
],
20012048
)
20022049
def test_notify_users_calling_msg_type(
@@ -2008,13 +2055,17 @@ def test_notify_users_calling_msg_type(
20082055
vary_each_msg,
20092056
visual_notification_status,
20102057
types_when_notify_called,
2058+
is_muted_stream: Optional[bool],
2059+
is_muted_topic: Optional[bool],
20112060
):
20122061
message_fixture.update(vary_each_msg)
20132062
model.user_id = user_id
20142063
mocker.patch(
20152064
MODEL + ".is_visual_notifications_enabled",
20162065
return_value=visual_notification_status,
20172066
)
2067+
mocker.patch.object(model, "is_muted_stream", return_value=is_muted_stream)
2068+
mocker.patch.object(model, "is_muted_topic", return_value=is_muted_topic)
20182069
notify = mocker.patch(MODULE + ".notify")
20192070

20202071
model.notify_user(message_fixture)
@@ -2031,7 +2082,17 @@ def test_notify_users_calling_msg_type(
20312082
if target is not None:
20322083
title = f"Test Organization Name:\nFoo Foo (to {target})"
20332084
# TODO: Test message content too?
2034-
notify.assert_called_once_with(title, mocker.ANY)
2085+
if message_fixture["type"] == "private":
2086+
notify.assert_called_once_with(title, mocker.ANY)
2087+
elif len(
2088+
vary_each_msg["flags"]
2089+
) == 1 and "has_alert_word" in vary_each_msg.get("flags"):
2090+
if not is_muted_topic and not is_muted_stream:
2091+
notify.assert_called_once_with(title, mocker.ANY)
2092+
else:
2093+
notify.assert_not_called()
2094+
else:
2095+
notify.assert_called_once_with(title, mocker.ANY)
20352096
else:
20362097
notify.assert_not_called()
20372098

zulipterminal/model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,13 @@ def notify_user(self, message: Message) -> str:
15171517
) or self.is_visual_notifications_enabled(stream_id):
15181518
recipient = "{display_recipient} -> {subject}".format(**message)
15191519

1520+
if "has_alert_word" in message["flags"]:
1521+
# Check if stream or topic is muted
1522+
topic = message.get("subject", "")
1523+
if not self.is_muted_stream(stream_id) and not self.is_muted_topic(
1524+
stream_id, topic
1525+
):
1526+
recipient = "{display_recipient} -> {subject}".format(**message)
15201527
if recipient:
15211528
if hidden_content:
15221529
text = content

0 commit comments

Comments
 (0)