mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
Auto-join when adding new network on irc:// link click
Closes: https://todo.sr.ht/~emersion/gamja/111
This commit is contained in:
parent
a58befd6d7
commit
74fe6ee944
3 changed files with 72 additions and 9 deletions
|
@ -781,7 +781,16 @@ export default class App extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-join channels given at connect-time
|
// Auto-join channels given at connect-time
|
||||||
join = join.concat(this.state.connectParams.autojoin);
|
let server = this.state.servers.get(serverID);
|
||||||
|
let bouncerNetID = server.isupport.get("BOUNCER_NETID");
|
||||||
|
let bouncerNetwork = null;
|
||||||
|
if (bouncerNetID) {
|
||||||
|
bouncerNetwork = this.state.bouncerNetworks.get(bouncerNetID);
|
||||||
|
}
|
||||||
|
if (!bouncerNetwork || bouncerNetwork.state === "connected") {
|
||||||
|
join = join.concat(client.params.autojoin);
|
||||||
|
client.params.autojoin = [];
|
||||||
|
}
|
||||||
|
|
||||||
if (join.length > 0) {
|
if (join.length > 0) {
|
||||||
client.send({
|
client.send({
|
||||||
|
@ -849,6 +858,18 @@ export default class App extends Component {
|
||||||
bouncerNetwork: id,
|
bouncerNetwork: id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attrs && attrs.state === "connected") {
|
||||||
|
let serverID = this.serverFromBouncerNetwork(id);
|
||||||
|
let client = this.clients.get(serverID);
|
||||||
|
if (client && client.status === Client.Status.REGISTERED && client.params.autojoin && client.params.autojoin.length > 0) {
|
||||||
|
client.send({
|
||||||
|
command: "JOIN",
|
||||||
|
params: [client.params.autojoin.join(",")],
|
||||||
|
});
|
||||||
|
client.params.autojoin = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -904,7 +925,7 @@ export default class App extends Component {
|
||||||
if (client && client.enabledCaps["soju.im/bouncer-networks"]) {
|
if (client && client.enabledCaps["soju.im/bouncer-networks"]) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let params = { host: url.host };
|
let params = { host: url.host };
|
||||||
this.openDialog("network", { params });
|
this.openDialog("network", { params, autojoin: url.entity });
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1275,7 +1296,7 @@ export default class App extends Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNetworkSubmit(attrs) {
|
handleNetworkSubmit(attrs, autojoin) {
|
||||||
let client = this.clients.values().next().value;
|
let client = this.clients.values().next().value;
|
||||||
|
|
||||||
if (this.state.dialogData && this.state.dialogData.id) {
|
if (this.state.dialogData && this.state.dialogData.id) {
|
||||||
|
@ -1290,9 +1311,18 @@ export default class App extends Component {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
attrs = { ...attrs, tls: "1" };
|
attrs = { ...attrs, tls: "1" };
|
||||||
client.send({
|
client.createBouncerNetwork(attrs).then((id) => {
|
||||||
command: "BOUNCER",
|
if (!autojoin) {
|
||||||
params: ["ADDNETWORK", irc.formatTags(attrs)],
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// By this point, bouncer-networks-notify should've advertised
|
||||||
|
// the new network
|
||||||
|
let serverID = this.serverFromBouncerNetwork(id);
|
||||||
|
let client = this.clients.get(serverID);
|
||||||
|
client.params.autojoin = [autojoin];
|
||||||
|
|
||||||
|
this.switchToChannel = autojoin;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1406,14 +1436,16 @@ export default class App extends Component {
|
||||||
let dialog = null;
|
let dialog = null;
|
||||||
switch (this.state.dialog) {
|
switch (this.state.dialog) {
|
||||||
case "network":
|
case "network":
|
||||||
let isNew = !!(!this.state.dialogData || !this.state.dialogData.id);
|
let data = this.state.dialogData || {};
|
||||||
|
let isNew = !data.id;
|
||||||
let title = isNew ? "Add network" : "Edit network";
|
let title = isNew ? "Add network" : "Edit network";
|
||||||
dialog = html`
|
dialog = html`
|
||||||
<${Dialog} title=${title} onDismiss=${this.dismissDialog}>
|
<${Dialog} title=${title} onDismiss=${this.dismissDialog}>
|
||||||
<${NetworkForm}
|
<${NetworkForm}
|
||||||
onSubmit=${this.handleNetworkSubmit}
|
onSubmit=${this.handleNetworkSubmit}
|
||||||
onRemove=${this.handleNetworkRemove}
|
onRemove=${this.handleNetworkRemove}
|
||||||
params=${this.state.dialogData ? this.state.dialogData.params : null}
|
params=${data.params}
|
||||||
|
autojoin=${data.autojoin}
|
||||||
isNew=${isNew}
|
isNew=${isNew}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -14,6 +14,7 @@ export default class NetworkForm extends Component {
|
||||||
prevParams = null;
|
prevParams = null;
|
||||||
state = {
|
state = {
|
||||||
...defaultParams,
|
...defaultParams,
|
||||||
|
autojoin: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -54,7 +55,8 @@ export default class NetworkForm extends Component {
|
||||||
params[k] = this.state[k];
|
params[k] = this.state[k];
|
||||||
});
|
});
|
||||||
|
|
||||||
this.props.onSubmit(params);
|
let autojoin = this.state.autojoin ? this.props.autojoin : null;
|
||||||
|
this.props.onSubmit(params, autojoin);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -67,6 +69,21 @@ export default class NetworkForm extends Component {
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let autojoin = null;
|
||||||
|
if (this.props.autojoin) {
|
||||||
|
autojoin = html`
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="autojoin"
|
||||||
|
checked=${this.state.autojoin}
|
||||||
|
/>
|
||||||
|
Auto-join channel <strong>${this.props.autojoin}</strong>
|
||||||
|
</label>
|
||||||
|
<br/><br/>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
|
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
|
||||||
<label>
|
<label>
|
||||||
|
@ -75,6 +92,8 @@ export default class NetworkForm extends Component {
|
||||||
</label>
|
</label>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
|
||||||
|
${autojoin}
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary role="button">Advanced options</summary>
|
<summary role="button">Advanced options</summary>
|
||||||
|
|
||||||
|
|
|
@ -861,4 +861,16 @@ export default class Client extends EventTarget {
|
||||||
|
|
||||||
this.send({ command: "MONITOR", params: ["-", target] });
|
this.send({ command: "MONITOR", params: ["-", target] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createBouncerNetwork(attrs) {
|
||||||
|
let msg = {
|
||||||
|
command: "BOUNCER",
|
||||||
|
params: ["ADDNETWORK", irc.formatTags(attrs)],
|
||||||
|
};
|
||||||
|
return this.roundtrip(msg, (msg) => {
|
||||||
|
if (msg.command === "BOUNCER" && msg.params[0] === "ADDNETWORK") {
|
||||||
|
return msg.params[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue