mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
Show join/leave messages
This commit is contained in:
parent
14ac3617ce
commit
cbf64e56a0
1 changed files with 28 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue