Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

email_notifications: Highlight personal mentions in explanations.

khanhdq59d0f9b30136
diff --git a/templates/zerver/emails/missed_message.source.html b/templates/zerver/emails/missed_message.source.html
index 12fb27fe5ad..938bb3df7d9 100644
--- a/templates/zerver/emails/missed_message.source.html
+++ b/templates/zerver/emails/missed_message.source.html
@@ -25,14 +25,14 @@
{% block manage_preferences %}
<div class="email-preferences">
&mdash;<br />
- {% if mention %}
- {% if mentioned_user_group_name %}
- {% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned in {{ realm_name }}.{% endtrans %}<br />
- {% else %}
- {% trans %}You are receiving this because you were mentioned in {{ realm_name }}.{% endtrans %}<br />
- {% endif %}
+ {% if personal_mentioned %}
+ {% trans %}You are receiving this because you were personally mentioned.{% endtrans %}<br />
+ {% elif mentioned_user_group_name %}
+ {% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}<br />
+ {% elif wildcard_mentioned %}
+ {% trans %}You are receiving this because everyone was mentioned.{% endtrans %}<br />
{% elif stream_email_notify %}
- {% trans %}You are receiving this because you have email notifications enabled for this stream.{% endtrans %}<br />
+ {% trans %}You are receiving this because you have email notifications enabled for #{{ stream_name }}.{% endtrans %}<br />
{% endif %}
{% if reply_to_zulip %}
{% trans notif_url=realm_uri + "/#settings/notifications" %}Reply to this email directly, <a href="{{ narrow_url }}">view it in Zulip</a>, or <a href="{{ notif_url }}">manage email preferences</a>.{% endtrans %}
diff --git a/templates/zerver/emails/missed_message.txt b/templates/zerver/emails/missed_message.txt
index ccf6243f31e..861f090205c 100644
--- a/templates/zerver/emails/missed_message.txt
+++ b/templates/zerver/emails/missed_message.txt
@@ -21,14 +21,14 @@ See {{ alert_notif_url }} for more details.
{% endif %}
--
-{% if mention %}
-{% if mentioned_user_group_name %}
-{% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned in {{ realm_name }}.{% endtrans %}
-{% else %}
-{% trans %}You are receiving this because you were mentioned in {{ realm_name }}.{% endtrans %}
-{% endif %}
+{% if personal_mentioned %}
+{% trans %}You are receiving this because you were personally mentioned.{% endtrans %}
+{% elif mentioned_user_group_name %}
+{% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}
+{% elif wildcard_mentioned %}
+{% trans %}You are receiving this because everyone was mentioned.{% endtrans %}
{% elif stream_email_notify %}
-{% trans %}You are receiving this because you have email notifications enabled for this stream.{% endtrans %}
+{% trans %}You are receiving this because you have email notifications enabled for #{{ stream_name }}.{% endtrans %}
{% endif %}
{% if reply_to_zulip %}
diff --git a/zerver/lib/email_notifications.py b/zerver/lib/email_notifications.py
index 630d53837ea..a0e043ad23d 100644
--- a/zerver/lib/email_notifications.py
+++ b/zerver/lib/email_notifications.py
@@ -408,8 +408,15 @@ def do_send_missedmessage_events_reply_in_zulip(
triggers = [message["trigger"] for message in missed_messages]
unique_triggers = set(triggers)
+ personal_mentioned = any(
+ message["trigger"] == "mentioned" and message["mentioned_user_group_id"] is None
+ for message in missed_messages
+ )
+
context.update(
mention="mentioned" in unique_triggers or "wildcard_mentioned" in unique_triggers,
+ personal_mentioned=personal_mentioned,
+ wildcard_mentioned="wildcard_mentioned" in unique_triggers,
stream_email_notify="stream_email_notify" in unique_triggers,
mention_count=triggers.count("mentioned") + triggers.count("wildcard_mentioned"),
mentioned_user_group_name=mentioned_user_group_name,
@@ -476,6 +483,7 @@ def do_send_missedmessage_events_reply_in_zulip(
stream = Stream.objects.only("id", "name").get(id=message.recipient.type_id)
stream_header = f"{stream.name} > {message.topic_name()}"
context.update(
+ stream_name=stream.name,
stream_header=stream_header,
)
else:
diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.py
index 72b434447d8..e3e146452c8 100644
--- a/zerver/tests/test_email_notifications.py
+++ b/zerver/tests/test_email_notifications.py
@@ -518,7 +518,7 @@ class TestMissedMessages(ZulipTestCase):
if show_message_content:
verify_body_include = [
"Othello, the Moor of Venice: > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > @**King Hamlet** -- ",
- "You are receiving this because you were mentioned in Zulip Dev.",
+ "You are receiving this because you were personally mentioned.",
]
email_subject = "#Denmark > test"
verify_body_does_not_include: List[str] = []
@@ -561,7 +561,7 @@ class TestMissedMessages(ZulipTestCase):
if show_message_content:
verify_body_include = [
"Othello, the Moor of Venice: > 1 > 2 > 3 > 4 > 5 > @**all** -- ",
- "You are receiving this because you were mentioned in Zulip Dev.",
+ "You are receiving this because everyone was mentioned.",
]
email_subject = "#Denmark > test"
verify_body_does_not_include: List[str] = []
@@ -599,7 +599,7 @@ class TestMissedMessages(ZulipTestCase):
msg_id = self.send_stream_message(self.example_user("othello"), "denmark", "12")
verify_body_include = [
"Othello, the Moor of Venice: > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 12 -- ",
- "You are receiving this because you have email notifications enabled for this stream.",
+ "You are receiving this because you have email notifications enabled for #Denmark.",
]
email_subject = "#Denmark > test"
self._test_cases(
@@ -619,7 +619,7 @@ class TestMissedMessages(ZulipTestCase):
)
verify_body_include = [
"Cordelia, Lear's daughter: > 0 > 1 > 2 Othello, the Moor of Venice: > @**King Hamlet** -- ",
- "You are receiving this because you were mentioned in Zulip Dev.",
+ "You are receiving this because you were personally mentioned.",
]
email_subject = "#Denmark > test"
self._test_cases(
@@ -849,7 +849,7 @@ class TestMissedMessages(ZulipTestCase):
expected_email_include = [
"Othello, the Moor of Venice: > @*hamlet_only* > @*hamlet_and_cordelia* -- ",
- "You are receiving this because @hamlet_only was mentioned in Zulip Dev.",
+ "You are receiving this because @hamlet_only was mentioned.",
]
for text in expected_email_include:
@@ -889,7 +889,76 @@ class TestMissedMessages(ZulipTestCase):
expected_email_include = [
"Othello, the Moor of Venice: > @*hamlet_and_cordelia* > @**King Hamlet** -- ",
- "You are receiving this because you were mentioned in Zulip Dev.",
+ "You are receiving this because you were personally mentioned.",
+ ]
+
+ for text in expected_email_include:
+ self.assertIn(text, self.normalize_string(mail.outbox[0].body))
+
+ def test_user_group_over_wildcard_mention_priority(self) -> None:
+ hamlet = self.example_user("hamlet")
+ cordelia = self.example_user("cordelia")
+ othello = self.example_user("othello")
+
+ hamlet_and_cordelia = create_user_group(
+ "hamlet_and_cordelia", [hamlet, cordelia], get_realm("zulip")
+ )
+
+ wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**")
+ user_group_mentioned_message_id = self.send_stream_message(
+ othello, "Denmark", "@*hamlet_and_cordelia*"
+ )
+
+ handle_missedmessage_emails(
+ hamlet.id,
+ [
+ {
+ "message_id": wildcard_mentioned_message_id,
+ "trigger": "wildcard_mentioned",
+ "mentioned_user_group_id": None,
+ },
+ {
+ "message_id": user_group_mentioned_message_id,
+ "trigger": "mentioned",
+ "mentioned_user_group_id": hamlet_and_cordelia.id,
+ },
+ ],
+ )
+
+ expected_email_include = [
+ "Othello, the Moor of Venice: > @**all** > @*hamlet_and_cordelia* -- ",
+ "You are receiving this because @hamlet_and_cordelia was mentioned.",
+ ]
+
+ for text in expected_email_include:
+ self.assertIn(text, self.normalize_string(mail.outbox[0].body))
+
+ def test_wildcard_over_stream_mention_priority(self) -> None:
+ hamlet = self.example_user("hamlet")
+ othello = self.example_user("othello")
+
+ stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", "1")
+ wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**")
+
+ handle_missedmessage_emails(
+ hamlet.id,
+ [
+ {
+ "message_id": stream_mentioned_message_id,
+ "trigger": "stream_email_notify",
+ "mentioned_user_group_id": None,
+ },
+ {
+ "message_id": wildcard_mentioned_message_id,
+ "trigger": "wildcard_mentioned",
+ "mentioned_user_group_id": None,
+ },
+ ],
+ )
+
+ expected_email_include = [
+ "Othello, the Moor of Venice: > 1 > @**all** -- ",
+ "You are receiving this because everyone was mentioned.",
]
for text in expected_email_include: