lib/client: rename whoisDB to pendingWHOIS, garbage collect

This commit is contained in:
Simon Ser 2021-10-23 19:48:04 +02:00
parent 49a59077b7
commit b059e034e2

View file

@ -79,7 +79,7 @@ export default class Client extends EventTarget {
pendingHistory = Promise.resolve(null);
cm = irc.CaseMapping.RFC1459;
monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
whoisDB = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
pendingWHOIS = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
whoxQueries = new Map();
constructor(params) {
@ -273,10 +273,16 @@ export default class Client extends EventTarget {
case irc.RPL_WHOISCHANNELS:
case irc.RPL_ENDOFWHOIS:
let nick = msg.params[1];
if (!this.whoisDB.has(nick)) {
this.whoisDB.set(nick, {});
let whois = this.pendingWHOIS.get(nick);
if (!whois) {
whois = {};
this.pendingWHOIS.set(nick, whois);
}
whois[msg.command] = msg;
if (msg.command == irc.RPL_ENDOFWHOIS) {
this.pendingWHOIS.delete(nick);
msg.whois = whois;
}
this.whoisDB.get(nick)[msg.command] = msg;
break;
case irc.ERR_NICKLOCKED:
case irc.ERR_SASLFAIL:
@ -440,7 +446,7 @@ export default class Client extends EventTarget {
case irc.RPL_ENDOFWHOIS:
nick = msg.params[1];
if (this.cm(nick) === targetCM) {
return this.whoisDB.get(nick);
return msg.whois;
}
break;
case irc.ERR_NOSUCHNICK:
@ -587,7 +593,7 @@ export default class Client extends EventTarget {
this.cm = irc.CaseMapping.RFC1459;
}
this.whoisDB = new irc.CaseMapMap(this.whoisDB, this.cm);
this.pendingWHOIS = new irc.CaseMapMap(this.pendingWHOIS, this.cm);
this.monitored = new irc.CaseMapMap(this.monitored, this.cm);
}