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: Go to the DB for streams.

Steve Howell1b7880fc2150
diff --git a/zerver/lib/display_recipient.py b/zerver/lib/display_recipient.py
index bfec6c2825f..ed8367b465c 100644
--- a/zerver/lib/display_recipient.py
+++ b/zerver/lib/display_recipient.py
@@ -40,7 +40,7 @@ def get_display_recipient_remote_cache(
stream this will be the stream name as a string. For a huddle or
personal, it will be an array of dicts about each recipient.
"""
- if recipient_type == Recipient.STREAM:
+ if recipient_type == Recipient.STREAM: # nocoverage
assert recipient_type_id is not None
stream = Stream.objects.values("name").get(id=recipient_type_id)
return stream["name"]
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py
index a660d71d2fe..6375decd9f3 100644
--- a/zerver/lib/push_notifications.py
+++ b/zerver/lib/push_notifications.py
@@ -33,6 +33,7 @@ from zerver.models import (
NotificationTriggers,
PushDeviceToken,
Recipient,
+ Stream,
UserGroup,
UserMessage,
UserProfile,
@@ -60,6 +61,16 @@ def hex_to_b64(data: str) -> str:
return base64.b64encode(bytes.fromhex(data)).decode()
+def get_message_stream_name_from_database(message: Message) -> str:
+ """
+ Never use this function outside of the push-notifications
+ codepath. Most of our code knows how to get streams
+ up front in a more efficient manner.
+ """
+ stream_id = message.recipient.type_id
+ return Stream.objects.get(id=stream_id).name
+
+
class UserPushIdentityCompat:
"""Compatibility class for supporting the transition from remote servers
sending their UserProfile ids to the bouncer to sending UserProfile uuids instead.
@@ -669,7 +680,7 @@ def get_gcm_alert(
return f"New direct message from {sender_str}"
assert message.is_stream_message()
- stream_name = get_display_recipient(message.recipient)
+ stream_name = get_message_stream_name_from_database(message)
if trigger == NotificationTriggers.MENTION:
if mentioned_user_group_name is None:
@@ -805,7 +816,7 @@ def get_message_payload(
if message.recipient.type == Recipient.STREAM:
data["recipient_type"] = "stream"
- data["stream"] = get_display_recipient(message.recipient)
+ data["stream"] = get_message_stream_name_from_database(message)
data["stream_id"] = message.recipient.type_id
data["topic"] = message.topic_name()
elif message.recipient.type == Recipient.HUDDLE:
@@ -826,7 +837,8 @@ def get_apns_alert_title(message: Message) -> str:
assert isinstance(recipients, list)
return ", ".join(sorted(r["full_name"] for r in recipients))
elif message.is_stream_message():
- return f"#{get_display_recipient(message.recipient)} > {message.topic_name()}"
+ stream_name = get_message_stream_name_from_database(message)
+ return f"#{stream_name} > {message.topic_name()}"
# For 1:1 direct messages, we just show the sender name.
return message.sender.full_name