Add support for TOPIC messages

This commit is contained in:
Simon Ser 2020-06-10 19:24:03 +02:00
parent e7a0274172
commit 9a3409e970
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 27 additions and 1 deletions

View file

@ -92,6 +92,10 @@ function createMessageElement(msg) {
line.appendChild(createNickElement(msg.prefix.name));
line.appendChild(document.createTextNode(" has left"));
break;
case "TOPIC":
line.appendChild(createNickElement(msg.prefix.name));
line.appendChild(document.createTextNode(" changed the topic to: " + msg.params[1]));
break;
default:
line.appendChild(document.createTextNode(" " + msg.command + " " + msg.params.join(" ")));
}
@ -118,8 +122,9 @@ function createBuffer(name) {
var buf = {
name: name,
li: li,
messages: [],
readOnly: false,
topic: null,
messages: [],
addMessage: function(msg) {
buf.messages.push(msg);
@ -208,6 +213,16 @@ function connect() {
});
}
break;
case RPL_TOPIC:
var channel = msg.params[1];
var topic = msg.params[2];
var buf = buffers[channel];
if (!buf) {
break;
}
buf.topic = topic;
break;
case ERR_PASSWDMISMATCH:
console.error("Password mismatch");
disconnect();
@ -248,6 +263,16 @@ function connect() {
}
// TODO: append message to all buffers the user is a member of
break;
case "TOPIC":
var channel = msg.params[0];
var topic = msg.params[1];
var buf = buffers[channel];
if (!buf) {
break;
}
buf.topic = topic;
buf.addMessage(msg);
break;
default:
serverBuffer.addMessage(msg);
}

View file

@ -1,4 +1,5 @@
const RPL_WELCOME = "001";
const RPL_TOPIC = "332";
const ERR_PASSWDMISMATCH = "464";
function parsePrefix(s) {