From a87596a3f9c3d93245a71ca4c8046f7a8a7dcc29 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 17 Feb 2021 17:48:10 +0000 Subject: [PATCH] subs cleanup: Simplify is_sub_already_present(). Checking for the button was a brittle way to do this. Note that the code on master is flawed insofar as we don't respect the search filters. I don't fix that bug here. This is a tactical change to eliminate another function. Upcoming changes will make it so that all the bugs related to "notdisplayed" will simply go away. --- static/js/subs.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/static/js/subs.js b/static/js/subs.js index 1f11e80f60..85eaf31725 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -37,6 +37,10 @@ exports.row_for_stream_id = function (stream_id) { return $(`.stream-row[data-stream-id='${CSS.escape(stream_id)}']`); }; +exports.is_sub_already_present = function (sub) { + return exports.row_for_stream_id(sub.stream_id).length > 0; +}; + exports.settings_button_for_sub = function (sub) { // We don't do expectOne() here, because this button is only // visible if the user has that stream selected in the streams UI. @@ -266,16 +270,6 @@ exports.add_sub_to_table = function (sub) { } }; -exports.is_sub_already_present = function (sub) { - // This checks if a stream is already listed the "Manage streams" - // UI, by checking for its subscribe/unsubscribe checkmark button. - const button = exports.check_button_for_sub(sub); - if (button.length !== 0) { - return true; - } - return false; -}; - exports.remove_stream = function (stream_id) { // It is possible that row is empty when we deactivate a // stream, but we let jQuery silently handle that.