Link to streams in notification bot messages.

It's a little weird that these still open in a new tab, but it might
be best to keep them consistent with all other links?

This is a first pass on Trac #1927.

(imported from commit 390bdef790a83af4240ad5f5a82e572ef5824756)
This commit is contained in:
Kevin Mehall 2013-11-25 10:18:09 -05:00
parent 14ae79b311
commit ca182ec062
2 changed files with 22 additions and 9 deletions

View File

@ -1489,10 +1489,10 @@ class SubscriptionAPITest(AuthedTestCase):
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'"
"subscribed you to the %sstream [%s](#narrow/stream/%s)."
% (self.user_profile.full_name,
'**invite-only** ' if invite_only else '',
streams[0]))
streams[0], urllib.quote(streams[0].encode('utf-8'))))
if not Stream.objects.get(name=streams[0]).invite_only:
expected_msg += ("\nYou can see historical content on a "

View File

@ -1611,6 +1611,10 @@ def filter_stream_authorization(user_profile, streams):
stream.id not in set(stream.id for stream in unauthorized_streams)]
return streams, unauthorized_streams
def stream_link(stream_name):
"Escapes a stream name to make a #narrow/stream/stream_name link"
return "#narrow/stream/%s" % (urllib.quote(stream_name.encode('utf-8')),)
@has_request_variables
def add_subscriptions_backend(request, user_profile,
streams_raw = REQ("subscriptions", json_to_list),
@ -1671,17 +1675,20 @@ 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'"
"subscribed you to the%s stream [%s](%s)."
% (user_profile.full_name,
" **invite-only**" if private_streams[subscriptions[0]] else "",
subscriptions[0]))
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\n" % (
msg += "* [%s](%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:
@ -1694,11 +1701,17 @@ def add_subscriptions_backend(request, user_profile,
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),)
(", ".join('[%s](%s)' % (
s.name,
stream_link(s.name),
) for s in created_streams),)
else:
stream_msg = "a new stream `%s`" % (created_streams[0].name)
msg = ("%s just created %s. To join, click the gear "
"in the left-side streams list.") % (user_profile.full_name, stream_msg)
stream_msg = "a new stream [%s](%s)" % (
created_streams[0].name,
stream_link(created_streams[0].name)
)
msg = ("%s just created %s. To join, visit your [Streams page](#subscriptions)."
% (user_profile.full_name, stream_msg))
notifications.append(internal_prep_message(settings.NOTIFICATION_BOT,
"stream",
notifications_stream.name, "Streams", msg,