Better formatting of non-privmsg

This commit is contained in:
Neale Pickett 2014-10-29 23:47:04 +00:00
parent 01cfc318b1
commit 97705bc5d0
4 changed files with 55 additions and 21 deletions

View File

@ -20,8 +20,9 @@ function networkConnect(network, baseURL, authtok) {
} }
function handleEventSourceLine(line) { function handleEventSourceLine(line) {
var lhs = line.split(" :", 1)[0] var lhs = line.split(" :", 1)[0];
var parts = lhs.split(' ') var parts = lhs.split(' ');
var timestamp = new Date(parts[0] * 1000); var timestamp = new Date(parts[0] * 1000);
var fullSender = parts[1]; var fullSender = parts[1];
var command = parts[2].toLowerCase(); var command = parts[2].toLowerCase();
@ -36,7 +37,7 @@ function networkConnect(network, baseURL, authtok) {
} }
// XXX: Handle differently based on command // XXX: Handle differently based on command
room.addMessage(timestamp, command, sender, txt); room.addMessage(timestamp, fullSender, command, sender, args, txt);
} }
function handleEventSourceMessage(oEvent) { function handleEventSourceMessage(oEvent) {
@ -50,7 +51,8 @@ function networkConnect(network, baseURL, authtok) {
function handleEventSourceError(oEvent) { function handleEventSourceError(oEvent) {
timestamp = new Date(); 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) { element.send = function(target, text) {

View File

@ -34,7 +34,7 @@ function purtify(text) {
return txtElement; return txtElement;
} }
function kiboze(busted) { function kiboze(this_is_currently_busted) {
if ((kiboze) || (-1 != text.search(kibozeRe))) { if ((kiboze) || (-1 != text.search(kibozeRe))) {
var k = document.getElementById("kiboze"); var k = document.getElementById("kiboze");
@ -50,6 +50,7 @@ function kiboze(busted) {
} }
} }
var visibleRoom; var visibleRoom;
function newRoom(element, network, name, maxSize) { function newRoom(element, network, name, maxSize) {
@ -59,8 +60,38 @@ function newRoom(element, network, name, maxSize) {
maxSize = 500; 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 message = getTemplate("message");
var eTimestamp = message.getElementsByClassName("timestamp")[0]; var eTimestamp = message.getElementsByClassName("timestamp")[0];
@ -69,19 +100,19 @@ function newRoom(element, network, name, maxSize) {
message.classList.add("update"); message.classList.add("update");
message.classList.add(command); message.classList.add(command);
if (source == ".") { if (sender == ".") {
message.classList.add("self"); message.classList.add("self");
} }
eTimestamp.textContent = timestamp.toLocaleTimeString(); eTimestamp.textContent = timestamp.toLocaleTimeString();
eSource.textContent = source; eSource.textContent = sender;
eSource.setAttribute("colornumber", djbhash(source) % 31); eSource.setAttribute("colornumber", djbhash(sender) % 31);
eContent.appendChild(purtify(content)); eContent.appendChild(purtify(fullSender, command, sender, args, txt));
messages.appendChild(message); messages.appendChild(message);
while (messages.childNodes.length > maxSize) { while (messages.childNodes.length > maxSize) {
messages.removeChild(element.firstChild); messages.removeChild(messages.firstChild);
} }
lastmsg = message; lastmsg = message;

View File

@ -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 pos += int64(len(t)) + 1 // XXX: this breaks if we ever see \r\n
parts := strings.Split(t, " ") parts := strings.Split(t, " ")
if (len(parts) >= 4) && (parts[3] == "NEXTLOG") { if (len(parts) >= 4) && (parts[2] == "NEXTLOG") {
watcher.Remove(filepath) watcher.Remove(filepath)
filename = parts[4] filename = parts[4]
filepath = path.Join(NetworkDir, filename) filepath = path.Join(NetworkDir, filename)
f.Close() f.Close()
f, err = os.Open(filename) f, err = os.Open(filepath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
watcher.Add(filename) watcher.Add(filepath)
} }
fmt.Fprintf(w, "data: %s\n", t) fmt.Fprintf(w, "data: %s\n", t)
printid = true printid = true

View File

@ -114,6 +114,7 @@ func parse(v string) (Message, error) {
m.FullSender = "." m.FullSender = "."
m.Forum = "." m.Forum = "."
m.Sender = "." m.Sender = "."
m.Args = parts
parts = strings.Split(lhs, " ") parts = strings.Split(lhs, " ")
if parts[0][0] == ':' { if parts[0][0] == ':' {
@ -220,7 +221,7 @@ func usage() {
func main() { func main() {
dotls := flag.Bool("notls", true, "Disable TLS security") dotls := flag.Bool("notls", true, "Disable TLS security")
outqdir := flag.String("outq", "outq", "Output queue directory") 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.StringVar(&gecos, "gecos", "Bob The Merry Slug", "Gecos entry (full name)")
flag.Parse() flag.Parse()