2018-07-10 07:49:23 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-16 17:24:03 +00:00
|
|
|
import socket from "../socket";
|
|
|
|
import store from "../store";
|
|
|
|
import {switchToChannel} from "../router";
|
2019-11-03 11:23:03 +00:00
|
|
|
|
2019-11-16 17:24:03 +00:00
|
|
|
function input(args) {
|
2018-09-25 16:52:22 +00:00
|
|
|
if (args.length > 0) {
|
2019-10-04 16:56:18 +00:00
|
|
|
let channels = args[0];
|
2018-07-10 07:49:23 +00:00
|
|
|
|
2019-10-04 16:56:18 +00:00
|
|
|
if (channels.length > 0) {
|
2019-11-02 19:40:59 +00:00
|
|
|
const chanTypes = store.state.activeChannel.network.serverOptions.CHANTYPES;
|
2019-10-04 16:56:18 +00:00
|
|
|
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(",");
|
|
|
|
|
2019-11-03 11:23:03 +00:00
|
|
|
const chan = store.getters.findChannelOnCurrentNetwork(channels);
|
2018-09-25 16:52:22 +00:00
|
|
|
|
|
|
|
if (chan) {
|
2019-11-11 19:18:55 +00:00
|
|
|
switchToChannel(chan);
|
2019-10-04 16:56:18 +00:00
|
|
|
} else {
|
|
|
|
socket.emit("input", {
|
|
|
|
text: `/join ${channels} ${args.length > 1 ? args[1] : ""}`,
|
2019-11-02 19:40:59 +00:00
|
|
|
target: store.state.activeChannel.channel.id,
|
2019-10-04 16:56:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
2018-09-25 16:52:22 +00:00
|
|
|
}
|
2018-07-10 07:49:23 +00:00
|
|
|
}
|
2019-11-02 19:40:59 +00:00
|
|
|
} else if (store.state.activeChannel.channel.type === "channel") {
|
2018-09-25 16:52:22 +00:00
|
|
|
// If `/join` command is used without any arguments, re-join current channel
|
2018-07-10 07:49:23 +00:00
|
|
|
socket.emit("input", {
|
2019-11-02 19:40:59 +00:00
|
|
|
target: store.state.activeChannel.channel.id,
|
|
|
|
text: `/join ${store.state.activeChannel.channel.name}`,
|
2018-07-10 07:49:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-16 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {input};
|