From ca182ec062352e5685db7cf641b492d4c1cfc792 Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Mon, 25 Nov 2013 10:18:09 -0500 Subject: [PATCH] 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) --- zerver/tests.py | 4 ++-- zerver/views/__init__.py | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/zerver/tests.py b/zerver/tests.py index 2581964dea..dd83cfd20d 100644 --- a/zerver/tests.py +++ b/zerver/tests.py @@ -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 " diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index 352dcb769a..74709ca619 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -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,