diff --git a/client/components/ChatInput.vue b/client/components/ChatInput.vue index 704beda4..aa589a1a 100644 --- a/client/components/ChatInput.vue +++ b/client/components/ChatInput.vue @@ -56,7 +56,7 @@ import Mousetrap from "mousetrap"; import {wrapCursor} from "undate"; import autocompletion from "../js/autocompletion"; -import commands from "../js/commands/index"; +import {commands} from "../js/commands/index"; import socket from "../js/socket"; import upload from "../js/upload"; import eventbus from "../js/eventbus"; @@ -185,10 +185,7 @@ export default defineComponent({ return false; } - if ( - Object.prototype.hasOwnProperty.call(commands, cmd) && - commands[cmd].input(args) - ) { + if (Object.prototype.hasOwnProperty.call(commands, cmd) && commands[cmd](args)) { return false; } } diff --git a/client/js/commands/collapse.ts b/client/js/commands/collapse.ts index 953ba98b..5c377c0c 100644 --- a/client/js/commands/collapse.ts +++ b/client/js/commands/collapse.ts @@ -1,9 +1,9 @@ import socket from "../socket"; import {store} from "../store"; -function input() { +export function input(): boolean { if (!store.state.activeChannel) { - return; + return false; } const messageIds: number[] = []; @@ -34,5 +34,3 @@ function input() { return true; } - -export default {input}; diff --git a/client/js/commands/expand.ts b/client/js/commands/expand.ts index 36290359..dbea4510 100644 --- a/client/js/commands/expand.ts +++ b/client/js/commands/expand.ts @@ -1,9 +1,9 @@ import socket from "../socket"; import {store} from "../store"; -function input() { +export function input(): boolean { if (!store.state.activeChannel) { - return; + return false; } const messageIds: number[] = []; @@ -34,5 +34,3 @@ function input() { return true; } - -export default {input}; diff --git a/client/js/commands/index.ts b/client/js/commands/index.ts index 247ed3e3..dd0a0181 100644 --- a/client/js/commands/index.ts +++ b/client/js/commands/index.ts @@ -1,19 +1,11 @@ -// Taken from views/index.js +import {input as collapse} from "./collapse"; +import {input as expand} from "./expand"; +import {input as join} from "./join"; +import {input as search} from "./search"; -// This creates a version of `require()` in the context of the current -// directory, so we iterate over its content, which is a map statically built by -// Webpack. -// Second argument says it's recursive, third makes sure we only load javascript. -const commands = require.context("./", true, /\.ts$/); - -export default commands.keys().reduce>((acc, path) => { - const command = path.substring(2, path.length - 3); - - if (command === "index") { - return acc; - } - - acc[command] = commands(path).default; - - return acc; -}, {}); +export const commands = { + collapse: collapse, + expand: expand, + join: join, + search: search, +}; diff --git a/client/js/commands/join.ts b/client/js/commands/join.ts index 64776e64..a66a9291 100644 --- a/client/js/commands/join.ts +++ b/client/js/commands/join.ts @@ -1,8 +1,9 @@ import socket from "../socket"; import {store} from "../store"; import {switchToChannel} from "../router"; +import {ChanType} from "../../../shared/types/chan"; -function input(args: string[]) { +export function input(args: string[]): boolean { if (args.length > 0) { let channels = args[0]; @@ -35,7 +36,7 @@ function input(args: string[]) { return true; } } - } else if (store.state.activeChannel?.channel.type === "channel") { + } else if (store.state.activeChannel?.channel.type === ChanType.CHANNEL) { // If `/join` command is used without any arguments, re-join current channel socket.emit("input", { target: store.state.activeChannel.channel.id, @@ -44,6 +45,6 @@ function input(args: string[]) { return true; } -} -export default {input}; + return false; +} diff --git a/client/js/commands/search.ts b/client/js/commands/search.ts index b6231725..5819b845 100644 --- a/client/js/commands/search.ts +++ b/client/js/commands/search.ts @@ -1,7 +1,7 @@ import {store} from "../store"; import {router} from "../router"; -function input(args: string[]) { +export function input(args: string[]): boolean { if (!store.state.settings.searchEnabled) { return false; } @@ -23,5 +23,3 @@ function input(args: string[]) { return true; } - -export default {input};