From c9fccf476a4b9a1c6bf35e720a1a5517d921d033 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Mon, 23 Oct 2023 12:32:57 +0530 Subject: [PATCH] settings: Rename default_view and escape_navigates_to_default_view. This commit renames default_view and escape_navigates_to_default_view settings to web_home_view and web_escape_navigates_to_home_view in database and API to match with our recent renaming of user facing strings related to this. We also rename the variables, functions, comments in code and class names and IDs for elements related to this. --- api_docs/changelog.md | 8 ++ version.py | 2 +- web/src/admin.js | 2 +- web/src/browser_history.ts | 6 +- web/src/click_handlers.js | 2 +- web/src/hashchange.js | 32 ++++---- web/src/hotkey.js | 6 +- web/src/info_overlay.js | 4 +- web/src/left_sidebar_navigation_area.js | 8 +- .../left_sidebar_navigation_area_popovers.js | 18 ++--- web/src/realm_user_settings_defaults.ts | 4 +- web/src/server_events_dispatch.js | 22 +++--- web/src/settings.js | 2 +- web/src/settings_config.ts | 4 +- web/src/settings_display.js | 2 +- web/src/tippyjs.js | 2 +- web/src/ui_init.js | 8 +- web/src/user_settings.ts | 4 +- web/templates/keyboard_shortcuts.hbs | 2 +- web/templates/left_sidebar.hbs | 4 +- .../left_sidebar_all_messages_popover.hbs | 2 +- .../popovers/left_sidebar_inbox_popover.hbs | 4 +- .../left_sidebar_recent_view_popover.hbs | 2 +- web/templates/settings/display_settings.hbs | 12 +-- web/tests/browser_history.test.js | 2 +- web/tests/dispatch.test.js | 26 +++---- web/tests/hashchange.test.js | 6 +- web/tests/lib/events.js | 56 +++++++------- ..._escape_navigates_to_home_view_and_more.py | 32 ++++++++ zerver/models.py | 8 +- zerver/openapi/zulip.yaml | 74 ++++++++++++------- zerver/tests/test_audit_log.py | 2 +- zerver/tests/test_events.py | 6 +- zerver/tests/test_realm.py | 2 +- zerver/tests/test_settings.py | 4 +- zerver/tests/test_users.py | 6 +- zerver/views/realm.py | 10 ++- zerver/views/user_settings.py | 10 ++- 38 files changed, 235 insertions(+), 171 deletions(-) create mode 100644 zerver/migrations/0483_rename_escape_navigates_to_default_view_realmuserdefault_web_escape_navigates_to_home_view_and_more.py diff --git a/api_docs/changelog.md b/api_docs/changelog.md index 990a8a609d..a06e024662 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,14 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 8.0 +**Feature level 219** + +* [`PATCH /realm/user_settings_defaults`](/api/update-realm-user-settings-defaults) + [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events), + [`PATCH /settings`](/api/update-settings): Renamed `default_view` and + `escape_navigates_to_default_view` settings to `web_home_view` and + `web_escape_navigates_to_home_view` respectively. + **Feature level 218** * [`POST /messages`](/api/send-message): Added an optional diff --git a/version.py b/version.py index f395616fed..463b66b7b1 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 218 +API_FEATURE_LEVEL = 219 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/web/src/admin.js b/web/src/admin.js index 4e1110b9d9..25c81be9b5 100644 --- a/web/src/admin.js +++ b/web/src/admin.js @@ -184,7 +184,7 @@ export function build_page() { web_stream_unreads_count_display_policy_values: settings_config.web_stream_unreads_count_display_policy_values, color_scheme_values: settings_config.color_scheme_values, - default_view_values: settings_config.default_view_values, + web_home_view_values: settings_config.web_home_view_values, settings_object: realm_user_settings_defaults, display_settings: settings_config.get_all_display_settings(), settings_label: settings_config.realm_user_settings_defaults_labels, diff --git a/web/src/browser_history.ts b/web/src/browser_history.ts index 168f0fb43e..2b23e2415d 100644 --- a/web/src/browser_history.ts +++ b/web/src/browser_history.ts @@ -82,7 +82,7 @@ export function update(new_hash: string): void { export function exit_overlay(): void { if (hash_parser.is_overlay_hash(window.location.hash) && !state.changing_hash) { ui_util.blur_active_element(); - const new_hash = state.hash_before_overlay || `#${user_settings.default_view}`; + const new_hash = state.hash_before_overlay || `#${user_settings.web_home_view}`; update(new_hash); } } @@ -100,7 +100,7 @@ export function update_hash_internally_if_required(hash: string): void { } export function return_to_web_public_hash(): void { - window.location.hash = state.spectator_old_hash ?? `#${user_settings.default_view}`; + window.location.hash = state.spectator_old_hash ?? `#${user_settings.web_home_view}`; } export function get_full_url(hash: string): string { @@ -146,7 +146,7 @@ export function set_hash(hash: string): void { // TODO: Delete this case if we don't see any error reports in a while. if (hash === "" || hash === "#") { // Setting empty hash here would scroll to the top. - hash = user_settings.default_view; + hash = user_settings.web_home_view; } blueslip.error("browser does not support pushState"); diff --git a/web/src/click_handlers.js b/web/src/click_handlers.js index 545fe2131e..ba8b568379 100644 --- a/web/src/click_handlers.js +++ b/web/src/click_handlers.js @@ -787,7 +787,7 @@ export function initialize() { e.preventDefault(); e.stopPropagation(); - hashchange.set_hash_to_default_view(); + hashchange.set_hash_to_home_view(); }); // MAIN CLICK HANDLER diff --git a/web/src/hashchange.js b/web/src/hashchange.js index 8f9c312016..d667f722da 100644 --- a/web/src/hashchange.js +++ b/web/src/hashchange.js @@ -61,13 +61,13 @@ function show_all_message_view() { setTimeout(message_viewport.maybe_scroll_to_selected, 0); } -export function set_hash_to_default_view() { - let default_view_hash = `#${user_settings.default_view}`; - if (default_view_hash === "#recent_topics") { - default_view_hash = "#recent"; +export function set_hash_to_home_view() { + let home_view_hash = `#${user_settings.web_home_view}`; + if (home_view_hash === "#recent_topics") { + home_view_hash = "#recent"; } - if (window.location.hash !== default_view_hash) { + if (window.location.hash !== home_view_hash) { // We want to set URL with no hash here. It is not possible // to do so with `window.location.hash` since it will set an empty // hash. So, we use `pushState` which simply updates the current URL @@ -83,14 +83,14 @@ function hide_non_message_list_views() { maybe_hide_recent_view(); } -function show_default_view() { +function show_home_view() { hide_non_message_list_views(); // This function should only be called from the hashchange // handlers, as it does not set the hash to "". // - // We only allow the primary recommended options for default views + // We only allow the primary recommended options for home views // rendered without a hash. - switch (user_settings.default_view) { + switch (user_settings.web_home_view) { case "recent_topics": { recent_view_ui.show(); break; @@ -110,7 +110,7 @@ function show_default_view() { // go back in browser history. See // https://chat.zulip.org/#narrow/stream/9-issues/topic/Browser.20back.20button.20on.20RT // for detailed description of the issue. - window.location.hash = user_settings.default_view; + window.location.hash = user_settings.web_home_view; } } } @@ -141,11 +141,11 @@ function do_hashchange_normal(from_reload) { } if (operators === undefined) { // If the narrow URL didn't parse, - // send them to default_view. + // send them to web_home_view. // We cannot clear hash here since // it will block user from going back // in browser history. - show_default_view(); + show_home_view(); return false; } const narrow_opts = { @@ -171,7 +171,7 @@ function do_hashchange_normal(from_reload) { } case "": case "#": - show_default_view(); + show_home_view(); break; case "#recent_topics": // The URL for Recent Conversations was changed from @@ -208,7 +208,7 @@ function do_hashchange_normal(from_reload) { blueslip.error("overlay logic skipped for: " + hash); break; default: - show_default_view(); + show_home_view(); } return false; } @@ -216,8 +216,8 @@ function do_hashchange_normal(from_reload) { function do_hashchange_overlay(old_hash) { if (old_hash === undefined) { // The user opened the app with an overlay hash; we need to - // show the user's default view behind it. - show_default_view(); + // show the user's home view behind it. + show_home_view(); } const base = hash_parser.get_current_hash_category(); const old_base = hash_parser.get_hash_category(old_hash); @@ -225,7 +225,7 @@ function do_hashchange_overlay(old_hash) { if (base === "groups" && (!page_params.development_environment || page_params.is_guest)) { // The #groups settings page is unfinished, and disabled in production. - show_default_view(); + show_home_view(); return; } diff --git a/web/src/hotkey.js b/web/src/hotkey.js index 9d139a0599..e658907e51 100644 --- a/web/src/hotkey.js +++ b/web/src/hotkey.js @@ -350,10 +350,10 @@ export function process_escape_key(e) { return true; } - /* The Ctrl+[ hotkey navigates to the default view + /* The Ctrl+[ hotkey navigates to the home view * unconditionally; Esc's behavior depends on a setting. */ - if (user_settings.escape_navigates_to_default_view || e.which === 219) { - hashchange.set_hash_to_default_view(); + if (user_settings.web_escape_navigates_to_home_view || e.which === 219) { + hashchange.set_hash_to_home_view(); return true; } diff --git a/web/src/info_overlay.js b/web/src/info_overlay.js index c4e255c867..81269f5fc7 100644 --- a/web/src/info_overlay.js +++ b/web/src/info_overlay.js @@ -294,9 +294,9 @@ export function set_up_toggler() { $(".informational-overlays .overlay-tabs").append($elem); - $("#go-to-default-view-hotkey-help").toggleClass( + $("#go-to-home-view-hotkey-help").toggleClass( "notdisplayed", - !user_settings.escape_navigates_to_default_view, + !user_settings.web_escape_navigates_to_home_view, ); common.adjust_mac_kbd_tags(".hotkeys_table .hotkey kbd"); common.adjust_mac_kbd_tags("#markdown-instructions kbd"); diff --git a/web/src/left_sidebar_navigation_area.js b/web/src/left_sidebar_navigation_area.js index a0af91f5ad..fd0f7fca77 100644 --- a/web/src/left_sidebar_navigation_area.js +++ b/web/src/left_sidebar_navigation_area.js @@ -142,17 +142,17 @@ export function highlight_inbox_view() { }, 0); } -export function handle_home_view_changed(new_default_view) { +export function handle_home_view_changed(new_home_view) { const $recent_view_sidebar_menu_icon = $(".recent-view-sidebar-menu-icon"); const $all_messages_sidebar_menu_icon = $(".all-messages-sidebar-menu-icon"); - if (new_default_view === settings_config.default_view_values.all_messages.code) { + if (new_home_view === settings_config.web_home_view_values.all_messages.code) { $recent_view_sidebar_menu_icon.removeClass("hide"); $all_messages_sidebar_menu_icon.addClass("hide"); - } else if (new_default_view === settings_config.default_view_values.recent_topics.code) { + } else if (new_home_view === settings_config.web_home_view_values.recent_topics.code) { $recent_view_sidebar_menu_icon.addClass("hide"); $all_messages_sidebar_menu_icon.removeClass("hide"); } else { - // Inbox is default view. + // Inbox is home view. $recent_view_sidebar_menu_icon.removeClass("hide"); $all_messages_sidebar_menu_icon.removeClass("hide"); } diff --git a/web/src/left_sidebar_navigation_area_popovers.js b/web/src/left_sidebar_navigation_area_popovers.js index 676e9e3c1f..b705f23b3d 100644 --- a/web/src/left_sidebar_navigation_area_popovers.js +++ b/web/src/left_sidebar_navigation_area_popovers.js @@ -20,12 +20,12 @@ import * as unread_ops from "./unread_ops"; import {user_settings} from "./user_settings"; function common_click_handlers() { - $("body").on("click", ".set-default-view", (e) => { + $("body").on("click", ".set-home-view", (e) => { e.preventDefault(); e.preventDefault(); - const default_view = $(e.currentTarget).attr("data-view-code"); - const data = {default_view}; + const web_home_view = $(e.currentTarget).attr("data-view-code"); + const data = {web_home_view}; channel.patch({ url: "/json/settings", data, @@ -116,11 +116,11 @@ export function initialize() { }, onShow(instance) { popovers.hide_all(); - const view_code = settings_config.default_view_values.inbox.code; + const view_code = settings_config.web_home_view_values.inbox.code; instance.setContent( parse_html( render_left_sidebar_inbox_popover({ - is_default_view: user_settings.default_view === view_code, + is_home_view: user_settings.web_home_view === view_code, view_code, }), ), @@ -138,11 +138,11 @@ export function initialize() { onShow(instance) { popover_menus.popover_instances.left_sidebar_all_messages_popover = instance; popovers.hide_all(); - const view_code = settings_config.default_view_values.all_messages.code; + const view_code = settings_config.web_home_view_values.all_messages.code; instance.setContent( parse_html( render_left_sidebar_all_messages_popover({ - is_default_view: user_settings.default_view === view_code, + is_home_view: user_settings.web_home_view === view_code, view_code, }), ), @@ -160,11 +160,11 @@ export function initialize() { onShow(instance) { popover_menus.popover_instances.left_sidebar_recent_view_popover = instance; popovers.hide_all(); - const view_code = settings_config.default_view_values.recent_topics.code; + const view_code = settings_config.web_home_view_values.recent_topics.code; instance.setContent( parse_html( render_left_sidebar_recent_view_popover({ - is_default_view: user_settings.default_view === view_code, + is_home_view: user_settings.web_home_view === view_code, view_code, }), ), diff --git a/web/src/realm_user_settings_defaults.ts b/web/src/realm_user_settings_defaults.ts index 55b232da14..ffe74a04a5 100644 --- a/web/src/realm_user_settings_defaults.ts +++ b/web/src/realm_user_settings_defaults.ts @@ -1,7 +1,7 @@ export type RealmDefaultSettings = { color_scheme: number; default_language: string; - default_view: string; + web_home_view: string; desktop_icon_count_display: number; demote_inactive_streams: number; dense_mode: boolean; @@ -27,7 +27,7 @@ export type RealmDefaultSettings = { enable_followed_topic_email_notifications: boolean; enable_followed_topic_wildcard_mentions_notify: boolean; enter_sends: boolean; - escape_navigates_to_default_view: boolean; + web_escape_navigates_to_home_view: boolean; fluid_layout_width: boolean; high_contrast_mode: boolean; message_content_in_email_notifications: boolean; diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index 9fea3dd701..8b2b71c1cd 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -688,12 +688,12 @@ export function dispatch_normal_event(event) { const user_display_settings = [ "color_scheme", "default_language", - "default_view", + "web_home_view", "demote_inactive_streams", "dense_mode", "web_mark_read_on_scroll_policy", "emojiset", - "escape_navigates_to_default_view", + "web_escape_navigates_to_home_view", "fluid_layout_width", "high_contrast_mode", "timezone", @@ -708,7 +708,7 @@ export function dispatch_normal_event(event) { "send_read_receipts", ]; - const original_default_view = user_settings.default_view; + const original_home_view = user_settings.web_home_view; if (user_display_settings.includes(event.property)) { user_settings[event.property] = event.value; } @@ -721,21 +721,19 @@ export function dispatch_normal_event(event) { // present in the backend/Jinja2 templates. settings_display.set_default_language_name(event.language_name); } - if (event.property === "default_view") { + if (event.property === "web_home_view") { left_sidebar_navigation_area.handle_home_view_changed(event.value); - // If current hash is empty (default view), and the - // user changes the default view while in settings, + // If current hash is empty (home view), and the + // user changes the home view while in settings, // then going back to an empty hash on closing the // overlay will not match the view currently displayed // under settings, so we set the hash to the previous - // value of the default view. + // value of the home view. if (!browser_history.state.hash_before_overlay && overlays.settings_open()) { browser_history.state.hash_before_overlay = "#" + - (original_default_view === "recent_topics" - ? "recent" - : original_default_view); + (original_home_view === "recent_topics" ? "recent" : original_home_view); } } if (event.property === "twenty_four_hour_time") { @@ -809,8 +807,8 @@ export function dispatch_normal_event(event) { if (event.property === "display_emoji_reaction_users") { message_live_update.rerender_messages_view(); } - if (event.property === "escape_navigates_to_default_view") { - $("#go-to-default-view-hotkey-help").toggleClass("notdisplayed", !event.value); + if (event.property === "web_escape_navigates_to_home_view") { + $("#go-to-home-view-hotkey-help").toggleClass("notdisplayed", !event.value); } if (event.property === "enter_sends") { user_settings.enter_sends = event.value; diff --git a/web/src/settings.js b/web/src/settings.js index a9c36016d2..33f92dfb29 100644 --- a/web/src/settings.js +++ b/web/src/settings.js @@ -123,7 +123,7 @@ export function build_page() { web_stream_unreads_count_display_policy_values: settings_config.web_stream_unreads_count_display_policy_values, color_scheme_values: settings_config.color_scheme_values, - default_view_values: settings_config.default_view_values, + web_home_view_values: settings_config.web_home_view_values, twenty_four_hour_time_values: settings_config.twenty_four_hour_time_values, general_settings: settings_config.all_notifications(user_settings).general_settings, notification_settings: settings_config.all_notifications(user_settings).settings, diff --git a/web/src/settings_config.ts b/web/src/settings_config.ts index 28e6803d25..211534281a 100644 --- a/web/src/settings_config.ts +++ b/web/src/settings_config.ts @@ -87,7 +87,7 @@ export const web_stream_unreads_count_display_policy_values = { }, }; -export const default_view_values = { +export const web_home_view_values = { inbox: { code: "inbox", description: $t({defaultMessage: "Inbox"}), @@ -553,7 +553,7 @@ export const display_settings_labels = { "Display names of reacting users when few users have reacted to a message", }), ), - escape_navigates_to_default_view: $t({defaultMessage: "Escape key navigates to home view"}), + web_escape_navigates_to_home_view: $t({defaultMessage: "Escape key navigates to home view"}), default_language_settings_label: $t({defaultMessage: "Language"}), }; diff --git a/web/src/settings_display.js b/web/src/settings_display.js index f8c25c9ab6..712150fe30 100644 --- a/web/src/settings_display.js +++ b/web/src/settings_display.js @@ -166,7 +166,7 @@ export function set_up(settings_panel) { .find(".setting_demote_inactive_streams") .val(settings_object.demote_inactive_streams); $container.find(".setting_color_scheme").val(settings_object.color_scheme); - $container.find(".setting_default_view").val(settings_object.default_view); + $container.find(".setting_web_home_view").val(settings_object.web_home_view); $container .find(".setting_twenty_four_hour_time") .val(JSON.stringify(settings_object.twenty_four_hour_time)); diff --git a/web/src/tippyjs.js b/web/src/tippyjs.js index 2252c9a5c6..087210b61c 100644 --- a/web/src/tippyjs.js +++ b/web/src/tippyjs.js @@ -149,7 +149,7 @@ export function initialize() { appendTo: () => document.body, onShow(instance) { const $container = instance.popper.querySelector(".views-tooltip-container"); - if ($($container).data("view-code") === user_settings.default_view) { + if ($($container).data("view-code") === user_settings.web_home_view) { $($container).find(".views-tooltip-home-view-note").removeClass("hide"); } }, diff --git a/web/src/ui_init.js b/web/src/ui_init.js index 077f8b7c51..5f3557d493 100644 --- a/web/src/ui_init.js +++ b/web/src/ui_init.js @@ -164,10 +164,10 @@ function initialize_left_sidebar() { const rendered_sidebar = render_left_sidebar({ is_guest: page_params.is_guest, development_environment: page_params.development_environment, - is_all_messages_default_view: - user_settings.default_view === settings_config.default_view_values.all_messages.code, - is_recent_view_default_view: - user_settings.default_view === settings_config.default_view_values.recent_topics.code, + is_all_messages_home_view: + user_settings.web_home_view === settings_config.web_home_view_values.all_messages.code, + is_recent_view_home_view: + user_settings.web_home_view === settings_config.web_home_view_values.recent_topics.code, }); $("#left-sidebar-container").html(rendered_sidebar); diff --git a/web/src/user_settings.ts b/web/src/user_settings.ts index fda6b06ed2..1d33a0002c 100644 --- a/web/src/user_settings.ts +++ b/web/src/user_settings.ts @@ -26,7 +26,7 @@ export type UserSettings = (StreamNotificationSettings & FollowedTopicNotificationSettings) & { color_scheme: number; default_language: string; - default_view: string; + web_home_view: string; desktop_icon_count_display: number; demote_inactive_streams: number; dense_mode: boolean; @@ -39,7 +39,7 @@ export type UserSettings = (StreamNotificationSettings & enable_marketing_emails: boolean; enable_online_push_notifications: boolean; enter_sends: boolean; - escape_navigates_to_default_view: boolean; + web_escape_navigates_to_home_view: boolean; fluid_layout_width: boolean; high_contrast_mode: boolean; message_content_in_email_notifications: boolean; diff --git a/web/templates/keyboard_shortcuts.hbs b/web/templates/keyboard_shortcuts.hbs index edb8455ece..d645c57db3 100644 --- a/web/templates/keyboard_shortcuts.hbs +++ b/web/templates/keyboard_shortcuts.hbs @@ -54,7 +54,7 @@ {{t 'Go to home view' }} - Ctrl + [ or Esc + Ctrl + [ or Esc diff --git a/web/templates/left_sidebar.hbs b/web/templates/left_sidebar.hbs index 8d2c7e0f42..bb16a05358 100644 --- a/web/templates/left_sidebar.hbs +++ b/web/templates/left_sidebar.hbs @@ -68,7 +68,7 @@ {{~!-- squash whitespace --~}} {{t 'Recent conversations' }} - + @@ -80,7 +80,7 @@ {{~!-- squash whitespace --~}} {{t 'All messages' }} - + diff --git a/web/templates/popovers/left_sidebar_all_messages_popover.hbs b/web/templates/popovers/left_sidebar_all_messages_popover.hbs index 5960296c84..e3dc8e0b0c 100644 --- a/web/templates/popovers/left_sidebar_all_messages_popover.hbs +++ b/web/templates/popovers/left_sidebar_all_messages_popover.hbs @@ -1,6 +1,6 @@