Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
add_subscriptions: Only exclude DMs and not new channel notifications.
Kislay Verma18d9b686b737
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex f58c38ecb34..176dcc0c2c2 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -5147,8 +5147,11 @@ class SubscriptionAPITest(ZulipTestCase):recipient__type_id=announce.id,date_sent__gt=now,)- # Currently, this notification is not sent even though it should be.- self.assertEqual(announcement_channel_message.count(), 0)+ self.assertEqual(announcement_channel_message.count(), 1)+ self.assertEqual(+ announcement_channel_message[0].content,+ f"@_**{desdemona.full_name}|{desdemona.id}** created a new channel #**test D**.",+ )new_channel = get_stream("test D", realm)new_channel_message = Message.objects.filter(@@ -5158,8 +5161,15 @@ class SubscriptionAPITest(ZulipTestCase):recipient__type_id=new_channel.id,date_sent__gt=now,)- # Currently, this notification is not sent even though it should be.- self.assert_length(new_channel_message.values(), 0)+ self.assert_length(new_channel_message.values(), 1)+ self.assertEqual(+ new_channel_message[0].topic_name(), Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME+ )+ self.assertEqual(+ new_channel_message[0].content,+ f"**Public** channel created by @_**{desdemona.full_name}|{desdemona.id}**. **Description:**\n"+ "```` quote\n*No description.*\n````",+ )class InviteOnlyStreamTest(ZulipTestCase):diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex 7f36833a6ad..70be4fd3b8b 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -1013,18 +1013,21 @@ def add_subscriptions_backend(result["already_subscribed"] = dict(result["already_subscribed"])if send_new_subscription_messages:- if len(result["subscribed"]) <= settings.MAX_BULK_NEW_SUBSCRIPTION_MESSAGES:- send_user_subscribed_and_new_channel_notifications(- user_profile=user_profile,- subscribers=subscribers,- new_subscriptions=result["subscribed"],- id_to_user_profile=id_to_user_profile,- created_streams=created_streams,- announce=announce,- )- result["new_subscription_messages_sent"] = True- else:- result["new_subscription_messages_sent"] = False+ send_user_subscribed_direct_messages = (+ len(result["subscribed"]) <= settings.MAX_BULK_NEW_SUBSCRIPTION_MESSAGES+ )+ result["new_subscription_messages_sent"] = send_user_subscribed_direct_messages+ else:+ send_user_subscribed_direct_messages = False+ send_user_subscribed_and_new_channel_notifications(+ user_profile=user_profile,+ subscribers=subscribers,+ new_subscriptions=result["subscribed"],+ id_to_user_profile=id_to_user_profile,+ created_streams=created_streams,+ announce=announce,+ send_user_subscribed_direct_messages=send_user_subscribed_direct_messages,+ )result["subscribed"] = dict(result["subscribed"])result["already_subscribed"] = dict(result["already_subscribed"])@@ -1040,6 +1043,7 @@ def send_user_subscribed_and_new_channel_notifications(id_to_user_profile: dict[str, UserProfile],created_streams: list[Stream],announce: bool,+ send_user_subscribed_direct_messages: bool = True,) -> None:"""If a user is subscribing lots of other users to existing channels,@@ -1051,7 +1055,7 @@ def send_user_subscribed_and_new_channel_notifications("""notifications = []# Inform users if someone else subscribed them to an existing channel.- if new_subscriptions:+ if new_subscriptions and send_user_subscribed_direct_messages:bots = {str(subscriber.id): subscriber.is_bot for subscriber in subscribers}newly_created_stream_names = {s.name for s in created_streams}