Handle invite event

This commit is contained in:
Pavel Djundik 2016-02-12 13:24:13 +02:00
parent 0d823f24d6
commit 533ec1071b
5 changed files with 44 additions and 4 deletions

View file

@ -666,6 +666,13 @@ button, .user {
#chat.hide-quit .quit {
display: none !important;
}
#chat .invite .from:before {
font-family: FontAwesome;
content: "\f003";
color: #2ECC40;
}
#chat .join .from:before {
font-family: FontAwesome;
content: "\f090";

View file

@ -193,8 +193,10 @@ $(function() {
var chan = chat.find(target);
var from = data.msg.from;
var msg;
if ([
"invite",
"join",
"mode",
"kick",
@ -205,6 +207,7 @@ $(function() {
"action",
].indexOf(type) !== -1) {
switch (type) {
case "invite": data.msg.formattedAction = "invited " + data.msg.target + " to"; break;
case "join": data.msg.formattedAction = "has joined the channel"; break;
case "mode": data.msg.formattedAction = "sets mode"; break;
case "kick": data.msg.formattedAction = "has kicked"; break;
@ -215,12 +218,11 @@ $(function() {
default: data.msg.formattedAction = "";
}
var action = $(render("msg_action", data.msg));
return action;
msg = $(render("msg_action", data.msg));
} else {
msg = $(render("msg", data.msg));
}
var msg = $(render("msg", data.msg));
var text = msg.find(".text");
if (text.find("i").size() === 1) {
text = text.find("i");

View file

@ -17,6 +17,7 @@ var id = 0;
var events = [
"ctcp",
"error",
"invite",
"join",
"kick",
"mode",

View file

@ -4,6 +4,7 @@ var moment = require("moment");
Msg.Type = {
ACTION: "action",
ERROR: "error",
INVITE: "invite",
JOIN: "join",
KICK: "kick",
MESSAGE: "message",

View file

@ -0,0 +1,29 @@
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("invite", function(data) {
var target = data.to;
if (target.toLowerCase() === irc.me.toLowerCase()) {
target = "you";
}
var chan = _.findWhere(network.channels, {name: data.channel});
if (typeof chan === "undefined") {
chan = network.channels[0];
}
var msg = new Msg({
type: Msg.Type.INVITE,
from: data.from,
target: target,
text: data.channel
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};