thelounge/src/plugins/irc-events/join.js
Fredrik Pettersen fabbb43e18 Added boolean flag if message was sent from "me"
Your own messages now have a different color, and the possibility of
changing colors etc in css of all things sent by yourself
2014-09-14 19:06:56 +02:00

43 lines
943 B
JavaScript

var _ = require("lodash");
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
var User = require("../../models/user");
module.exports = function(irc, network) {
var client = this;
irc.on("join", function(data) {
var chan = _.find(network.channels, {name: data.channel});
if (typeof chan === "undefined") {
chan = new Chan({
name: data.channel
});
network.channels.push(chan);
client.emit("join", {
network: network.id,
chan: chan
});
}
var from_me = false
if (data.from.toLowerCase() == irc.me.toLowerCase() ) {
from_me = true
}
var users = chan.users;
users.push(new User({name: data.nick}));
chan.sortUsers();
client.emit("users", {
chan: chan.id,
users: users
});
var msg = new Msg({
from: data.nick,
type: Msg.Type.JOIN,
from_me: from_me
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};