android notifications: Differentiate personal vs wildcard mentions.

The code to also notify for wildcard mentions was added in
0ed0bb6828.

But that showed the same text for both the cases. This commit fixes
that.

This is more of change for correctness. The mobile app currently does
not rely on this text for notifications, but constructs the text by
itself from the data in the payload.

This also fixes the "stream_push_notify" case to consistently show
a `#` before the stream name.
This commit is contained in:
Abhijeet Prasad Bodas 2021-07-08 16:41:52 +05:30 committed by Tim Abbott
parent ce6f6a3829
commit 4d24499317
2 changed files with 22 additions and 11 deletions

View File

@ -554,17 +554,18 @@ def get_gcm_alert(message: Message) -> str:
Determine what alert string to display based on the missed messages.
"""
sender_str = message.sender.full_name
display_recipient = get_display_recipient(message.recipient)
if message.recipient.type == Recipient.HUDDLE and message.trigger == "private_message":
return f"New private group message from {sender_str}"
elif message.recipient.type == Recipient.PERSONAL and message.trigger == "private_message":
return f"New private message from {sender_str}"
elif message.is_stream_message() and (
message.trigger == "mentioned" or message.trigger == "wildcard_mentioned"
):
return f"New mention from {sender_str}"
elif message.is_stream_message() and message.trigger == "mentioned":
return f"{sender_str} mentioned you in #{display_recipient}"
elif message.is_stream_message() and message.trigger == "wildcard_mentioned":
return f"{sender_str} mentioned everyone in #{display_recipient}"
else:
assert message.is_stream_message() and message.trigger == "stream_push_notify"
return f"New stream message from {sender_str} in {get_display_recipient(message.recipient)}"
return f"New stream message from {sender_str} in #{display_recipient}"
def get_mobile_push_content(rendered_content: str) -> str:

View File

@ -1740,13 +1740,13 @@ class TestGetAPNsPayload(PushNotificationTest):
class TestGetGCMPayload(PushNotificationTest):
def test_get_message_payload_gcm(self) -> None:
def _test_get_message_payload_gcm_mentions(self, trigger: str, alert: str) -> None:
stream = Stream.objects.filter(name="Verona").get()
message = self.get_message(Recipient.STREAM, stream.id)
message.content = "a" * 210
message.rendered_content = "a" * 210
message.save()
message.trigger = "mentioned"
message.trigger = trigger
hamlet = self.example_user("hamlet")
payload, gcm_options = get_message_payload_gcm(hamlet, message)
@ -1755,7 +1755,7 @@ class TestGetGCMPayload(PushNotificationTest):
{
"user_id": hamlet.id,
"event": "message",
"alert": "New mention from King Hamlet",
"alert": alert,
"zulip_message_id": message.id,
"time": datetime_to_timestamp(message.date_sent),
"content": "a" * 200 + "",
@ -1779,7 +1779,17 @@ class TestGetGCMPayload(PushNotificationTest):
},
)
def test_get_message_payload_gcm_personal(self) -> None:
def test_get_message_payload_gcm_personal_mention(self) -> None:
self._test_get_message_payload_gcm_mentions(
"mentioned", "King Hamlet mentioned you in #Verona"
)
def test_get_message_payload_gcm_wildcard_mention(self) -> None:
self._test_get_message_payload_gcm_mentions(
"wildcard_mentioned", "King Hamlet mentioned everyone in #Verona"
)
def test_get_message_payload_gcm_private_message(self) -> None:
message = self.get_message(Recipient.PERSONAL, 1)
message.trigger = "private_message"
hamlet = self.example_user("hamlet")
@ -1823,7 +1833,7 @@ class TestGetGCMPayload(PushNotificationTest):
{
"user_id": hamlet.id,
"event": "message",
"alert": "New stream message from King Hamlet in Denmark",
"alert": "New stream message from King Hamlet in #Denmark",
"zulip_message_id": message.id,
"time": datetime_to_timestamp(message.date_sent),
"content": message.content,
@ -1860,7 +1870,7 @@ class TestGetGCMPayload(PushNotificationTest):
{
"user_id": hamlet.id,
"event": "message",
"alert": "New stream message from King Hamlet in Denmark",
"alert": "New stream message from King Hamlet in #Denmark",
"zulip_message_id": message.id,
"time": datetime_to_timestamp(message.date_sent),
"content": "*This organization has disabled including message content in mobile push notifications*",