Request caps on CAP NEW

This commit is contained in:
Simon Ser 2020-06-26 12:37:45 +02:00
parent 1807f29d2d
commit c59a8ff63c
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -132,6 +132,28 @@ export default class Client extends EventTarget {
}); });
} }
supportsSASL(mech) {
var saslCap = this.availableCaps["sasl"];
if (saslCap === undefined) {
return false;
}
return saslCap.split(",").includes(mech);
}
requestCaps(extra) {
var reqCaps = extra || [];
permanentCaps.forEach((cap) => {
if (this.availableCaps[cap] !== undefined && !this.enabledCaps[cap]) {
reqCaps.push(cap);
}
});
if (reqCaps.length > 0) {
this.send({ command: "CAP", params: ["REQ", reqCaps.join(" ")] });
}
}
handleCap(msg) { handleCap(msg) {
var subCmd = msg.params[1]; var subCmd = msg.params[1];
var args = msg.params.slice(2); var args = msg.params.slice(2);
@ -142,29 +164,14 @@ export default class Client extends EventTarget {
console.log("Available server caps:", this.availableCaps); console.log("Available server caps:", this.availableCaps);
var reqCaps = []; var reqCaps = [];
var saslCap = this.availableCaps["sasl"];
var supportsSaslPlain = (saslCap !== undefined);
if (saslCap.length > 0) {
supportsSaslPlain = saslCap.split(",").includes("PLAIN");
}
var capEnd = true; var capEnd = true;
if (this.params.saslPlain && supportsSaslPlain) { if (this.params.saslPlain && this.supportsSASL("PLAIN")) {
// CAP END is deferred after authentication finishes // CAP END is deferred after authentication finishes
reqCaps.push("sasl"); reqCaps.push("sasl");
capEnd = false; capEnd = false;
} }
permanentCaps.forEach((cap) => { this.requestCaps(reqCaps);
if (this.availableCaps[cap] !== undefined) {
reqCaps.push(cap);
}
});
if (reqCaps.length > 0) {
this.send({ command: "CAP", params: ["REQ", reqCaps.join(" ")] });
}
if (!this.registered && capEnd) { if (!this.registered && capEnd) {
this.send({ command: "CAP", params: ["END"] }); this.send({ command: "CAP", params: ["END"] });
@ -174,7 +181,7 @@ export default class Client extends EventTarget {
case "NEW": case "NEW":
this.addAvailableCaps(args[0]); this.addAvailableCaps(args[0]);
console.log("Server added available caps:", args[0]); console.log("Server added available caps:", args[0]);
// TODO: request caps this.requestCaps();
break; break;
case "DEL": case "DEL":
args[0].split(" ").forEach((cap) => { args[0].split(" ").forEach((cap) => {