thelounge/src/plugins/irc-events/join.js
Maxime Poulin 5bf205195d Only update the users list when needed
Currently, for join/part/kick/nick/... the server will send an updated list of users and the client will re-render the list entirely. This ends up being a very expensive operation when joined on large channels and causes the client to slow down a lot.
2016-02-17 04:35:55 -05:00

42 lines
913 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.save();
client.emit("join", {
network: network.id,
chan: chan
});
}
chan.users.push(new User({name: data.nick}));
chan.sortUsers();
client.emit("users", {
chan: chan.id
});
var self = false;
if (data.nick.toLowerCase() === irc.me.toLowerCase()) {
self = true;
}
var msg = new Msg({
from: data.nick,
type: Msg.Type.JOIN,
self: self
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};