Add support for the soju.im/bouncer-networks-notify cap
This commit is contained in:
parent
94fba920cd
commit
6524dc5dd2
2 changed files with 50 additions and 19 deletions
|
@ -542,19 +542,19 @@ export default class App extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
networkFromBouncerNetwork(bouncerNetworkID) {
|
||||||
|
for (var [id, client] of this.clients) {
|
||||||
|
if (client.params.bouncerNetwork === bouncerNetworkID) {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
handleMessage(netID, msg) {
|
handleMessage(netID, msg) {
|
||||||
var client = this.clients.get(netID);
|
var client = this.clients.get(netID);
|
||||||
switch (msg.command) {
|
switch (msg.command) {
|
||||||
case irc.RPL_WELCOME:
|
case irc.RPL_WELCOME:
|
||||||
if (client.enabledCaps["soju.im/bouncer-networks"] && !client.params.bouncerNetwork) {
|
|
||||||
client.listBouncerNetworks().then((bouncerNetworks) => {
|
|
||||||
this.setState((state) => {
|
|
||||||
return { bouncerNetworks };
|
|
||||||
});
|
|
||||||
this.openSecondaryClients(client, bouncerNetworks);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.state.connectParams.autojoin.length > 0) {
|
if (this.state.connectParams.autojoin.length > 0) {
|
||||||
client.send({
|
client.send({
|
||||||
command: "JOIN",
|
command: "JOIN",
|
||||||
|
@ -745,11 +745,47 @@ export default class App extends Component {
|
||||||
this.setState({ error: description });
|
this.setState({ error: description });
|
||||||
this.addMessage(netID, SERVER_BUFFER, msg);
|
this.addMessage(netID, SERVER_BUFFER, msg);
|
||||||
break;
|
break;
|
||||||
|
case "BOUNCER":
|
||||||
|
if (msg.params[0] !== "NETWORK") {
|
||||||
|
break; // We're only interested in network updates
|
||||||
|
}
|
||||||
|
|
||||||
|
var id = msg.params[1];
|
||||||
|
var attrs = null;
|
||||||
|
if (msg.params[2] !== "*") {
|
||||||
|
attrs = irc.parseTags(msg.params[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
this.setState((state) => {
|
||||||
|
var bouncerNetworks = new Map(state.bouncerNetworks);
|
||||||
|
if (!attrs) {
|
||||||
|
bouncerNetworks.delete(id);
|
||||||
|
} else {
|
||||||
|
var prev = bouncerNetworks.get(id);
|
||||||
|
isNew = prev === undefined;
|
||||||
|
attrs = { ...prev, ...attrs };
|
||||||
|
bouncerNetworks.set(id, attrs);
|
||||||
|
}
|
||||||
|
return { bouncerNetworks };
|
||||||
|
}, () => {
|
||||||
|
if (!attrs) {
|
||||||
|
var netID = this.networkFromBouncerNetwork(id);
|
||||||
|
if (netID) {
|
||||||
|
this.close({ network: netID, name: SERVER_BUFFER });
|
||||||
|
}
|
||||||
|
} else if (isNew) {
|
||||||
|
this.connect({
|
||||||
|
...client.params,
|
||||||
|
bouncerNetwork: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "CAP":
|
case "CAP":
|
||||||
case "AUTHENTICATE":
|
case "AUTHENTICATE":
|
||||||
case "PING":
|
case "PING":
|
||||||
case "BATCH":
|
case "BATCH":
|
||||||
case "BOUNCER":
|
|
||||||
// Ignore these
|
// Ignore these
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -757,15 +793,6 @@ export default class App extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openSecondaryClients(client, bouncerNetworks) {
|
|
||||||
bouncerNetworks.forEach((attrs, id) => {
|
|
||||||
this.connect({
|
|
||||||
...client.params,
|
|
||||||
bouncerNetwork: id,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleConnectSubmit(connectParams) {
|
handleConnectSubmit(connectParams) {
|
||||||
this.setState({ error: null });
|
this.setState({ error: null });
|
||||||
|
|
||||||
|
|
|
@ -308,6 +308,10 @@ export default class Client extends EventTarget {
|
||||||
capEnd = false;
|
capEnd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.params.bouncerNetwork && this.availableCaps["soju.im/bouncer-networks-notify"] !== undefined) {
|
||||||
|
reqCaps.push("soju.im/bouncer-networks-notify");
|
||||||
|
}
|
||||||
|
|
||||||
this.requestCaps(reqCaps);
|
this.requestCaps(reqCaps);
|
||||||
|
|
||||||
if (this.status != Client.Status.REGISTERED && capEnd) {
|
if (this.status != Client.Status.REGISTERED && capEnd) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue