Merge pull request #4038 from thelounge/xpaw/sync-network-name

Sync changed network name to open clients
This commit is contained in:
Pavel Djundik 2020-08-18 11:00:21 +03:00 committed by GitHub
commit 3557bf00fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View file

@ -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;
});

View file

@ -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;
}

View file

@ -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;