thelounge/src/plugins/irc-events/join.js
Al McKinlay 5ce67ba093 Insert channel/user into channel list at alphabetically sorted point, not just the end
Don't sort queries/users after special chans


Set all users in tests to be of type query


Add test for not inserting infront of lobby


Break after finding the index, otherwise it always adds it to the end


Add checking for lobby in first test


Fix off-by-one error on the frontend


Fix utterly idiotic issue adding a duplicate of the channel we are on rather than the new user when we query


Check that we always insert before first special chan
2018-03-12 12:42:59 +00:00

50 lines
1.1 KiB
JavaScript

"use strict";
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
const User = require("../../models/user");
module.exports = function(irc, network) {
const client = this;
irc.on("join", function(data) {
let chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
chan = new Chan({
name: data.channel,
state: Chan.State.JOINED,
});
client.emit("join", {
network: network.id,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});
client.save();
chan.loadMessages(client, network);
// Request channels' modes
network.irc.raw("MODE", chan.name);
} else if (data.nick === irc.user.nick) {
chan.state = Chan.State.JOINED;
}
const user = new User({nick: data.nick});
const msg = new Msg({
time: data.time,
from: user,
hostmask: data.ident + "@" + data.hostname,
type: Msg.Type.JOIN,
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
chan.setUser(new User({nick: data.nick}));
client.emit("users", {
chan: chan.id,
});
});
};