mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
Request caps on CAP NEW
This commit is contained in:
parent
1807f29d2d
commit
c59a8ff63c
1 changed files with 25 additions and 18 deletions
|
@ -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) {
|
||||
var subCmd = msg.params[1];
|
||||
var args = msg.params.slice(2);
|
||||
|
@ -142,29 +164,14 @@ export default class Client extends EventTarget {
|
|||
console.log("Available server caps:", this.availableCaps);
|
||||
|
||||
var reqCaps = [];
|
||||
|
||||
var saslCap = this.availableCaps["sasl"];
|
||||
var supportsSaslPlain = (saslCap !== undefined);
|
||||
if (saslCap.length > 0) {
|
||||
supportsSaslPlain = saslCap.split(",").includes("PLAIN");
|
||||
}
|
||||
|
||||
var capEnd = true;
|
||||
if (this.params.saslPlain && supportsSaslPlain) {
|
||||
if (this.params.saslPlain && this.supportsSASL("PLAIN")) {
|
||||
// CAP END is deferred after authentication finishes
|
||||
reqCaps.push("sasl");
|
||||
capEnd = false;
|
||||
}
|
||||
|
||||
permanentCaps.forEach((cap) => {
|
||||
if (this.availableCaps[cap] !== undefined) {
|
||||
reqCaps.push(cap);
|
||||
}
|
||||
});
|
||||
|
||||
if (reqCaps.length > 0) {
|
||||
this.send({ command: "CAP", params: ["REQ", reqCaps.join(" ")] });
|
||||
}
|
||||
this.requestCaps(reqCaps);
|
||||
|
||||
if (!this.registered && capEnd) {
|
||||
this.send({ command: "CAP", params: ["END"] });
|
||||
|
@ -174,7 +181,7 @@ export default class Client extends EventTarget {
|
|||
case "NEW":
|
||||
this.addAvailableCaps(args[0]);
|
||||
console.log("Server added available caps:", args[0]);
|
||||
// TODO: request caps
|
||||
this.requestCaps();
|
||||
break;
|
||||
case "DEL":
|
||||
args[0].split(" ").forEach((cap) => {
|
||||
|
|
Loading…
Reference in a new issue