Show join/leave messages

This commit is contained in:
Simon Ser 2020-04-25 23:00:49 +02:00
parent 14ac3617ce
commit cbf64e56a0
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -24,6 +24,18 @@ function djb2(s) {
return hash;
}
function createNickElement(name) {
var nick = document.createElement("a");
nick.href = "#";
nick.className = "nick nick-" + (djb2(name) % 16 + 1);
nick.innerText = name;
nick.onclick = function(event) {
event.preventDefault();
switchBuffer(createBuffer(name));
};
return nick;
}
function createMessageElement(msg) {
var date = new Date();
@ -49,15 +61,6 @@ function createMessageElement(msg) {
case "PRIVMSG":
var text = msg.params[1];
var nick = document.createElement("a");
nick.href = "#";
nick.className = "nick nick-" + (djb2(msg.prefix.name) % 16 + 1);
nick.innerText = msg.prefix.name;
nick.onclick = function(event) {
event.preventDefault();
switchBuffer(createBuffer(msg.prefix.name));
};
var actionPrefix = "\001ACTION ";
if (text.startsWith(actionPrefix) && text.endsWith("\001")) {
var action = text.slice(actionPrefix.length, -1);
@ -65,17 +68,25 @@ function createMessageElement(msg) {
line.className += " me-tell";
line.appendChild(document.createTextNode("* "));
line.appendChild(nick);
line.appendChild(createNickElement(msg.prefix.name));
line.appendChild(document.createTextNode(" " + action));
} else {
line.className += " talk";
line.appendChild(document.createTextNode("<"));
line.appendChild(nick);
line.appendChild(createNickElement(msg.prefix.name));
line.appendChild(document.createTextNode("> "));
line.appendChild(document.createTextNode(text));
}
break;
case "JOIN":
line.appendChild(createNickElement(msg.prefix.name));
line.appendChild(document.createTextNode(" has joined"));
break;
case "PART":
line.appendChild(createNickElement(msg.prefix.name));
line.appendChild(document.createTextNode(" has left"));
break;
default:
line.appendChild(document.createTextNode(" " + msg.command + " " + msg.params.join(" ")));
}
@ -191,8 +202,14 @@ ws.onmessage = function(event) {
var channel = msg.params[0];
if (msg.prefix.name == server.nick) {
createBuffer(channel);
} else {
createBuffer(channel).addMessage(msg);
}
break;
case "PART":
var channel = msg.params[0];
createBuffer(channel).addMessage(msg);
break;
default:
serverBuffer.addMessage(msg);
}