diff --git a/client/js/autocompletion.js b/client/js/autocompletion.js index cc626fb7..8fa83e29 100644 --- a/client/js/autocompletion.js +++ b/client/js/autocompletion.js @@ -6,6 +6,7 @@ import Mousetrap from "mousetrap"; import {Textcomplete, Textarea} from "textcomplete"; import fuzzy from "fuzzy"; +import commands from "./commands/index"; import emojiMap from "./helpers/simplemap.json"; import store from "./store"; @@ -311,8 +312,19 @@ function completeNicks(word, isFuzzy) { return users.filter((w) => !w.toLowerCase().indexOf(word)); } +function getCommands() { + const clientCommands = Object.keys(commands).map((cmd) => `/${cmd}`); + const cmds = [...new Set(Array.from(constants.commands).concat(clientCommands))]; + + if (!store.state.settings.searchEnabled) { + cmds.pop("/search"); + } + + return cmds.sort(); +} + function completeCommands(word) { - const words = constants.commands.slice(); + const words = getCommands().slice(); return fuzzyGrep(word, words); } diff --git a/src/plugins/inputs/index.js b/src/plugins/inputs/index.js index 112615b5..6fc5f5f7 100644 --- a/src/plugins/inputs/index.js +++ b/src/plugins/inputs/index.js @@ -1,5 +1,3 @@ -const clientSideCommands = ["/collapse", "/expand"]; - const passThroughCommands = [ "/as", "/bs", @@ -43,19 +41,12 @@ const userInputs = [ const pluginCommands = new Map(); -const getCommands = (client) => { - const commands = Array.from(userInputs.keys()) +const getCommands = () => + Array.from(userInputs.keys()) .concat(Array.from(pluginCommands.keys())) .map((command) => `/${command}`) - .concat(clientSideCommands) - .concat(passThroughCommands); - - if (client.messageProvider !== undefined) { - commands.push("/search"); - } - - return commands.sort(); -}; + .concat(passThroughCommands) + .sort(); const addPluginCommand = (packageInfo, command, func) => { func.packageInfo = packageInfo; diff --git a/src/server.js b/src/server.js index 880d6e7c..f50ee078 100644 --- a/src/server.js +++ b/src/server.js @@ -692,7 +692,7 @@ function initializeClient(socket, client, token, lastMessage, openChannel) { ), token: tokenToSend, }); - socket.emit("commands", inputs.getCommands(client)); + socket.emit("commands", inputs.getCommands()); }; if (Helper.config.public) { diff --git a/test/plugins/inputs/indexTest.js b/test/plugins/inputs/indexTest.js index 313bf7ca..75cef0ba 100644 --- a/test/plugins/inputs/indexTest.js +++ b/test/plugins/inputs/indexTest.js @@ -4,34 +4,16 @@ const expect = require("chai").expect; const inputs = require("../../../src/plugins/inputs"); describe("inputs", function () { - const client = { - messageProvider: undefined, - }; - const clientWithProvider = { - ...client, - messageProvider: true, - }; - describe(".getCommands", function () { it("should return a non-empty array", function () { - expect(inputs.getCommands(client)).to.be.an("array").that.is.not.empty; + expect(inputs.getCommands()).to.be.an("array").that.is.not.empty; }); it("should only return strings with no whitespaces and starting with /", function () { - inputs.getCommands(client).forEach((command) => { + inputs.getCommands().forEach((command) => { expect(command).to.be.a("string").that.does.not.match(/\s/); expect(command[0]).to.equal("/"); }); }); - - it("should not include /search without a message provider", function () { - expect(inputs.getCommands(client)).to.be.an("array").that.does.not.contains("/search"); - }); - - it("should include /search with a message provider", function () { - expect(inputs.getCommands(clientWithProvider)) - .to.be.an("array") - .that.contains("/search"); - }); }); });