diff --git a/web/src/compose_setup.js b/web/src/compose_setup.js index 2e6c5a6e67..4b0e1cbf2d 100644 --- a/web/src/compose_setup.js +++ b/web/src/compose_setup.js @@ -253,7 +253,7 @@ export function initialize() { const $invite_row = $(event.target).parents(".main-view-banner"); const user_id = Number.parseInt($invite_row.data("user-id"), 10); - const stream_id = Number.parseInt($invite_row.data("stream-id"), 10); + const stream_id = Number($invite_row.attr("data-stream-id")); function success() { $invite_row.remove(); diff --git a/web/src/compose_validate.ts b/web/src/compose_validate.ts index eb17ca31f5..cbbba3bd90 100644 --- a/web/src/compose_validate.ts +++ b/web/src/compose_validate.ts @@ -183,7 +183,7 @@ export function warn_if_private_stream_is_linked( ); const existing_stream_warnings = [...$existing_stream_warnings_area].map((stream_row) => - Number.parseInt($(stream_row).data("stream-id"), 10), + Number($(stream_row).attr("data-stream-id")), ); if (!existing_stream_warnings.includes(linked_stream.stream_id)) { diff --git a/web/src/settings_streams.js b/web/src/settings_streams.js index 498a7899bd..34f532ee53 100644 --- a/web/src/settings_streams.js +++ b/web/src/settings_streams.js @@ -29,7 +29,7 @@ function get_chosen_default_streams() { // Return the set of stream id's of streams chosen in the default stream modal. return new Set( $("#default-stream-choices .choice-row .dropdown_widget_value") - .map((_i, elem) => $(elem).data("stream-id")?.toString()) + .map((_i, elem) => Number($(elem).attr("data-stream-id")).toString()) .get(), ); } @@ -58,7 +58,7 @@ function create_choice_row() { const $stream_dropdown_widget = $(`#${CSS.escape(stream_dropdown_widget_name)}_widget`); const $stream_name = $stream_dropdown_widget.find(".dropdown_widget_value"); $stream_name.text(selected_stream_name); - $stream_name.data("stream-id", selected_stream_id); + $stream_name.attr("data-stream-id", selected_stream_id); add_choice_row($stream_dropdown_widget); dropdown.hide(); diff --git a/web/src/stream_edit.js b/web/src/stream_edit.js index 042e8fc8da..67ac7a6479 100644 --- a/web/src/stream_edit.js +++ b/web/src/stream_edit.js @@ -599,7 +599,7 @@ export function initialize() { } function do_archive_stream() { - const stream_id = $(".dialog_submit_button").data("stream-id"); + const stream_id = Number($(".dialog_submit_button").attr("data-stream-id")); if (!stream_id) { ui_report.client_error( $t_html({defaultMessage: "Invalid channel ID"}), @@ -692,7 +692,9 @@ export function initialize() { const $save_button = $(e.currentTarget); const $subsection_elem = $save_button.closest(".settings-subsection-parent"); - const stream_id = $save_button.closest(".subscription_settings.show").data("stream-id"); + const stream_id = Number( + $save_button.closest(".subscription_settings.show").attr("data-stream-id"), + ); const sub = sub_store.get(stream_id); const data = settings_org.populate_data_for_request($subsection_elem, false, sub); @@ -724,7 +726,9 @@ export function initialize() { e.preventDefault(); e.stopPropagation(); - const stream_id = $(e.target).closest(".subscription_settings.show").data("stream-id"); + const stream_id = Number( + $(e.target).closest(".subscription_settings.show").attr("data-stream-id"), + ); const sub = sub_store.get(stream_id); const $subsection = $(e.target).closest(".settings-subsection-parent"); diff --git a/web/src/stream_ui_updates.js b/web/src/stream_ui_updates.js index 0046eab40b..0c482191f0 100644 --- a/web/src/stream_ui_updates.js +++ b/web/src/stream_ui_updates.js @@ -313,7 +313,7 @@ export function update_notification_setting_checkbox(notification_name) { if (!$stream_row.length) { return; } - const stream_id = $stream_row.data("stream-id"); + const stream_id = Number($stream_row.attr("data-stream-id")); $(`#${CSS.escape(notification_name)}_${CSS.escape(stream_id)}`).prop( "checked", stream_data.receives_notifications(stream_id, notification_name), diff --git a/web/tests/compose_validate.test.js b/web/tests/compose_validate.test.js index cad9fcfe8b..57a783225d 100644 --- a/web/tests/compose_validate.test.js +++ b/web/tests/compose_validate.test.js @@ -647,10 +647,7 @@ test_ui("warn_if_private_stream_is_linked", ({mock_template}) => { // Simulate that the row was added to the DOM. const $warning_row = $("#compose_banners .private_stream_warning"); - $warning_row.data = (key) => - ({ - "stream-id": "22", - })[key]; + $warning_row.attr("data-stream-id", "22"); $("#compose_banners .private_stream_warning").length = 1; $("#compose_banners .private_stream_warning")[0] = $warning_row; @@ -738,8 +735,8 @@ test_ui("warn_if_mentioning_unsubscribed_user", ({override, mock_template}) => { $warning_row.data = (key) => ({ "user-id": "34", - "stream-id": "111", })[key]; + $warning_row.attr("data-stream-id", "111"); $("#compose_banners .recipient_not_subscribed").length = 1; $("#compose_banners .recipient_not_subscribed")[0] = $warning_row;