From 9a3409e970cd994c09a003b65dd9fb7e522d3684 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 10 Jun 2020 19:24:03 +0200 Subject: [PATCH] Add support for TOPIC messages --- assets/client.js | 27 ++++++++++++++++++++++++++- assets/irc.js | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/assets/client.js b/assets/client.js index bf1844e..8e6205c 100644 --- a/assets/client.js +++ b/assets/client.js @@ -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); } diff --git a/assets/irc.js b/assets/irc.js index 42ea212..8c6112a 100644 --- a/assets/irc.js +++ b/assets/irc.js @@ -1,4 +1,5 @@ const RPL_WELCOME = "001"; +const RPL_TOPIC = "332"; const ERR_PASSWDMISMATCH = "464"; function parsePrefix(s) {