Disable /search and hide help item if searching is disabled

This commit is contained in:
Max Leiter 2021-11-15 13:57:20 -08:00
parent 3cec329e3b
commit 40a5ee70b6
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA
5 changed files with 21 additions and 34 deletions

View file

@ -723,7 +723,7 @@
</div>
</div>
<div class="help-item">
<div v-if="$store.state.settings.searchEnabled" class="help-item">
<div class="subject">
<code>/search query</code>
</div>

View file

@ -312,23 +312,18 @@ function completeNicks(word, isFuzzy) {
}
function getCommands() {
const cmds = constants.commands.slice();
let cmds = constants.commands.slice();
if (store.state.settings.searchEnabled === false) {
const search = cmds.indexOf("/search");
if (search !== -1) {
cmds.splice(search, 1);
}
if (!store.state.settings.searchEnabled) {
cmds = cmds.filter((c) => c !== "/search");
}
return cmds;
}
function completeCommands(word) {
const words = getCommands();
return fuzzyGrep(word, words);
const commands = getCommands();
return fuzzyGrep(word, commands);
}
function completeChans(word) {

View file

@ -2,29 +2,22 @@
import store from "../store";
import {router} from "../router";
const Msg = require("../../../src/models/msg");
function input(args) {
const {channel} = store.state.activeChannel;
if (!store.state.settings.searchEnabled) {
const message = new Msg({
type: Msg.Type.ERROR,
text: "Search is currently not enabled.",
});
channel.messages.push(message);
} else {
router.push({
name: "SearchResults",
params: {
id: channel.id,
},
query: {
q: args.join(" "),
},
});
return false;
}
router.push({
name: "SearchResults",
params: {
id: store.state.activeChannel.channel.id,
},
query: {
q: args.join(" "),
},
});
return true;
}

View file

@ -1,12 +1,8 @@
const constants = require("../constants");
import localCommands from "../commands/index";
import socket from "../socket";
const clientCommands = Object.keys(localCommands).map((cmd) => `/${cmd}`);
socket.on("commands", function (commands) {
if (commands) {
const cmds = [...new Set(commands.concat(clientCommands))];
constants.commands = cmds.sort();
constants.commands = commands;
}
});

View file

@ -1,3 +1,5 @@
const clientSideCommands = ["/collapse", "/expand", "/search"];
const passThroughCommands = [
"/as",
"/bs",
@ -45,6 +47,7 @@ const getCommands = () =>
Array.from(userInputs.keys())
.concat(Array.from(pluginCommands.keys()))
.map((command) => `/${command}`)
.concat(clientSideCommands)
.concat(passThroughCommands)
.sort();