Added ACTION messages

This commit is contained in:
Mattias Erming 2014-05-03 21:22:14 +02:00
parent 880b9b4104
commit ea543e90e1
4 changed files with 49 additions and 21 deletions

View File

@ -10,6 +10,7 @@ These are the commands currently implemented:
- `/join` - `/join`
- `/kick` - `/kick`
- `/leave` - `/leave`
- `/me`
- `/mode` - `/mode`
- `/msg` - `/msg`
- `/nick` - `/nick`

View File

@ -164,6 +164,13 @@ button::-moz-focus-inner {
#chat .topic .user { #chat .topic .user {
color: #e74c3c; color: #e74c3c;
} }
#chat .action,
#chat .action .user {
color: #f39c12;
}
#chat .action .user:before {
content: '* ';
}
#chat .show-more { #chat .show-more {
display: none; display: none;
margin: 6px 8px 4px 148px; margin: 6px 8px 4px 148px;

View File

@ -119,14 +119,11 @@ $(function() {
chat.on("append", ".messages", function() { chat.on("append", ".messages", function() {
var messages = $(this); var messages = $(this);
var id = messages.closest(".window").find(".form").data("target"); var id = messages.closest(".window").find(".form").data("target");
var badge = $("#channel-" + id + ":not(.active)") var badge = $("#channel-" + id + ":not(.active) .badge");
.find(".badge"); if (badge.length != 0) {
console.log(badge); var i = (parseInt(badge.html()) || 0) + 1;
if (badge.length == 0) { badge.html(i);
return;
} }
var i = (parseInt(badge.html()) || 0) + 1;
badge.html(i);
}); });
chat.on("click", ".show-more .btn", function() { chat.on("click", ".show-more .btn", function() {

View File

@ -133,23 +133,20 @@ function input(data) {
); );
case "msg": case "msg":
var user; var user;
var text = _.tail(args, 2).join(" "); var text = args.slice(2).join(" ");
if (client) { if (client) {
user = client.me; user = client.me;
client.send(args[1], text); client.send(args[1], text);
} }
var chan = _.findWhere(network.channels, {name: args[1]}); var msg = new Msg({
if (typeof chan !== "undefined") { from: user,
var msg = new Msg({ text: text,
from: user, });
text: text, chan.messages.push(msg)
}); sockets.emit("msg", {
chan.messages.push(msg) id: chan.id,
sockets.emit("msg", { msg: msg,
id: chan.id, });
msg: msg,
});
}
break; break;
case "notice": case "notice":
@ -158,6 +155,28 @@ function input(data) {
} }
break; 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 "server":
case "connect": case "connect":
if (args[1]) { if (args[1]) {
@ -360,9 +379,13 @@ function event(e, data) {
} }
var type = ""; var type = "";
var text = data.message; var text = data.message;
if (text.split(" ")[0] === "\u0001ACTION") {
type = "action";
text = text.replace(/\u0001|ACTION/g, "");
}
var network = this; var network = this;
text.split(' ').forEach(function(w) { 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({ var msg = new Msg({
type: type || "normal", type: type || "normal",