diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index d9475ff0f2..994b9197a6 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -564,9 +564,8 @@ run_test('delete_sub', () => { // We had earlier disabled warnings, so we need to remake zblueslip. set_global('blueslip', global.make_zblueslip()); - blueslip.set_test_data('warn', 'Failed to delete stream does_not_exist'); - blueslip.set_test_data('warn', 'We got a get_subscriber_count count call for a non-existent stream.'); - stream_data.delete_sub('does_not_exist'); + blueslip.set_test_data('warn', 'Failed to delete stream 99999'); + stream_data.delete_sub(99999); assert.equal(blueslip.get_test_logs('warn').length, 1); blueslip.clear_test_data(); }); @@ -776,17 +775,17 @@ run_test('initialize', () => { function initialize() { page_params.subscriptions = [{ name: 'subscriptions', - stream_id: '2001', + stream_id: 2001, }]; page_params.unsubscribed = [{ name: 'unsubscribed', - stream_id: '2002', + stream_id: 2002, }]; page_params.never_subscribed = [{ name: 'never_subscribed', - stream_id: '2003', + stream_id: 2003, }]; } diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 4a19ba7ac0..2a4da78af7 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -586,7 +586,7 @@ MessageListView.prototype = { }); content.find('a.stream').each(function () { - const stream_id = $(this).attr('data-stream-id'); + const stream_id = parseInt($(this).attr('data-stream-id'), 10); if (stream_id && !$(this).find(".highlight").length) { // Display the current name for stream if it is not // being displayed in search highlight. @@ -595,7 +595,7 @@ MessageListView.prototype = { }); content.find('a.stream-topic').each(function () { - const stream_id = $(this).attr('data-stream-id'); + const stream_id = parseInt($(this).attr('data-stream-id'), 10); if (stream_id && !$(this).find(".highlight").length) { // Display the current name for stream if it is not // being displayed in search highlight. diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 771bc563a9..a80fc334b6 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -282,7 +282,7 @@ exports.show_new_stream_modal = function () { $("#stream-checkboxes label.checkbox").on('change', function (e) { const elem = $(this); - const stream_id = elem.attr('data-stream-id'); + const stream_id = parseInt(elem.attr('data-stream-id'), 10); const checked = elem.find('input').prop('checked'); const subscriber_ids = stream_data.get_sub_by_id(stream_id).subscribers; diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 09884c5968..49d7a418a9 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -1,4 +1,5 @@ const Dict = require('./dict').Dict; +const IntDict = require('./int_dict').IntDict; const FoldDict = require('./fold_dict').FoldDict; const LazySet = require('./lazy_set').LazySet; @@ -90,7 +91,7 @@ exports.clear_subscriptions = function () { stream_info = new BinaryDict(function (sub) { return sub.subscribed; }); - subs_by_stream_id = new Dict(); + subs_by_stream_id = new IntDict(); }; exports.clear_subscriptions(); @@ -231,7 +232,7 @@ exports.name_to_slug = function (name) { exports.slug_to_name = function (slug) { const m = /^([\d]+)-/.exec(slug); if (m) { - const stream_id = m[1]; + const stream_id = parseInt(m[1], 10); const sub = subs_by_stream_id.get(stream_id); if (sub) { return sub.name; diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 910b7471ff..796a0db199 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -51,7 +51,8 @@ function get_stream_id(target) { if (target.constructor !== jQuery) { target = $(target); } - return target.closest(".stream-row, .subscription_settings").attr("data-stream-id"); + const row = target.closest(".stream-row, .subscription_settings"); + return parseInt(row.attr("data-stream-id"), 10); } function get_sub_for_target(target) { diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 8196524f17..f7a96f2669 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -153,6 +153,10 @@ exports.get_stream_li = function (stream_id) { return li; }; +function stream_id_for_elt(elt) { + return parseInt(elt.attr('data-stream-id'), 10); +} + exports.zoom_in_topics = function (options) { // This only does stream-related tasks related to zooming // in to more topics, which is basically hiding all the @@ -170,9 +174,9 @@ exports.zoom_in_topics = function (options) { $("#stream_filters li.narrow-filter").each(function () { const elt = $(this); - const stream_id = options.stream_id.toString(); + const stream_id = options.stream_id; - if (elt.attr('data-stream-id') === stream_id) { + if (stream_id_for_elt(elt) === stream_id) { elt.show(); } else { elt.hide(); @@ -502,7 +506,7 @@ exports.set_event_handlers = function () { if (e.metaKey || e.ctrlKey) { return; } - const stream_id = $(e.target).parents('li').attr('data-stream-id'); + const stream_id = stream_id_for_elt($(e.target).parents('li')); const sub = stream_data.get_sub_by_id(stream_id); popovers.hide_all(); narrow.by('stream', sub.name, {trigger: 'sidebar'}); diff --git a/static/js/subs.js b/static/js/subs.js index 12e5ba0288..ba830d3b2a 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -393,12 +393,16 @@ exports.populate_stream_settings_left_panel = function () { exports.filter_table = function (query) { exports.show_active_stream_in_left_panel(); + function stream_id_for_row(row) { + return parseInt($(row).attr('data-stream-id'), 10); + } + const widgets = {}; const streams_list_scrolltop = ui.get_scroll_element($(".streams-list")).scrollTop(); const stream_ids = []; _.each($("#subscriptions_table .stream-row"), function (row) { - const stream_id = $(row).attr('data-stream-id'); + const stream_id = stream_id_for_row(row); stream_ids.push(stream_id); }); @@ -412,7 +416,7 @@ exports.filter_table = function (query) { }); _.each($("#subscriptions_table .stream-row"), function (row) { - const stream_id = $(row).attr('data-stream-id'); + const stream_id = stream_id_for_row(row); // Below code goes away if we don't do sort-DOM-in-place. if (hidden_ids[stream_id]) { diff --git a/static/js/topic_list.js b/static/js/topic_list.js index d8032e2ee7..1577e532c7 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -393,7 +393,8 @@ exports.initialize = function () { // In a more componentized world, we would delegate some // of this stuff back up to our parents. - const stream_id = $(e.target).parents('.narrow-filter').attr('data-stream-id'); + const stream_row = $(e.target).parents('.narrow-filter'); + const stream_id = parseInt(stream_row.attr('data-stream-id'), 10); const sub = stream_data.get_sub_by_id(stream_id); const topic = $(e.target).parents('li').attr('data-topic-name');