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.

streams: Add function to get topic for channel events notifications.

Vector737afed92c00e0
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index 8a521dc56fb..73a98762369 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -38,6 +38,7 @@ from zerver.lib.stream_subscription import (
from zerver.lib.stream_traffic import get_streams_traffic
from zerver.lib.streams import (
can_access_stream_metadata_user_ids,
+ channel_events_topic_name,
check_basic_stream_access,
get_anonymous_group_membership_dict_for_streams,
get_stream_permission_policy_key,
@@ -190,7 +191,7 @@ def do_deactivate_stream(stream: Stream, *, acting_user: UserProfile | None) ->
internal_send_stream_message(
sender,
stream,
- topic_name=str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ topic_name=channel_events_topic_name(stream),
content=_("Channel #**{channel_name}** has been archived.").format(
channel_name=stream.name
),
@@ -314,7 +315,7 @@ def do_unarchive_stream(stream: Stream, new_name: str, *, acting_user: UserProfi
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
_("Channel #**{channel_name}** has been unarchived.").format(channel_name=new_name),
)
@@ -1247,7 +1248,7 @@ def send_change_stream_permission_notification(
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
notification_string,
archived_channel_notice=stream.deactivated,
)
@@ -1481,7 +1482,7 @@ def send_stream_posting_permission_update_notification(
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
notification_string,
archived_channel_notice=stream.deactivated,
)
@@ -1536,7 +1537,7 @@ def do_rename_stream(stream: Stream, new_name: str, user_profile: UserProfile) -
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
_("{user_name} renamed channel {old_channel_name} to {new_channel_name}.").format(
user_name=silent_mention_syntax_for_user(user_profile),
old_channel_name=f"**{old_name}**",
@@ -1573,7 +1574,7 @@ def send_change_stream_description_notification(
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
notification_string,
archived_channel_notice=stream.deactivated,
)
@@ -1667,7 +1668,7 @@ def send_change_stream_message_retention_days_notification(
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
notification_string,
archived_channel_notice=stream.deactivated,
)
@@ -1772,7 +1773,7 @@ def do_set_stream_property(stream: Stream, name: str, value: Any, acting_user: U
internal_send_stream_message(
sender,
stream,
- str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ channel_events_topic_name(stream),
NOTIFICATION_MESSAGES[name],
)
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index ee7727cf86d..82df3cf4a6a 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -263,6 +263,10 @@ def get_user_ids_with_metadata_access_via_permission_groups(stream: Stream) -> s
return users_with_metadata_access_dict[stream.id]
+def channel_events_topic_name(stream: Stream) -> str:
+ return str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME)
+
+
@transaction.atomic(savepoint=False)
def create_stream_if_needed(
realm: Realm,
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index fbce0c4fd54..c934daf6d63 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -73,6 +73,7 @@ from zerver.lib.streams import (
access_stream_by_name,
access_stream_for_delete_or_update_requiring_metadata_access,
access_web_public_stream,
+ channel_events_topic_name,
check_stream_name_available,
do_get_streams,
filter_stream_authorization_for_adding_subscribers,
@@ -108,7 +109,7 @@ from zerver.lib.user_groups import (
from zerver.lib.user_topics import get_users_with_user_topic_visibility_policy
from zerver.lib.users import access_bot_by_id, bulk_access_users_by_email, bulk_access_users_by_id
from zerver.lib.utils import assert_is_not_none
-from zerver.models import ChannelFolder, Realm, Stream, UserMessage, UserProfile, UserTopic
+from zerver.models import ChannelFolder, Stream, UserMessage, UserProfile, UserTopic
from zerver.models.groups import SystemGroups
from zerver.models.streams import StreamTopicsPolicyEnum
from zerver.models.users import get_system_bot
@@ -1001,7 +1002,7 @@ def send_messages_for_new_subscribers(
internal_prep_stream_message(
sender=sender,
stream=stream,
- topic_name=str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
+ topic_name=channel_events_topic_name(stream),
content=new_channel_message.format(
user_name=silent_mention_syntax_for_user(user_profile),
)