mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
streams.py: replace stream_subscribe_button with new #stream syntax.
Previously, we included a special subscribe button in new stream notifications, but that had 2 problems: (1) The subscribe button would render badly if the stream was renamed. (2) There wasn't an easy way to look at the stream when deciding whether to subscribe. This fixes the second problem, but not really the first.
This commit is contained in:
@@ -1242,10 +1242,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
self.assertEqual(msg.recipient.type, Recipient.PERSONAL)
|
||||
self.assertEqual(msg.sender_id,
|
||||
get_user_profile_by_email('notification-bot@zulip.com').id)
|
||||
expected_msg = "Hi there! %s just created a new stream '%s'. " \
|
||||
"!_stream_subscribe_button(%s)" % (invitee_full_name,
|
||||
invite_streams[0],
|
||||
invite_streams[0])
|
||||
expected_msg = "Hi there! %s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0])
|
||||
self.assertEqual(msg.content, expected_msg)
|
||||
|
||||
def test_successful_subscriptions_notifies_stream(self):
|
||||
@@ -1281,10 +1278,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
self.assertEqual(msg.recipient.type, Recipient.STREAM)
|
||||
self.assertEqual(msg.sender_id,
|
||||
get_user_profile_by_email('notification-bot@zulip.com').id)
|
||||
expected_msg = "%s just created a new stream `%s`. " \
|
||||
"!_stream_subscribe_button(%s)" % (invitee_full_name,
|
||||
invite_streams[0],
|
||||
invite_streams[0])
|
||||
expected_msg = "%s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0])
|
||||
self.assertEqual(msg.content, expected_msg)
|
||||
|
||||
def test_successful_subscriptions_notifies_with_escaping(self):
|
||||
@@ -1314,10 +1308,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
msg = self.get_last_message()
|
||||
self.assertEqual(msg.sender_id,
|
||||
get_user_profile_by_email('notification-bot@zulip.com').id)
|
||||
expected_msg = "%s just created a new stream `%s`. " \
|
||||
"!_stream_subscribe_button(strange \\) \\\\ test)" % (
|
||||
invitee_full_name,
|
||||
invite_streams[0])
|
||||
expected_msg = "%s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0])
|
||||
self.assertEqual(msg.content, expected_msg)
|
||||
|
||||
def test_non_ascii_stream_subscription(self):
|
||||
@@ -1392,10 +1383,10 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
self.assertEqual(msg.sender_id,
|
||||
get_user_profile_by_email("notification-bot@zulip.com").id)
|
||||
expected_msg = ("Hi there! We thought you'd like to know that %s just "
|
||||
"subscribed you to the %sstream [%s](#narrow/stream/%s)."
|
||||
"subscribed you to the %sstream #**%s**."
|
||||
% (self.user_profile.full_name,
|
||||
'**invite-only** ' if invite_only else '',
|
||||
streams[0], urllib.parse.quote(streams[0].encode('utf-8'))))
|
||||
streams[0]))
|
||||
|
||||
if not Stream.objects.get(name=streams[0]).invite_only:
|
||||
expected_msg += ("\nYou can see historical content on a "
|
||||
|
||||
@@ -299,17 +299,6 @@ def filter_stream_authorization(user_profile, streams):
|
||||
stream.id not in set(stream.id for stream in unauthorized_streams)]
|
||||
return authorized_streams, unauthorized_streams
|
||||
|
||||
def stream_link(stream_name):
|
||||
# type: (text_type) -> text_type
|
||||
"Escapes a stream name to make a #narrow/stream/stream_name link"
|
||||
return u"#narrow/stream/%s" % (urllib.parse.quote(stream_name.encode('utf-8')),)
|
||||
|
||||
def stream_button(stream_name):
|
||||
# type: (text_type) -> text_type
|
||||
stream_name = stream_name.replace('\\', '\\\\')
|
||||
stream_name = stream_name.replace(')', '\\)')
|
||||
return '!_stream_subscribe_button(%s)' % (stream_name,)
|
||||
|
||||
@has_request_variables
|
||||
def add_subscriptions_backend(request, user_profile,
|
||||
streams_raw = REQ("subscriptions",
|
||||
@@ -373,20 +362,18 @@ def add_subscriptions_backend(request, user_profile,
|
||||
|
||||
if len(subscriptions) == 1:
|
||||
msg = ("Hi there! We thought you'd like to know that %s just "
|
||||
"subscribed you to the%s stream [%s](%s)."
|
||||
"subscribed you to the%s stream #**%s**."
|
||||
% (user_profile.full_name,
|
||||
" **invite-only**" if private_streams[subscriptions[0]] else "",
|
||||
subscriptions[0],
|
||||
stream_link(subscriptions[0]),
|
||||
))
|
||||
else:
|
||||
msg = ("Hi there! We thought you'd like to know that %s just "
|
||||
"subscribed you to the following streams: \n\n"
|
||||
% (user_profile.full_name,))
|
||||
for stream in subscriptions:
|
||||
msg += "* [%s](%s)%s\n" % (
|
||||
msg += "* #**%s**%s\n" % (
|
||||
stream,
|
||||
stream_link(stream),
|
||||
" (**invite-only**)" if private_streams[stream] else "")
|
||||
|
||||
if len([s for s in subscriptions if not private_streams[s]]) > 0:
|
||||
@@ -398,22 +385,18 @@ def add_subscriptions_backend(request, user_profile,
|
||||
notifications_stream = user_profile.realm.notifications_stream
|
||||
if notifications_stream is not None:
|
||||
if len(created_streams) > 1:
|
||||
stream_msg = "the following streams: %s" % \
|
||||
(", ".join('`%s`' % (s.name,) for s in created_streams),)
|
||||
stream_msg = "the following streams: %s" % (", ".join('#**%s**' % s.name for s in created_streams))
|
||||
else:
|
||||
stream_msg = "a new stream `%s`" % (created_streams[0].name)
|
||||
|
||||
stream_buttons = ' '.join(stream_button(s.name) for s in created_streams)
|
||||
msg = ("%s just created %s. %s" % (user_profile.full_name,
|
||||
stream_msg, stream_buttons))
|
||||
stream_msg = "a new stream #**%s**." % created_streams[0].name
|
||||
msg = ("%s just created %s" % (user_profile.full_name, stream_msg))
|
||||
notifications.append(
|
||||
internal_prep_message(settings.NOTIFICATION_BOT,
|
||||
"stream",
|
||||
notifications_stream.name, "Streams", msg,
|
||||
realm=notifications_stream.realm))
|
||||
else:
|
||||
msg = ("Hi there! %s just created a new stream '%s'. %s"
|
||||
% (user_profile.full_name, created_streams[0].name, stream_button(created_streams[0].name)))
|
||||
msg = ("Hi there! %s just created a new stream #**%s**."
|
||||
% (user_profile.full_name, created_streams[0].name))
|
||||
for realm_user_dict in get_active_user_dicts_in_realm(user_profile.realm):
|
||||
# Don't announce to yourself or to people you explicitly added
|
||||
# (who will get the notification above instead).
|
||||
|
||||
Reference in New Issue
Block a user