From 67e4a4bbb2a874c3a049ac972a5373e5b3e8bb2b Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 28 Oct 2019 18:11:45 +0200 Subject: [PATCH] Sync changed network name to open clients --- client/js/socket-events/network.js | 5 +++++ src/models/network.js | 9 +++++++++ test/models/network.js | 13 +++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/client/js/socket-events/network.js b/client/js/socket-events/network.js index 1646d08a..9f248657 100644 --- a/client/js/socket-events/network.js +++ b/client/js/socket-events/network.js @@ -64,3 +64,8 @@ socket.on("network:info", function (data) { Vue.set(network, key, data[key]); } }); + +socket.on("network:name", function (data) { + const network = store.getters.findNetwork(data.uuid); + network.name = network.channels[0].name = data.name; +}); diff --git a/src/models/network.js b/src/models/network.js index f19adae5..a2e4a946 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -253,6 +253,7 @@ Network.prototype.createWebIrc = function (client) { }; Network.prototype.edit = function (client, args) { + const oldNetworkName = this.name; const oldNick = this.nick; const oldRealname = this.realname; @@ -279,6 +280,14 @@ Network.prototype.edit = function (client, args) { // Sync lobby channel name this.channels[0].name = this.name; + if (this.name !== oldNetworkName) { + // Send updated network name to all connected clients + client.emit("network:name", { + uuid: this.uuid, + name: this.name, + }); + } + if (!this.validate(client)) { return; } diff --git a/test/models/network.js b/test/models/network.js index 44e59cf7..3308bbc6 100644 --- a/test/models/network.js +++ b/test/models/network.js @@ -109,10 +109,18 @@ describe("Network", function () { it("editing a network should enforce correct types", function () { let saveCalled = false; + let nameEmitCalled = false; const network = new Network(); network.edit( { + emit(name, data) { + if (name === "network:name") { + nameEmitCalled = true; + expect(data.uuid).to.equal(network.uuid); + expect(data.name).to.equal("Lounge Test Network"); + } + }, save() { saveCalled = true; }, @@ -133,12 +141,13 @@ describe("Network", function () { commands: "/command 1 2 3\r\n/ping HELLO\r\r\r\r/whois test\r\n\r\n", ip: "newIp", hostname: "newHostname", - guid: "newGuid", + uuid: "newuuid", } ); expect(saveCalled).to.be.true; - expect(network.guid).to.not.equal("newGuid"); + expect(nameEmitCalled).to.be.true; + expect(network.uuid).to.not.equal("newuuid"); expect(network.ip).to.be.undefined; expect(network.hostname).to.be.undefined;