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.

stream notifications: Add helper for silent user mention syntax.

Eeshan Garg3714a30e63a5
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index dece5511ca5..6adb94bf24a 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -100,7 +100,7 @@ from zerver.lib.hotspots import get_next_hotspots
from zerver.lib.i18n import get_language_name
from zerver.lib.markdown import MessageRenderingResult, topic_links
from zerver.lib.markdown import version as markdown_version
-from zerver.lib.mention import MentionData
+from zerver.lib.mention import MentionData, silent_mention_syntax_for_user
from zerver.lib.message import (
MessageDict,
SendMessageRequest,
@@ -376,7 +376,7 @@ def notify_new_user(user_profile: UserProfile) -> None:
is_first_user = user_count == 1
if not is_first_user:
message = _("{user} just signed up for Zulip. (total: {user_count})").format(
- user=f"@_**{user_profile.full_name}|{user_profile.id}**", user_count=user_count
+ user=silent_mention_syntax_for_user(user_profile), user_count=user_count
)
if settings.BILLING_ENABLED:
@@ -4989,7 +4989,7 @@ def do_rename_stream(stream: Stream, new_name: str, user_profile: UserProfile) -
stream,
Realm.STREAM_EVENTS_NOTIFICATION_TOPIC,
_("{user_name} renamed stream {old_stream_name} to {new_stream_name}.").format(
- user_name=f"@_**{user_profile.full_name}|{user_profile.id}**",
+ user_name=silent_mention_syntax_for_user(user_profile),
old_stream_name=f"**{old_name}**",
new_stream_name=f"**{new_name}**",
),
@@ -5020,7 +5020,7 @@ def send_change_stream_message_retention_days_notification(
user_profile: UserProfile, stream: Stream, old_value: Optional[int], new_value: Optional[int]
) -> None:
sender = get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id)
- user_mention = f"@_**{user_profile.full_name}|{user_profile.id}**"
+ user_mention = silent_mention_syntax_for_user(user_profile)
# If switching from or to the organization's default retention policy,
# we want to take the realm's default into account.
@@ -6048,7 +6048,7 @@ def maybe_send_resolve_topic_notifications(
return
sender = get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id)
- user_mention = f"@_**{user_profile.full_name}|{user_profile.id}**"
+ user_mention = silent_mention_syntax_for_user(user_profile)
with override_language(stream.realm.default_language):
if topic_resolved:
notification_string = _("{user} has marked this topic as resolved.")
@@ -6082,7 +6082,7 @@ def send_message_moved_breadcrumbs(
if new_topic is None:
new_topic = old_topic
- user_mention = f"@_**{user_profile.full_name}|{user_profile.id}**"
+ user_mention = silent_mention_syntax_for_user(user_profile)
old_topic_link = f"#**{old_stream.name}>{old_topic}**"
new_topic_link = f"#**{new_stream.name}>{new_topic}**"
diff --git a/zerver/lib/mention.py b/zerver/lib/mention.py
index b85b6d0f336..a4e3eef4f54 100644
--- a/zerver/lib/mention.py
+++ b/zerver/lib/mention.py
@@ -152,3 +152,7 @@ def get_stream_name_info(realm: Realm, stream_names: Set[str]) -> Dict[str, Full
dct = {row["name"]: row for row in rows}
return dct
+
+
+def silent_mention_syntax_for_user(user_profile: UserProfile) -> str:
+ return f"@_**{user_profile.full_name}|{user_profile.id}**"
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index aa6fa73f94a..3da57633f7d 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -50,6 +50,7 @@ from zerver.lib.exceptions import (
OrganizationOwnerRequired,
ResourceNotFoundError,
)
+from zerver.lib.mention import silent_mention_syntax_for_user
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.retention import parse_message_retention_days
@@ -649,7 +650,7 @@ def send_messages_for_new_subscribers(
topic = _("new streams")
content = content.format(
- user_name=f"@_**{user_profile.full_name}|{user_profile.id}**",
+ user_name=silent_mention_syntax_for_user(user_profile),
stream_str=", ".join(f"#**{s.name}**" for s in created_streams),
)
@@ -674,7 +675,7 @@ def send_messages_for_new_subscribers(
stream=stream,
topic=Realm.STREAM_EVENTS_NOTIFICATION_TOPIC,
content=_("Stream created by {user_name}.").format(
- user_name=f"@_**{user_profile.full_name}|{user_profile.id}**",
+ user_name=silent_mention_syntax_for_user(user_profile),
),
),
)