From 9489960b73f268fef45812c18a8f93b36f915dad Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 27 May 2020 19:08:13 +0000 Subject: [PATCH] dead code: Remove useless resize calls. We had a bunch of places where we were calling `resize.resize_bottom_whitespace` with no arguments, which has been a no-op since the below commit that removed support for our `autoscroll_forever` option: fa44d2ea693260c1081c1144206bb687f47b963a With the `autoscroll_forever` options things like opening/closing the compose box could alter how much bottom whitespace you'd want, but we stopped supporting that feature in 2017. Since then bottom_whitespace has just always been 40% of the viewport size. So we only need to change it on actual resize events. It's worth noting that we still call `resize_bottom_whitespace` indirectly in many places, via `resize_page_components`, and the latter actually causes `resize_bottom_whitespace` to do real work, but that work is redundant for most of those codepaths, since they're not triggered by changes to the viewport. So there are other opportunities for cleanup. --- frontend_tests/node_tests/compose.js | 5 +---- frontend_tests/node_tests/compose_actions.js | 4 ---- frontend_tests/node_tests/message_fetch.js | 2 -- static/js/compose.js | 1 - static/js/compose_actions.js | 2 -- static/js/gear_menu.js | 1 - static/js/hotkey.js | 3 --- static/js/message_fetch.js | 1 - static/js/resize.js | 4 +--- 9 files changed, 2 insertions(+), 21 deletions(-) diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 746258f121..8295674e86 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -22,9 +22,6 @@ const _document = { const _drafts = { delete_draft_after_send: noop, }; -const _resize = { - resize_bottom_whitespace: noop, -}; const _sent_messages = { start_tracking_message: noop, @@ -42,7 +39,6 @@ set_global('drafts', _drafts); set_global('navigator', _navigator); set_global('notifications', _notifications); set_global('reminder', _reminder); -set_global('resize', _resize); set_global('sent_messages', _sent_messages); set_global('local_message', {}); @@ -52,6 +48,7 @@ set_global('stream_edit', {}); set_global('markdown', {}); set_global('loading', {}); set_global('page_params', {}); +set_global('resize', {}); set_global('subs', {}); set_global('ui_util', {}); diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 867442fb31..78c7723422 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -63,10 +63,6 @@ set_global('drafts', { update_draft: noop, }); -set_global('resize', { - resize_bottom_whitespace: noop, -}); - set_global('narrow_state', { set_compose_defaults: noop, }); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 8181291d4b..0c43d2438f 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -35,7 +35,6 @@ set_global('notifications', { hide_or_show_history_limit_message: () => {}, }); set_global('pm_list', {}); -set_global('resize', {}); set_global('server_events', {}); set_global('stream_list', { maybe_scroll_narrow_into_view: () => {}, @@ -48,7 +47,6 @@ const alice = { }; people.add_active_user(alice); -resize.resize_bottom_whitespace = noop; server_events.home_view_loaded = noop; function stub_message_view(list) { diff --git a/static/js/compose.js b/static/js/compose.js index 2c14da368d..7c3c82a0d2 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -275,7 +275,6 @@ function clear_compose_box() { $("#compose-send-status").hide(0); $("#compose-send-button").prop('disabled', false); $("#sending-indicator").hide(); - resize.resize_bottom_whitespace(); } exports.clear_compose_box = clear_compose_box; diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 12593c96d4..b4b223d200 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -114,7 +114,6 @@ exports.complete_starting_tasks = function (msg_type, opts) { compose_fade.start_compose(msg_type); ui_util.decorate_stream_bar(opts.stream, $("#stream-message .message_header_stream"), true); $(document).trigger($.Event('compose_started.zulip', opts)); - resize.resize_bottom_whitespace(); exports.update_placeholder_text(opts); }; @@ -244,7 +243,6 @@ exports.cancel = function () { } hide_box(); $("#compose_close").hide(); - resize.resize_bottom_whitespace(); clear_box(); notifications.clear_compose_notifications(); compose.abort_xhr(); diff --git a/static/js/gear_menu.js b/static/js/gear_menu.js index 69b01b6b73..aefa02d21a 100644 --- a/static/js/gear_menu.js +++ b/static/js/gear_menu.js @@ -93,7 +93,6 @@ exports.initialize = function () { }); $('#gear-menu a[data-toggle="tab"]').on('shown', function (e) { const target_tab = $(e.target).attr('href'); - resize.resize_bottom_whitespace(); // Hide all our error messages when switching tabs $('.alert').removeClass("show"); diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 6dcd984229..86f8120da5 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -773,9 +773,6 @@ exports.process_keydown = function (e) { $(document).keydown(function (e) { if (exports.process_keydown(e)) { - // TODO: We should really move this resize code - // so it only executes as part of navigation actions. - resize.resize_bottom_whitespace(); e.preventDefault(); } }); diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index d55ee89fb6..1f8e28f1db 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -103,7 +103,6 @@ function get_messages_success(data, opts) { } process_result(data, opts); - resize.resize_bottom_whitespace(); } // This function modifies the data.narrow filters to use user IDs diff --git a/static/js/resize.js b/static/js/resize.js index 1251aa2981..a39d2d5f7c 100644 --- a/static/js/resize.js +++ b/static/js/resize.js @@ -186,9 +186,7 @@ exports.watch_manual_resize = function (element) { }; exports.resize_bottom_whitespace = function (h) { - if (h !== undefined) { - $("#bottom_whitespace").height(h.bottom_whitespace_height); - } + $("#bottom_whitespace").height(h.bottom_whitespace_height); }; exports.resize_stream_filters_container = function (h) {