2014-06-19 15:28:53 +00:00
|
|
|
var _ = require("lodash");
|
|
|
|
var Chan = require("../models/chan");
|
|
|
|
var Msg = require("../models/msg");
|
|
|
|
|
2014-06-23 17:28:36 +00:00
|
|
|
module.exports = function(slate, network) {
|
|
|
|
var client = this;
|
|
|
|
slate.on("quit", function(data) {
|
2014-06-19 15:28:53 +00:00
|
|
|
network.channels.forEach(function(chan) {
|
|
|
|
var user = _.findWhere(chan.users, {name: data.nick});
|
|
|
|
if (!user) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
chan.users = _.without(chan.users, user);
|
2014-06-23 17:28:36 +00:00
|
|
|
client.emit("users", {
|
2014-06-19 15:28:53 +00:00
|
|
|
id: chan.id,
|
|
|
|
users: chan.users,
|
|
|
|
});
|
|
|
|
var msg = new Msg({
|
|
|
|
type: "quit",
|
|
|
|
from: data.nick,
|
|
|
|
});
|
|
|
|
chan.addMsg(msg);
|
2014-06-23 17:28:36 +00:00
|
|
|
client.emit("msg", {
|
2014-06-19 15:28:53 +00:00
|
|
|
id: chan.id,
|
|
|
|
msg: msg,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|