Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
composebox_typeahead: Remove redundant options from the `/` typeahead.
Jonny Tranddf4053a7356
diff --git a/docs/subsystems/slash-commands.md b/docs/subsystems/slash-commands.mdindex bf2501a4b70..c6ae26209ed 100644--- a/docs/subsystems/slash-commands.md+++ b/docs/subsystems/slash-commands.md@@ -6,7 +6,7 @@ and both these terms are often user interchangeably.Currently supported slash commands are:-- `/day` and `/night` to change the UI theme+- `/light` and `/dark` to change the UI theme- `/ping` to ping to server and get back the time for the roundtrip. Mainly for testing.- `/fluid-width` and `/fixed-width` to toggle that setting@@ -28,8 +28,8 @@ basically just acks the client. The client then computesthe round trip time and shows a little message abovethe compose box that the user can see and then dismiss.-For commands like "/day" and "/night", the server does-a little bit of logic to toggle the user's night mode+For commands like "/light" and "/dark", the server does+a little bit of logic to toggle the user's dark modesetting, and this is largely done inside `zcommand.py`.The server sends a very basic response, and thenthe client actually changes the display colors. Thediff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.jsindex be21a2be979..9e180b10a6d 100644--- a/frontend_tests/node_tests/composebox_typeahead.js+++ b/frontend_tests/node_tests/composebox_typeahead.js@@ -154,14 +154,28 @@ const emoji_list = Array.from(emojis_by_name.values(), (emoji_dict) => {const me_slash = {name: "me",+ aliases: "",text: "translated: /me is excited (Display action text)",};const my_slash = {name: "my",+ aliases: "",text: "translated: /my (Test)",};+const dark_slash = {+ name: "dark",+ aliases: "night",+ text: "translated: /dark (Toggle dark mode)",+};++const light_slash = {+ name: "light",+ aliases: "day",+ text: "translated: /light (Toggle light mode)",+};+const sweden_stream = {name: "Sweden",description: "Cold, mountains and home decor.",@@ -485,6 +499,30 @@ test("content_typeahead_selected", ({override}) => {expected_value = "/me ";assert.equal(actual_value, expected_value);+ fake_this.query = "/da";+ fake_this.completing = "slash";+ actual_value = ct.content_typeahead_selected.call(fake_this, dark_slash);+ expected_value = "/dark ";+ assert.equal(actual_value, expected_value);++ fake_this.query = "/ni";+ fake_this.completing = "slash";+ actual_value = ct.content_typeahead_selected.call(fake_this, dark_slash);+ expected_value = "/dark ";+ assert.equal(actual_value, expected_value);++ fake_this.query = "/li";+ fake_this.completing = "slash";+ actual_value = ct.content_typeahead_selected.call(fake_this, light_slash);+ expected_value = "/light ";+ assert.equal(actual_value, expected_value);++ fake_this.query = "/da";+ fake_this.completing = "slash";+ actual_value = ct.content_typeahead_selected.call(fake_this, light_slash);+ expected_value = "/light ";+ assert.equal(actual_value, expected_value);+// streamfake_this.completing = "stream";let warned_for_stream_link = false;@@ -948,6 +986,11 @@ test("initialize", ({override, mock_template}) => {expected_value = [me_slash, my_slash];assert.deepEqual(actual_value, expected_value);+ fake_this = {completing: "slash", token: "da"};+ actual_value = sort_items(fake_this, [dark_slash, light_slash]);+ expected_value = [dark_slash, light_slash];+ assert.deepEqual(actual_value, expected_value);+fake_this = {completing: "stream", token: "de"};actual_value = sort_items(fake_this, [sweden_stream, denmark_stream]);expected_value = [denmark_stream, sweden_stream];@@ -1520,6 +1563,10 @@ test("typeahead_results", () => {// Autocomplete by slash commands.assert_slash_matches("me", [me_slash]);+ assert_slash_matches("dark", [dark_slash]);+ assert_slash_matches("night", [dark_slash]);+ assert_slash_matches("light", [light_slash]);+ assert_slash_matches("day", [light_slash]);// Autocomplete stream by stream name or stream description.assert_stream_matches("den", [denmark_stream, sweden_stream]);diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.jsindex 238ba4baee2..da5155f1e80 100644--- a/static/js/composebox_typeahead.js+++ b/static/js/composebox_typeahead.js@@ -118,7 +118,7 @@ function get_slash_matcher(query) {query = typeahead.clean_query_lowercase(query);return function (item) {- return typeahead.query_matches_source_attrs(query, item, ["name"], " ");+ return typeahead.query_matches_source_attrs(query, item, ["name", "aliases"], " ");};}@@ -393,40 +393,39 @@ function should_show_custom_query(query, items) {export const slash_commands = [{- text: $t({defaultMessage: "/dark (Toggle night mode)"}),+ text: $t({defaultMessage: "/dark (Toggle dark mode)"}),name: "dark",- },- {- text: $t({defaultMessage: "/day (Toggle day mode)"}),- name: "day",+ aliases: "night",},{text: $t({defaultMessage: "/fixed-width (Toggle fixed width mode)"}),name: "fixed-width",+ aliases: "",},{text: $t({defaultMessage: "/fluid-width (Toggle fluid width mode)"}),name: "fluid-width",+ aliases: "",},{- text: $t({defaultMessage: "/light (Toggle day mode)"}),+ text: $t({defaultMessage: "/light (Toggle light mode)"}),name: "light",+ aliases: "day",},{text: $t({defaultMessage: "/me is excited (Display action text)"}),name: "me",- },- {- text: $t({defaultMessage: "/night (Toggle night mode)"}),- name: "night",+ aliases: "",},{text: $t({defaultMessage: "/poll Where should we go to lunch today? (Create a poll)"}),name: "poll",+ aliases: "",},{text: $t({defaultMessage: "/todo (Create a todo list)"}),name: "todo",+ aliases: "",},];diff --git a/static/js/zcommand.js b/static/js/zcommand.jsindex d422ff950ef..3a86c0b8b3e 100644--- a/static/js/zcommand.js+++ b/static/js/zcommand.js@@ -74,8 +74,8 @@ export function enter_day_mode() {command: "/night",});},- title_text: $t({defaultMessage: "Day mode"}),- undo_button_text: $t({defaultMessage: "Night"}),+ title_text: $t({defaultMessage: "Light mode"}),+ undo_button_text: $t({defaultMessage: "Dark mode"}),});},});@@ -96,8 +96,8 @@ export function enter_night_mode() {command: "/day",});},- title_text: $t({defaultMessage: "Night mode"}),- undo_button_text: $t({defaultMessage: "Day"}),+ title_text: $t({defaultMessage: "Dark mode"}),+ undo_button_text: $t({defaultMessage: "Light mode"}),});},});diff --git a/zerver/lib/zcommand.py b/zerver/lib/zcommand.pyindex 4cad092932f..457c40cce23 100644--- a/zerver/lib/zcommand.py+++ b/zerver/lib/zcommand.py@@ -34,22 +34,22 @@ def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any]return {}elif command == "night":if user_profile.color_scheme == UserProfile.COLOR_SCHEME_NIGHT:- return dict(msg="You are still in night mode.")+ return dict(msg="You are still in dark mode.")return dict(msg=change_mode_setting(- command=command,- switch_command="day",+ command="dark",+ switch_command="light",setting="color_scheme",setting_value=UserProfile.COLOR_SCHEME_NIGHT,))elif command == "day":if user_profile.color_scheme == UserProfile.COLOR_SCHEME_LIGHT:- return dict(msg="You are still in day mode.")+ return dict(msg="You are still in light mode.")return dict(msg=change_mode_setting(- command=command,- switch_command="night",+ command="light",+ switch_command="dark",setting="color_scheme",setting_value=UserProfile.COLOR_SCHEME_LIGHT,)diff --git a/zerver/tests/test_zcommand.py b/zerver/tests/test_zcommand.pyindex 4a8bade7ec6..0ab8c39b921 100644--- a/zerver/tests/test_zcommand.py+++ b/zerver/tests/test_zcommand.py@@ -30,11 +30,11 @@ class ZcommandTest(ZulipTestCase):payload = dict(command="/night")result = self.client_post("/json/zcommand", payload)self.assert_json_success(result)- self.assertIn("Changed to night", result.json()["msg"])+ self.assertIn("Changed to dark mode", result.json()["msg"])result = self.client_post("/json/zcommand", payload)self.assert_json_success(result)- self.assertIn("still in night mode", result.json()["msg"])+ self.assertIn("still in dark mode", result.json()["msg"])def test_day_zcommand(self) -> None:self.login("hamlet")@@ -45,11 +45,11 @@ class ZcommandTest(ZulipTestCase):payload = dict(command="/day")result = self.client_post("/json/zcommand", payload)self.assert_json_success(result)- self.assertIn("Changed to day", result.json()["msg"])+ self.assertIn("Changed to light mode", result.json()["msg"])result = self.client_post("/json/zcommand", payload)self.assert_json_success(result)- self.assertIn("still in day mode", result.json()["msg"])+ self.assertIn("still in light mode", result.json()["msg"])def test_fluid_zcommand(self) -> None:self.login("hamlet")