From 97705bc5d0894f85da5045d1e038548ffa982fa3 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 29 Oct 2014 23:47:04 +0000 Subject: [PATCH] Better formatting of non-privmsg --- app/network.js | 22 +++++++++++--------- app/room.js | 45 +++++++++++++++++++++++++++++++++------- src/wirc.cgi/wirc.cgi.go | 6 +++--- src/wirc/wirc.go | 3 ++- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/app/network.js b/app/network.js index c0d64bc..edd2a3f 100644 --- a/app/network.js +++ b/app/network.js @@ -20,15 +20,16 @@ function networkConnect(network, baseURL, authtok) { } function handleEventSourceLine(line) { - var lhs = line.split(" :", 1)[0] - var parts = lhs.split(' ') - var timestamp = new Date(parts[0] * 1000); + var lhs = line.split(" :", 1)[0]; + var parts = lhs.split(' '); + + var timestamp = new Date(parts[0] * 1000); var fullSender = parts[1]; - var command = parts[2].toLowerCase(); - var sender = parts[3]; - var forum = parts[4]; - var args = parts.slice(5); - var txt = line.substr(lhs.length + 2); + var command = parts[2].toLowerCase(); + var sender = parts[3]; + var forum = parts[4]; + var args = parts.slice(5); + var txt = line.substr(lhs.length + 2); var room = rooms[forum]; if (! room) { @@ -36,7 +37,7 @@ function networkConnect(network, baseURL, authtok) { } // XXX: Handle differently based on command - room.addMessage(timestamp, command, sender, txt); + room.addMessage(timestamp, fullSender, command, sender, args, txt); } function handleEventSourceMessage(oEvent) { @@ -50,7 +51,8 @@ function networkConnect(network, baseURL, authtok) { function handleEventSourceError(oEvent) { timestamp = new Date(); - messageHandler(timestamp, null, "ERROR", null, null, [], null); + roomElement.addMessage(timestamp, ".", "fault", ".", [], "Unable to open events feed (permissions problem on server?)"); + console.log(oEvent); } element.send = function(target, text) { diff --git a/app/room.js b/app/room.js index 3f087c7..32891d7 100644 --- a/app/room.js +++ b/app/room.js @@ -34,7 +34,7 @@ function purtify(text) { return txtElement; } -function kiboze(busted) { +function kiboze(this_is_currently_busted) { if ((kiboze) || (-1 != text.search(kibozeRe))) { var k = document.getElementById("kiboze"); @@ -50,6 +50,7 @@ function kiboze(busted) { } } + var visibleRoom; function newRoom(element, network, name, maxSize) { @@ -59,8 +60,38 @@ function newRoom(element, network, name, maxSize) { maxSize = 500; } + function purtify(fullSender, command, sender, args, txt) { + var txtElement = document.createElement("span"); + var msg = chrome.i18n.getMessage(command + "Command", [fullSender, command, sender, name, args, txt]); + if (! msg) { + msg = chrome.i18n.getMessage("unknownCommand", [fullSender, command, sender, name, String(args), txt]); + } - element.addMessage = function(timestamp, command, source, content) { + var rhs = msg; + var match; + + while ((match = urlRe.exec(rhs)) != null) { + var before = rhs.substr(0, match.index); + var a = document.createElement("a"); + var href = match[0]; + + if (href.indexOf("hxx") == 0) { + href = "htt" + href.substr(3); + } + a.href = href + a.target = "_blank"; + a.appendChild(document.createTextNode(match[0])); + txtElement.appendChild(document.createTextNode(before)); + txtElement.appendChild(a); + rhs = rhs.substr(match.index + match[0].length); + } + txtElement.appendChild(document.createTextNode(rhs)); + + return txtElement; + } + + + element.addMessage = function(timestamp, fullSender, command, sender, args, txt) { var message = getTemplate("message"); var eTimestamp = message.getElementsByClassName("timestamp")[0]; @@ -69,19 +100,19 @@ function newRoom(element, network, name, maxSize) { message.classList.add("update"); message.classList.add(command); - if (source == ".") { + if (sender == ".") { message.classList.add("self"); } eTimestamp.textContent = timestamp.toLocaleTimeString(); - eSource.textContent = source; - eSource.setAttribute("colornumber", djbhash(source) % 31); - eContent.appendChild(purtify(content)); + eSource.textContent = sender; + eSource.setAttribute("colornumber", djbhash(sender) % 31); + eContent.appendChild(purtify(fullSender, command, sender, args, txt)); messages.appendChild(message); while (messages.childNodes.length > maxSize) { - messages.removeChild(element.firstChild); + messages.removeChild(messages.firstChild); } lastmsg = message; diff --git a/src/wirc.cgi/wirc.cgi.go b/src/wirc.cgi/wirc.cgi.go index 3ba0398..73585d6 100644 --- a/src/wirc.cgi/wirc.cgi.go +++ b/src/wirc.cgi/wirc.cgi.go @@ -73,16 +73,16 @@ func tail(w http.ResponseWriter, filename string, pos int64) { pos += int64(len(t)) + 1 // XXX: this breaks if we ever see \r\n parts := strings.Split(t, " ") - if (len(parts) >= 4) && (parts[3] == "NEXTLOG") { + if (len(parts) >= 4) && (parts[2] == "NEXTLOG") { watcher.Remove(filepath) filename = parts[4] filepath = path.Join(NetworkDir, filename) f.Close() - f, err = os.Open(filename) + f, err = os.Open(filepath) if err != nil { log.Fatal(err) } - watcher.Add(filename) + watcher.Add(filepath) } fmt.Fprintf(w, "data: %s\n", t) printid = true diff --git a/src/wirc/wirc.go b/src/wirc/wirc.go index 1af62ec..2a48230 100644 --- a/src/wirc/wirc.go +++ b/src/wirc/wirc.go @@ -114,6 +114,7 @@ func parse(v string) (Message, error) { m.FullSender = "." m.Forum = "." m.Sender = "." + m.Args = parts parts = strings.Split(lhs, " ") if parts[0][0] == ':' { @@ -220,7 +221,7 @@ func usage() { func main() { dotls := flag.Bool("notls", true, "Disable TLS security") outqdir := flag.String("outq", "outq", "Output queue directory") - flag.UintVar(&maxlogsize, "logsize", 8000, "Log entries before rotating") + flag.UintVar(&maxlogsize, "logsize", 1000, "Log entries before rotating") flag.StringVar(&gecos, "gecos", "Bob The Merry Slug", "Gecos entry (full name)") flag.Parse()