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.

push_notifications: Return a common subtitle for wildcard mentions.

Prakhar Pratyush6dc3b1a05276
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py
index f4f1f5813d6..49f2269bad1 100644
--- a/zerver/lib/push_notifications.py
+++ b/zerver/lib/push_notifications.py
@@ -856,15 +856,12 @@ def get_apns_alert_subtitle(
)
else:
return _("{full_name} mentioned you:").format(full_name=message.sender.full_name)
- elif trigger == NotificationTriggers.TOPIC_WILDCARD_MENTION_IN_FOLLOWED_TOPIC:
- return _("TODO - 2")
- elif trigger == NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC:
- return _("TODO")
- elif trigger == NotificationTriggers.TOPIC_WILDCARD_MENTION:
- return _("{full_name} mentioned all topic participants:").format(
- full_name=message.sender.full_name
- )
- elif trigger == NotificationTriggers.STREAM_WILDCARD_MENTION:
+ elif trigger in (
+ NotificationTriggers.TOPIC_WILDCARD_MENTION_IN_FOLLOWED_TOPIC,
+ NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC,
+ NotificationTriggers.TOPIC_WILDCARD_MENTION,
+ NotificationTriggers.STREAM_WILDCARD_MENTION,
+ ):
return _("{full_name} mentioned everyone:").format(full_name=message.sender.full_name)
elif message.recipient.type == Recipient.PERSONAL:
return ""
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 7444bd8959c..952b7d7521b 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -2115,19 +2115,19 @@ class TestGetAPNsPayload(PushNotificationTest):
}
self.assertDictEqual(payload, expected)
- def test_get_message_payload_apns_topic_wildcard_mention_in_followed_topic(self) -> None:
+ def _test_get_message_payload_apns_wildcard_mention(self, trigger: str) -> None:
user_profile = self.example_user("othello")
stream = Stream.objects.filter(name="Verona").get()
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
payload = get_message_payload_apns(
user_profile,
message,
- NotificationTriggers.TOPIC_WILDCARD_MENTION_IN_FOLLOWED_TOPIC,
+ trigger,
)
expected = {
"alert": {
"title": "#Verona > Test topic",
- "subtitle": "TODO - 2",
+ "subtitle": "King Hamlet mentioned everyone:",
"body": message.content,
},
"sound": "default",
@@ -2150,104 +2150,25 @@ class TestGetAPNsPayload(PushNotificationTest):
}
self.assertDictEqual(payload, expected)
+ def test_get_message_payload_apns_topic_wildcard_mention_in_followed_topic(self) -> None:
+ self._test_get_message_payload_apns_wildcard_mention(
+ NotificationTriggers.TOPIC_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
+ )
+
def test_get_message_payload_apns_stream_wildcard_mention_in_followed_topic(self) -> None:
- user_profile = self.example_user("othello")
- stream = Stream.objects.filter(name="Verona").get()
- message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
- payload = get_message_payload_apns(
- user_profile, message, NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
+ self._test_get_message_payload_apns_wildcard_mention(
+ NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
)
- expected = {
- "alert": {
- "title": "#Verona > Test topic",
- "subtitle": "TODO",
- "body": message.content,
- },
- "sound": "default",
- "badge": 0,
- "custom": {
- "zulip": {
- "message_ids": [message.id],
- "recipient_type": "stream",
- "sender_email": self.sender.email,
- "sender_id": self.sender.id,
- "stream": stream.name,
- "stream_id": stream.id,
- "topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
- "realm_uri": self.sender.realm.uri,
- "user_id": user_profile.id,
- },
- },
- }
- self.assertDictEqual(payload, expected)
def test_get_message_payload_apns_topic_wildcard_mention(self) -> None:
- user_profile = self.example_user("othello")
- stream = Stream.objects.filter(name="Verona").get()
- message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
- payload = get_message_payload_apns(
- user_profile, message, NotificationTriggers.TOPIC_WILDCARD_MENTION
+ self._test_get_message_payload_apns_wildcard_mention(
+ NotificationTriggers.TOPIC_WILDCARD_MENTION
)
- expected = {
- "alert": {
- "title": "#Verona > Test topic",
- "subtitle": "King Hamlet mentioned all topic participants:",
- "body": message.content,
- },
- "sound": "default",
- "badge": 0,
- "custom": {
- "zulip": {
- "message_ids": [message.id],
- "recipient_type": "stream",
- "sender_email": self.sender.email,
- "sender_id": self.sender.id,
- "stream": stream.name,
- "stream_id": stream.id,
- "topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
- "realm_uri": self.sender.realm.uri,
- "user_id": user_profile.id,
- },
- },
- }
- self.assertDictEqual(payload, expected)
def test_get_message_payload_apns_stream_wildcard_mention(self) -> None:
- user_profile = self.example_user("othello")
- stream = Stream.objects.filter(name="Verona").get()
- message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
- payload = get_message_payload_apns(
- user_profile, message, NotificationTriggers.STREAM_WILDCARD_MENTION
+ self._test_get_message_payload_apns_wildcard_mention(
+ NotificationTriggers.STREAM_WILDCARD_MENTION
)
- expected = {
- "alert": {
- "title": "#Verona > Test topic",
- "subtitle": "King Hamlet mentioned everyone:",
- "body": message.content,
- },
- "sound": "default",
- "badge": 0,
- "custom": {
- "zulip": {
- "message_ids": [message.id],
- "recipient_type": "stream",
- "sender_email": self.sender.email,
- "sender_id": self.sender.id,
- "stream": stream.name,
- "stream_id": stream.id,
- "topic": message.topic_name(),
- "server": settings.EXTERNAL_HOST,
- "realm_id": self.sender.realm.id,
- "realm_uri": self.sender.realm.uri,
- "user_id": user_profile.id,
- },
- },
- }
- self.assertDictEqual(payload, expected)
@override_settings(PUSH_NOTIFICATION_REDACT_CONTENT=True)
def test_get_message_payload_apns_redacted_content(self) -> None: