2014-09-13 21:29:45 +00:00
|
|
|
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 users = chan.users;
|
|
|
|
users.push(new User({name: data.nick}));
|
|
|
|
chan.sortUsers();
|
|
|
|
client.emit("users", {
|
|
|
|
chan: chan.id,
|
|
|
|
users: users
|
|
|
|
});
|
2014-09-14 18:49:42 +00:00
|
|
|
var self = false;
|
|
|
|
if (data.nick.toLowerCase() == irc.me.toLowerCase()) {
|
|
|
|
self = true;
|
|
|
|
}
|
2014-09-13 21:29:45 +00:00
|
|
|
var msg = new Msg({
|
|
|
|
from: data.nick,
|
2014-09-14 17:06:56 +00:00
|
|
|
type: Msg.Type.JOIN,
|
2014-09-14 18:49:42 +00:00
|
|
|
self: self
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
chan.messages.push(msg);
|
|
|
|
client.emit("msg", {
|
|
|
|
chan: chan.id,
|
|
|
|
msg: msg
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|