mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
Add option to auto-join channels
This commit is contained in:
parent
deb82c7abe
commit
67ca372657
2 changed files with 35 additions and 8 deletions
|
@ -4,6 +4,7 @@ var server = {
|
|||
realname: null,
|
||||
nick: null,
|
||||
pass: null,
|
||||
autojoin: [],
|
||||
};
|
||||
|
||||
var ws = null;
|
||||
|
@ -182,13 +183,13 @@ function connect() {
|
|||
console.log("Connection opened");
|
||||
|
||||
if (server.pass) {
|
||||
ws.send(formatMessage({ command: "PASS", params: [server.pass] }));
|
||||
sendMessage({ command: "PASS", params: [server.pass] });
|
||||
}
|
||||
ws.send(formatMessage({ command: "NICK", params: [server.nick] }));
|
||||
ws.send(formatMessage({
|
||||
sendMessage({ command: "NICK", params: [server.nick] });
|
||||
sendMessage({
|
||||
command: "USER",
|
||||
params: [server.username, "0", "*", server.realname],
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
|
@ -199,6 +200,13 @@ function connect() {
|
|||
case RPL_WELCOME:
|
||||
console.log("Registration complete");
|
||||
connectElt.style.display = "none";
|
||||
|
||||
if (server.autojoin.length > 0) {
|
||||
sendMessage({
|
||||
command: "JOIN",
|
||||
params: [server.autojoin.join(",")],
|
||||
});
|
||||
}
|
||||
break;
|
||||
case ERR_PASSWDMISMATCH:
|
||||
console.error("Password mismatch");
|
||||
|
@ -220,10 +228,13 @@ function connect() {
|
|||
break;
|
||||
case "JOIN":
|
||||
var channel = msg.params[0];
|
||||
if (msg.prefix.name == server.nick) {
|
||||
createBuffer(channel);
|
||||
} else {
|
||||
createBuffer(channel).addMessage(msg);
|
||||
var buf = createBuffer(channel);
|
||||
if (msg.prefix.name != server.nick) {
|
||||
buf.addMessage(msg);
|
||||
}
|
||||
if (channel == server.autojoin[0]) {
|
||||
// TODO: only switch once right after connect
|
||||
switchBuffer(buf);
|
||||
}
|
||||
break;
|
||||
case "PART":
|
||||
|
@ -353,6 +364,15 @@ connectFormElt.onsubmit = function(event) {
|
|||
server.username = connectFormElt.elements.username.value || server.nick;
|
||||
server.realname = connectFormElt.elements.realname.value || server.nick;
|
||||
|
||||
server.autojoin = [];
|
||||
connectFormElt.elements.autojoin.value.split(",").forEach(function(ch) {
|
||||
ch = ch.trim();
|
||||
if (!ch) {
|
||||
return;
|
||||
}
|
||||
server.autojoin.push(ch);
|
||||
});
|
||||
|
||||
if (localStorage) {
|
||||
if (connectFormElt.elements["remember-me"].checked) {
|
||||
localStorage.setItem("server", JSON.stringify(server));
|
||||
|
@ -393,4 +413,7 @@ if (localStorage && localStorage.getItem("server")) {
|
|||
connectFormElt.elements.url.value = params.server;
|
||||
document.querySelector("#connect-url-container").style.display = "none";
|
||||
}
|
||||
if (params.channels) {
|
||||
connectFormElt.elements.autojoin.value = params.channels;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,10 @@
|
|||
|
||||
<label for="connect-realname">Real name:</label><br/>
|
||||
<input type="text" name="realname" id="connect-realname" placeholder="Same as nickname"/>
|
||||
<br/><br/>
|
||||
|
||||
<label for="connect-autojoin">Auto-join channels:</label><br/>
|
||||
<input type="text" name="autojoin" id="connect-autojoin" placeholder="Comma-separated list of channels"/>
|
||||
<br/>
|
||||
</details>
|
||||
|
||||
|
|
Loading…
Reference in a new issue