From 39754677648f4907439540bfa565e6b751d5ad2f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 22 Jan 2021 10:38:07 +0100 Subject: [PATCH] Drop state.activeNetwork Just grab it from state.activeBuffer's network. --- commands.js | 4 ++-- components/app.js | 37 +++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/commands.js b/commands.js index f91ce23..88727b3 100644 --- a/commands.js +++ b/commands.js @@ -92,9 +92,9 @@ export default { app.client.send({ command: "TOPIC", params }); }, "reconnect": (app, args) => { - app.reconnect(app.state.activeNetwork); + app.reconnect(); }, "disconnect": (app, args) => { - app.disconnect(app.state.activeNetwork); + app.disconnect(); }, }; diff --git a/components/app.js b/components/app.js index 328e68b..4c00cfc 100644 --- a/components/app.js +++ b/components/app.js @@ -106,6 +106,14 @@ function updateState(state, updater) { return { ...state, ...updated }; } +function getActiveNetworkID(state) { + var buf = state.buffers.get(state.activeBuffer); + if (!buf) { + return null; + } + return buf.network; +} + function getBuffer(state, id) { switch (typeof id) { case "number": @@ -117,7 +125,7 @@ function getBuffer(state, id) { var network = id.network, name = id.name; if (!network) { - network = state.activeNetwork; + network = getActiveNetworkID(state); } for (var buf of state.buffers.values()) { if (buf.network === network && buf.name === name) { @@ -146,7 +154,6 @@ export default class App extends Component { status: Status.DISCONNECTED, networks: new Map(), buffers: new Map(), - activeNetwork: DEFAULT_NETWORK, activeBuffer: null, error: null, }; @@ -485,6 +492,13 @@ export default class App extends Component { } disconnect(netID) { + if (!netID) { + netID = getActiveNetworkID(this.state); + if (!netID) { + return; + } + } + clearTimeout(this.reconnectTimeoutID); this.reconnectTimeoutID = null; @@ -498,6 +512,13 @@ export default class App extends Component { } reconnect(netID) { + if (!netID) { + netID = getActiveNetworkID(this.state); + if (!netID) { + return; + } + } + this.connect(netID, this.state.connectParams); } @@ -722,7 +743,7 @@ export default class App extends Component { } else { this.client.send({ command: "WHO", params: [target] }); } - this.createBuffer(this.state.activeNetwork, target); + this.createBuffer(getActiveNetworkID(this.state), target); this.switchBuffer({ name: target }); } @@ -786,7 +807,7 @@ export default class App extends Component { if (!this.client.enabledCaps["echo-message"]) { msg.prefix = { name: this.client.nick }; - this.addMessage(this.state.activeNetwork, target, msg); + this.addMessage(getActiveNetworkID(this.state), target, msg); } } @@ -942,14 +963,10 @@ export default class App extends Component { } render() { - var activeNetwork = null; - if (this.state.activeNetwork) { - activeNetwork = this.state.networks.get(this.state.activeNetwork); - } - - var activeBuffer = null; + var activeBuffer = null, activeNetwork = null; if (this.state.activeBuffer) { activeBuffer = this.state.buffers.get(this.state.activeBuffer); + activeNetwork = this.state.networks.get(activeBuffer.network); } if (!activeNetwork || (activeNetwork.status != Status.REGISTERED && !activeBuffer)) {