thelounge/client/js/commands/join.js
Pavel Djundik 2f635069e0 Move vuex state to a separate file and reorganize some code
Co-Authored-By: Tim Miller-Williams <timmw@users.noreply.github.com>
2019-11-25 20:12:54 +02:00

49 lines
1.2 KiB
JavaScript

"use strict";
exports.input = function(args) {
const utils = require("../utils");
const socket = require("../socket");
const {vueApp} = require("../vue");
const store = require("../store").default;
if (args.length > 0) {
let channels = args[0];
if (channels.length > 0) {
const chanTypes = store.state.activeChannel.network.serverOptions.CHANTYPES;
const channelList = args[0].split(",");
if (chanTypes && chanTypes.length > 0) {
for (let c = 0; c < channelList.length; c++) {
if (!chanTypes.includes(channelList[c][0])) {
channelList[c] = chanTypes[0] + channelList[c];
}
}
}
channels = channelList.join(",");
const chan = utils.findCurrentNetworkChan(channels);
if (chan) {
vueApp.switchToChannel(chan);
} else {
socket.emit("input", {
text: `/join ${channels} ${args.length > 1 ? args[1] : ""}`,
target: store.state.activeChannel.channel.id,
});
return true;
}
}
} else if (store.state.activeChannel.channel.type === "channel") {
// If `/join` command is used without any arguments, re-join current channel
socket.emit("input", {
target: store.state.activeChannel.channel.id,
text: `/join ${store.state.activeChannel.channel.name}`,
});
return true;
}
};