From 45bee2f512f49c7299e986495751fcc95389bbdb Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 16 Jan 2020 14:40:40 -0500 Subject: [PATCH] js: Clean up stream_id type confusion. Signed-off-by: Anders Kaseorg --- static/js/click_handlers.js | 4 ++-- static/js/popovers.js | 4 ++-- static/js/settings_muting.js | 2 +- static/js/stream_color.js | 2 +- static/js/stream_edit.js | 2 +- static/js/subs.js | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index e10636c24f..2cfde3cc27 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -258,7 +258,7 @@ exports.initialize = function () { e.preventDefault(); // Note that we may have an href here, but we trust the stream id more, // so we re-encode the hash. - const stream_id = $(this).attr('data-stream-id'); + const stream_id = parseInt($(this).attr('data-stream-id'), 10); if (stream_id) { hashchange.go_to_location(hash_util.by_stream_uri(stream_id)); return; @@ -392,7 +392,7 @@ exports.initialize = function () { $('body').on('click', '.on_hover_topic_mute', function (e) { e.stopPropagation(); - const stream_id = $(e.currentTarget).attr('data-stream-id'); + const stream_id = parseInt($(e.currentTarget).attr('data-stream-id'), 10); const topic = $(e.currentTarget).attr('data-topic-name'); muting_ui.mute(stream_id, topic); }); diff --git a/static/js/popovers.js b/static/js/popovers.js index bf597b5e41..c9e31f7b15 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -1020,7 +1020,7 @@ exports.register_click_handlers = function () { }); $('body').on('click', '.popover_mute_topic', function (e) { - const stream_id = $(e.currentTarget).attr('data-msg-stream-id'); + const stream_id = parseInt($(e.currentTarget).attr('data-msg-stream-id'), 10); const topic = $(e.currentTarget).attr('data-msg-topic'); exports.hide_actions_popover(); @@ -1030,7 +1030,7 @@ exports.register_click_handlers = function () { }); $('body').on('click', '.popover_unmute_topic', function (e) { - const stream_id = $(e.currentTarget).attr('data-msg-stream-id'); + const stream_id = parseInt($(e.currentTarget).attr('data-msg-stream-id'), 10); const topic = $(e.currentTarget).attr('data-msg-topic'); exports.hide_actions_popover(); diff --git a/static/js/settings_muting.js b/static/js/settings_muting.js index 0d1df5bd9d..d1a7eb1d4c 100644 --- a/static/js/settings_muting.js +++ b/static/js/settings_muting.js @@ -1,7 +1,7 @@ exports.set_up = function () { $('body').on('click', '.settings-unmute-topic', function (e) { const $row = $(this).closest("tr"); - const stream_id = $row.attr("data-stream-id"); + const stream_id = parseInt($row.attr("data-stream-id"), 10); const topic = $row.attr("data-topic"); e.stopImmediatePropagation(); diff --git a/static/js/stream_color.js b/static/js/stream_color.js index 87da690c40..02ff73e9a5 100644 --- a/static/js/stream_color.js +++ b/static/js/stream_color.js @@ -59,7 +59,7 @@ exports.set_colorpicker_color = function (colorpicker, color) { exports.update_stream_color = function (sub, color, opts) { opts = _.defaults({}, opts, {update_historical: false}); sub.color = color; - const id = parseInt(sub.stream_id, 10); + const id = sub.stream_id; // The swatch in the subscription row header. $(".stream-row[data-stream-id='" + id + "'] .icon").css('background-color', color); // The swatch in the color picker. diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 04870ecc02..46e014cd81 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -19,7 +19,7 @@ exports.setup_subscriptions_tab_hash = function (tab_key_value) { }; exports.settings_for_sub = function (sub) { - const id = parseInt(sub.stream_id, 10); + const id = sub.stream_id; return $("#subscription_overlay .subscription_settings[data-stream-id='" + id + "']"); }; diff --git a/static/js/subs.js b/static/js/subs.js index 686895c159..a92bc50f87 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -15,7 +15,7 @@ exports.show_subs_pane = { }; exports.check_button_for_sub = function (sub) { - const id = parseInt(sub.stream_id, 10); + const id = sub.stream_id; return $(".stream-row[data-stream-id='" + id + "'] .check"); }; @@ -26,12 +26,12 @@ exports.row_for_stream_id = function (stream_id) { 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. - const id = parseInt(sub.stream_id, 10); + const id = sub.stream_id; return $(".subscription_settings[data-stream-id='" + id + "'] .subscribe-button"); }; function get_row_data(row) { - const row_id = row.attr('data-stream-id'); + const row_id = parseInt(row.attr('data-stream-id'), 10); if (row_id) { const row_object = stream_data.get_sub_by_id(row_id); return { @@ -43,7 +43,7 @@ function get_row_data(row) { exports.get_active_data = function () { const active_row = $('div.stream-row.active'); - const valid_active_id = active_row.attr('data-stream-id'); + const valid_active_id = parseInt(active_row.attr('data-stream-id'), 10); const active_tab = $('.subscriptions-container').find('div.ind-tab.selected'); return { row: active_row,