Move isBouncer props to server state

Avoids having to pass this around.
This commit is contained in:
Simon Ser 2021-12-07 13:16:07 +01:00
parent f81c564d23
commit f3d38859d3
5 changed files with 11 additions and 17 deletions

View file

@ -1591,14 +1591,10 @@ export default class App extends Component {
}
let activeBuffer = null, activeServer = null, activeBouncerNetwork = null;
let isBouncer = false;
if (this.state.buffers.get(this.state.activeBuffer)) {
activeBuffer = this.state.buffers.get(this.state.activeBuffer);
activeServer = this.state.servers.get(activeBuffer.server);
let activeClient = this.clients.get(activeBuffer.server);
isBouncer = activeClient && activeClient.enabledCaps["soju.im/bouncer-networks"];
let bouncerNetID = activeServer.bouncerNetID;
if (bouncerNetID) {
activeBouncerNetwork = this.state.bouncerNetworks.get(bouncerNetID);
@ -1634,7 +1630,6 @@ export default class App extends Component {
buffer=${activeBuffer}
server=${activeServer}
user=${activeUser}
isBouncer=${isBouncer}
bouncerNetwork=${activeBouncerNetwork}
onChannelClick=${this.handleChannelClick}
onClose=${() => this.close(activeBuffer)}
@ -1716,7 +1711,7 @@ export default class App extends Component {
`;
}
dialog = html`
<${Dialog} title="Login to ${getServerName(activeServer, activeBouncerNetwork, isBouncer)}" onDismiss=${this.dismissDialog}>
<${Dialog} title="Login to ${getServerName(activeServer, activeBouncerNetwork)}" onDismiss=${this.dismissDialog}>
${dialogBody}
</>
`;
@ -1730,7 +1725,7 @@ export default class App extends Component {
`;
}
dialog = html`
<${Dialog} title="Register a new ${getServerName(activeServer, activeBouncerNetwork, isBouncer)} account" onDismiss=${this.dismissDialog}>
<${Dialog} title="Register a new ${getServerName(activeServer, activeBouncerNetwork)} account" onDismiss=${this.dismissDialog}>
${dialogBody}
</>
`;
@ -1744,7 +1739,7 @@ export default class App extends Component {
`;
}
dialog = html`
<${Dialog} title="Verify ${getServerName(activeServer, activeBouncerNetwork, isBouncer)} account" onDismiss=${this.dismissDialog}>
<${Dialog} title="Verify ${getServerName(activeServer, activeBouncerNetwork)} account" onDismiss=${this.dismissDialog}>
${dialogBody}
</>
`;
@ -1779,7 +1774,6 @@ export default class App extends Component {
buffers=${this.state.buffers}
servers=${this.state.servers}
bouncerNetworks=${this.state.bouncerNetworks}
isBouncer=${isBouncer}
activeBuffer=${this.state.activeBuffer}
onBufferClick=${this.handleBufferListClick}
onBufferClose=${this.handleBufferListClose}
@ -1803,7 +1797,6 @@ export default class App extends Component {
<${Buffer}
buffer=${activeBuffer}
server=${activeServer}
isBouncer=${isBouncer}
bouncerNetwork=${activeBouncerNetwork}
onChannelClick=${this.handleChannelClick}
onNickClick=${this.handleNickClick}

View file

@ -86,7 +86,7 @@ export default function BufferHeader(props) {
>Join channel</button>
`;
if (props.isBouncer) {
if (props.server.isBouncer) {
if (props.server.bouncerNetID) {
if (fullyConnected) {
actions.push(joinButton);
@ -221,7 +221,7 @@ export default function BufferHeader(props) {
let name = props.buffer.name;
if (props.buffer.type == BufferType.SERVER) {
name = getServerName(props.server, props.bouncerNetwork, props.isBouncer);
name = getServerName(props.server, props.bouncerNetwork);
}
return html`

View file

@ -16,7 +16,7 @@ function BufferItem(props) {
let name = props.buffer.name;
if (props.buffer.type == BufferType.SERVER) {
name = getServerName(props.server, props.bouncerNetwork, props.isBouncer);
name = getServerName(props.server, props.bouncerNetwork);
}
let classes = ["type-" + props.buffer.type];
@ -54,7 +54,6 @@ export default function BufferList(props) {
key=${buf.id}
buffer=${buf}
server=${server}
isBouncer=${props.isBouncer}
bouncerNetwork=${bouncerNetwork}
onClick=${() => props.onBufferClick(buf)}
onClose=${() => props.onBufferClose(buf)}

View file

@ -570,7 +570,7 @@ export default class Buffer extends Component {
if (buf.type == BufferType.SERVER) {
children.push(html`<${NotificationNagger}/>`);
}
if (buf.type == BufferType.SERVER && this.props.isBouncer && !server.bouncerNetID) {
if (buf.type == BufferType.SERVER && server.isBouncer && !server.bouncerNetID) {
children.push(html`<${ProtocolHandlerNagger} bouncerName=${serverName}/>`);
}
if (buf.type == BufferType.SERVER && server.status == ServerStatus.REGISTERED && server.supportsSASLPlain && !server.account) {

View file

@ -63,7 +63,7 @@ export function getMessageURL(buf, msg) {
}
}
export function getServerName(server, bouncerNetwork, isBouncer) {
export function getServerName(server, bouncerNetwork) {
let netName = server.name;
if (bouncerNetwork && bouncerNetwork.name && bouncerNetwork.name !== bouncerNetwork.host) {
@ -78,7 +78,7 @@ export function getServerName(server, bouncerNetwork, isBouncer) {
if (bouncerNetwork) {
return bouncerNetwork.name || bouncerNetwork.host || "server";
} else if (isBouncer) {
} else if (server.isBouncer) {
return "bouncer";
} else {
return "server";
@ -261,6 +261,7 @@ export const State = {
supportsAccountRegistration: false,
reliableUserAccounts: false,
statusMsg: null, // from ISUPPORT STATUSMSG
isBouncer: false,
bouncerNetID: null,
});
return [id, { servers }];
@ -360,6 +361,7 @@ export const State = {
return updateServer({
supportsSASLPlain: client.supportsSASL("PLAIN"),
supportsAccountRegistration: !!client.enabledCaps["draft/account-registration"],
isBouncer: !!client.enabledCaps["soju.im/bouncer-networks"],
});
case irc.RPL_LOGGEDIN:
return updateServer({ account: msg.params[2] });