From ea543e90e1606779f2675072affaac3cecf7e561 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 3 May 2014 21:22:14 +0200 Subject: [PATCH] Added ACTION messages --- README.md | 1 + client/css/style.css | 7 ++++++ client/js/chat.js | 11 ++++------ lib/server.js | 51 ++++++++++++++++++++++++++++++++------------ 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3c971daf..a8d8f1e4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ These are the commands currently implemented: - `/join` - `/kick` - `/leave` +- `/me` - `/mode` - `/msg` - `/nick` diff --git a/client/css/style.css b/client/css/style.css index 4aa80d17..63fe5f86 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -164,6 +164,13 @@ button::-moz-focus-inner { #chat .topic .user { color: #e74c3c; } +#chat .action, +#chat .action .user { + color: #f39c12; +} +#chat .action .user:before { + content: '* '; +} #chat .show-more { display: none; margin: 6px 8px 4px 148px; diff --git a/client/js/chat.js b/client/js/chat.js index 78b51459..714c205a 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -119,14 +119,11 @@ $(function() { chat.on("append", ".messages", function() { var messages = $(this); var id = messages.closest(".window").find(".form").data("target"); - var badge = $("#channel-" + id + ":not(.active)") - .find(".badge"); - console.log(badge); - if (badge.length == 0) { - return; + var badge = $("#channel-" + id + ":not(.active) .badge"); + if (badge.length != 0) { + var i = (parseInt(badge.html()) || 0) + 1; + badge.html(i); } - var i = (parseInt(badge.html()) || 0) + 1; - badge.html(i); }); chat.on("click", ".show-more .btn", function() { diff --git a/lib/server.js b/lib/server.js index 27ee5eff..edd1709d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -133,23 +133,20 @@ function input(data) { ); case "msg": var user; - var text = _.tail(args, 2).join(" "); + var text = args.slice(2).join(" "); if (client) { user = client.me; client.send(args[1], text); } - var chan = _.findWhere(network.channels, {name: args[1]}); - if (typeof chan !== "undefined") { - var msg = new Msg({ - from: user, - text: text, - }); - chan.messages.push(msg) - sockets.emit("msg", { - id: chan.id, - msg: msg, - }); - } + var msg = new Msg({ + from: user, + text: text, + }); + chan.messages.push(msg) + sockets.emit("msg", { + id: chan.id, + msg: msg, + }); break; case "notice": @@ -158,6 +155,28 @@ function input(data) { } break; + case "me": + if (!args[1]) { + break; + } + var user; + var text = args.slice(1).join(" "); + if (client) { + user = client.me; + client.action(chan.name, text); + } + var msg = new Msg({ + type: "action", + from: user, + text: text, + }); + chan.messages.push(msg) + sockets.emit("msg", { + id: chan.id, + msg: msg, + }); + break; + case "server": case "connect": if (args[1]) { @@ -360,9 +379,13 @@ function event(e, data) { } var type = ""; var text = data.message; + if (text.split(" ")[0] === "\u0001ACTION") { + type = "action"; + text = text.replace(/\u0001|ACTION/g, ""); + } var network = this; text.split(' ').forEach(function(w) { - if (w.indexOf(network.client.me) == 0) type = "highlight"; + if (w.indexOf(network.client.me) == 0) type += " highlight"; }); var msg = new Msg({ type: type || "normal",