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,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) {

View File

@ -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;

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
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

View File

@ -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()