From bf7eb0e727b5118e9ceb67af2ede3d7f85a6eb1a Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sun, 7 Apr 2024 14:22:53 +0200 Subject: [PATCH] network event: remove unused array All the network events only ever emit a single copy There's no point in wrapping it into an array --- client/js/socket-events/network.ts | 2 +- server/client.ts | 2 +- shared/types/socket-events.d.ts | 2 +- test/server.ts | 15 +++++++-------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/client/js/socket-events/network.ts b/client/js/socket-events/network.ts index e5dae7b4..c69a43e4 100644 --- a/client/js/socket-events/network.ts +++ b/client/js/socket-events/network.ts @@ -3,7 +3,7 @@ import {store} from "../store"; import {switchToChannel} from "../router"; socket.on("network", function (data) { - const network = data.networks[0]; + const network = data.network; network.isJoinChannelShown = false; network.isCollapsed = false; diff --git a/server/client.ts b/server/client.ts index 11041605..92d7b488 100644 --- a/server/client.ts +++ b/server/client.ts @@ -344,7 +344,7 @@ class Client { client.networks.push(network); client.emit("network", { - networks: [network.getFilteredClone(this.lastActiveChannel, -1)], + network: network.getFilteredClone(this.lastActiveChannel, -1), }); if (!network.validate(client)) { diff --git a/shared/types/socket-events.d.ts b/shared/types/socket-events.d.ts index ad15ddde..e89887f0 100644 --- a/shared/types/socket-events.d.ts +++ b/shared/types/socket-events.d.ts @@ -53,7 +53,7 @@ interface ServerToClientEvents { names: EventHandler<{id: number; users: SharedUser[]}>; - network: EventHandler<{networks: SharedNetwork[]}>; + network: EventHandler<{network: SharedNetwork}>; "network:options": EventHandler<{network: string; serverOptions: {[key: string]: any}}>; "network:status": EventHandler<{network: string; connected: boolean; secure: boolean}>; "network:info": EventHandler<{uuid: string}>; diff --git a/test/server.ts b/test/server.ts index de7e921f..f7745f91 100644 --- a/test/server.ts +++ b/test/server.ts @@ -110,14 +110,13 @@ describe("Server", function () { }); client.on("network", (data) => { - expect(data.networks).to.be.an("array"); - expect(data.networks).to.have.lengthOf(1); - expect(data.networks[0].nick).to.equal("test-user"); - expect(data.networks[0].name).to.equal("Test Network"); - expect(data.networks[0].channels).to.have.lengthOf(3); - expect(data.networks[0].channels[0].name).to.equal("Test Network"); - expect(data.networks[0].channels[1].name).to.equal("#thelounge"); - expect(data.networks[0].channels[2].name).to.equal("#spam"); + expect(data.network).to.exist; + expect(data.network.nick).to.equal("test-user"); + expect(data.network.name).to.equal("Test Network"); + expect(data.network.channels).to.have.lengthOf(3); + expect(data.network.channels[0].name).to.equal("Test Network"); + expect(data.network.channels[1].name).to.equal("#thelounge"); + expect(data.network.channels[2].name).to.equal("#spam"); done(); }); });