thelounge/src/plugins/irc-events/whois.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

48 lines
1 KiB
JavaScript

"use strict";
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
const client = this;
irc.on("whois", function(data) {
let chan = network.getChannel(data.nick);
if (typeof chan === "undefined") {
chan = new Chan({
type: Chan.Type.QUERY,
name: data.nick,
});
client.emit("join", {
shouldOpen: true,
network: network.id,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});
chan.loadMessages(client, network);
client.save();
}
let msg;
if (data.error) {
msg = new Msg({
type: Msg.Type.ERROR,
text: "No such nick: " + data.nick,
});
} else {
// Absolute datetime in milliseconds since nick is idle
data.idleTime = Date.now() - data.idle * 1000;
// Absolute datetime in milliseconds when nick logged on.
data.logonTime = data.logon * 1000;
msg = new Msg({
type: Msg.Type.WHOIS,
whois: data,
});
}
chan.pushMessage(client, msg);
});
};