lib/client: add Client.cm

This contains the current connection case-mapping, parsed from the
CASEMAPPING ISUPPORT token.
This commit is contained in:
Simon Ser 2021-05-27 15:14:03 +02:00
parent 3110a9e2df
commit 615e746ec5
2 changed files with 22 additions and 1 deletions

View File

@ -47,6 +47,7 @@ export default class Client extends EventTarget {
autoReconnect = true;
reconnectTimeoutID = null;
pendingHistory = Promise.resolve(null);
cm = irc.CaseMapping.RFC1459;
constructor(params) {
super();
@ -166,7 +167,18 @@ export default class Client extends EventTarget {
break;
case irc.RPL_ISUPPORT:
var tokens = msg.params.slice(1, -1);
irc.parseISUPPORT(tokens, this.isupport);
var changed = irc.parseISUPPORT(tokens, this.isupport);
if (changed.indexOf("CASEMAPPING") >= 0) {
this.setCaseMapping(this.isupport.get("CASEMAPPING"));
}
break;
case irc.RPL_ENDOFMOTD:
case irc.ERR_NOMOTD:
// These messages are used to indicate the end of the ISUPPORT list
if (!this.isupport.has("CASEMAPPING")) {
// Server didn't send any CASEMAPPING token, assume RFC 1459
this.setCaseMapping("rfc1459");
}
break;
case "CAP":
this.handleCap(msg);
@ -378,6 +390,14 @@ export default class Client extends EventTarget {
console.debug("Sent:", msg);
}
setCaseMapping(name) {
this.cm = irc.CaseMapping.byName(name);
if (!this.cm) {
console.error("Unsupported case-mapping '" + name + "', falling back to RFC 1459");
this.cm = irc.CaseMapping.RFC1459;
}
}
/* Execute a command that expects a response. `done` is called with message
* events until it returns a truthy value. */
roundtrip(msg, done) {

View File

@ -11,6 +11,7 @@ export const RPL_TOPICWHOTIME = "333";
export const RPL_WHOREPLY = "352";
export const RPL_NAMREPLY = "353";
export const RPL_ENDOFNAMES = "366";
export const RPL_ENDOFMOTD = "376";
export const ERR_NOMOTD = "422";
export const ERR_ERRONEUSNICKNAME = "432";
export const ERR_NICKNAMEINUSE = "433";