2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-07-11 14:40:43 +00:00
|
|
|
const User = require("../../models/user");
|
2014-09-13 21:29:45 +00:00
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
2017-07-11 14:40:43 +00:00
|
|
|
const client = this;
|
|
|
|
|
2016-03-07 21:09:42 +00:00
|
|
|
irc.on("userlist", function(data) {
|
2017-07-11 14:40:43 +00:00
|
|
|
const chan = network.getChannel(data.channel);
|
2014-09-13 21:29:45 +00:00
|
|
|
if (typeof chan === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-24 16:34:35 +00:00
|
|
|
|
2017-07-11 14:40:43 +00:00
|
|
|
// Create lookup map of current users,
|
|
|
|
// as we need to keep certain properties
|
|
|
|
// and we can recycle existing User objects
|
|
|
|
const oldUsers = new Map();
|
|
|
|
|
|
|
|
chan.users.forEach((user) => {
|
|
|
|
oldUsers.set(user.nick, user);
|
|
|
|
});
|
|
|
|
|
|
|
|
chan.users = data.users.map((user) => {
|
|
|
|
const oldUser = oldUsers.get(user.nick);
|
|
|
|
|
|
|
|
// For existing users, we only need to update mode
|
|
|
|
if (oldUser) {
|
|
|
|
oldUser.setModes(user.modes, network.prefixLookup);
|
|
|
|
return oldUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new User({
|
|
|
|
nick: user.nick,
|
|
|
|
modes: user.modes,
|
|
|
|
}, network.prefixLookup);
|
|
|
|
});
|
2016-09-24 16:34:35 +00:00
|
|
|
|
2016-03-14 11:44:06 +00:00
|
|
|
chan.sortUsers(irc);
|
2016-09-24 16:34:35 +00:00
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
client.emit("users", {
|
2017-11-15 06:35:15 +00:00
|
|
|
chan: chan.id,
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|