2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-07-11 16:40:43 +02:00
|
|
|
const User = require("../../models/user");
|
2014-09-13 23:29:45 +02:00
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
2017-07-11 16:40:43 +02:00
|
|
|
const client = this;
|
|
|
|
|
2016-03-07 22:09:42 +01:00
|
|
|
irc.on("userlist", function(data) {
|
2017-07-11 16:40:43 +02:00
|
|
|
const chan = network.getChannel(data.channel);
|
2014-09-13 23:29:45 +02:00
|
|
|
if (typeof chan === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-24 18:34:35 +02:00
|
|
|
|
2017-07-11 16:40:43 +02: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 18:34:35 +02:00
|
|
|
|
2016-03-14 12:44:06 +01:00
|
|
|
chan.sortUsers(irc);
|
2016-09-24 18:34:35 +02:00
|
|
|
|
2014-09-13 23:29:45 +02:00
|
|
|
client.emit("users", {
|
2016-02-17 03:29:44 +01:00
|
|
|
chan: chan.id
|
2014-09-13 23:29:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|