From 8a4dee4a80985db6cbe9e27f4a2711d4bb65e4e2 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 4 Mar 2017 14:02:59 -0800 Subject: [PATCH] bug fix: Handle bad streams for compose-invite feature. We now handle missing subs more gracefully when you click on the link to invite somebody you at-mentioned in a stream message. --- static/js/compose.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/static/js/compose.js b/static/js/compose.js index c7c1ff3cc7..7f0e8cf399 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -974,19 +974,34 @@ $(function () { return; } - subs.invite_user_to_stream(email, compose.stream_name(), function () { + function success() { var all_invites = $("#compose_invite_users"); invite_row.remove(); if (all_invites.children().length === 0) { all_invites.hide(); } - }, function () { + } + + function failure() { var error_msg = invite_row.find('.compose_invite_user_error'); error_msg.show(); $(event.target).attr('disabled', true); - }); + } + + var stream_name = compose.stream_name(); + var sub = stream_data.get_sub(stream_name); + if (!sub) { + // This should only happen if a stream rename occurs + // before the user clicks. We could prevent this by + // putting a stream id in the link. + blueslip.warn('Stream no longer exists: ' + stream_name); + failure(); + return; + } + + subs.invite_user_to_stream(email, sub.name, success, failure); }); $("#compose_invite_users").on('click', '.compose_invite_close', function (event) {