mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-15 03:15: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) {
|
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) => {
|
||||||
|
|
Loading…
Reference in a new issue