From 5eefa31400bf81b1143a32ac192ac15f9acfc64c Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 15 Mar 2014 17:14:05 +0100 Subject: [PATCH] Show errors in current window --- client/js/chat.js | 6 +++++- lib/server.js | 33 ++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/client/js/chat.js b/client/js/chat.js index 0a5072af..3d934780 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -59,8 +59,12 @@ $(function() { break; case "MESSAGES": + var message = data.data; + if (message.type == "error") { + target = target.parent().find(".active"); + } target = target.find(".messages"); - target.append(Mustache.render(messages, {messages: data.data})); + target.append(Mustache.render(messages, {messages: message})); break; } } diff --git a/lib/server.js b/lib/server.js index 0bce1190..a1c88678 100644 --- a/lib/server.js +++ b/lib/server.js @@ -231,10 +231,11 @@ function handleInput(input) { default: channel.get("messages").add( new models.Message({ - text: "Unknown command: `/" + cmd + "`", + text: cmd + " Unknown command", type: "error" }) ); + break; } } @@ -353,20 +354,22 @@ function handleEvent(argv) { var messages = channel.get("messages"); var user = users.findWhere({name: argv.nick}); - if (typeof user !== "undefined") { - user.set("name", argv.args[0]); - - users.sort(); - users.trigger( - "change", {}, users - ); - - messages.add(new models.Message({ - user: argv.nick, - text: "changed name to " + argv.args[0], - type: "nick" - })); + if (typeof user === "undefined") { + return; } + + user.set("name", argv.args[0]); + + users.sort(); + users.trigger( + "change", {}, users + ); + + messages.add(new models.Message({ + user: argv.nick, + text: "changed name to " + argv.args[0], + type: "nick" + })); }); if (argv.nick == network.get("nick")) { @@ -555,7 +558,7 @@ function handleEvent(argv) { var args = argv.args; channels.first().get("messages").add( new models.Message({ - text: args[args.length - 1], + text: args[args.length - 2].toUpperCase() + " " + args[args.length - 1], type: "error" }) );