Merge pull request #2390 from thelounge/xpaw/network-uuid

Remove network ids and use uuids everywhere
This commit is contained in:
Jérémie Astori 2018-04-27 01:23:49 -04:00 committed by GitHub
commit 92c4df6e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 38 additions and 43 deletions

View File

@ -9,7 +9,7 @@ const sidebar = $("#sidebar");
socket.on("join", function(data) {
const id = data.network;
const network = sidebar.find(`#network-${id}`);
const network = sidebar.find(`.network[data-uuid="${id}"]`);
const channels = network.children();
const position = $(channels[data.index || channels.length - 1]); // Put channel in correct position, or the end if we don't have one
const sidebarEntry = templates.chan({

View File

@ -19,12 +19,12 @@ socket.on("network", function(data) {
});
socket.on("network_changed", function(data) {
sidebar.find("#network-" + data.network).data("options", data.serverOptions);
sidebar.find(`.network[data-uuid="${data.network}"]`).data("options", data.serverOptions);
});
socket.on("network:status", function(data) {
sidebar
.find("#network-" + data.network)
.find(`.network[data-uuid="${data.network}"]`)
.toggleClass("not-connected", !data.connected)
.toggleClass("not-secure", !data.secure);
});

View File

@ -6,7 +6,7 @@ const socket = require("../socket");
socket.on("nick", function(data) {
const id = data.network;
const nick = data.nick;
const network = $("#sidebar").find("#network-" + id).data("nick", nick);
const network = $(`#sidebar .network[data-uuid="${id}"]`).data("nick", nick);
if (network.find(".active").length) {
$("#nick").text(nick);

View File

@ -7,7 +7,7 @@ const sidebar = $("#sidebar");
socket.on("quit", function(data) {
const id = data.network;
const network = sidebar.find(`#network-${id}`);
const network = sidebar.find(`.network[data-uuid="${id}"]`);
network.children(".chan").each(function() {
// this = child

View File

@ -13,10 +13,10 @@ socket.on("sync_sort", function(data) {
const type = data.type;
const order = data.order;
const container = $(".networks");
const network = container.find(`.network[data-uuid="${data.target}"]`);
if (type === "networks") {
const container = $(".networks");
$.each(order, function(index, value) {
const position = $(container.children()[index]);
@ -24,13 +24,9 @@ socket.on("sync_sort", function(data) {
return true; // No point in continuing
}
const network = container.find(`#network-${data.target}`);
$(network).insertBefore(position);
network.insertBefore(position);
});
} else if (type === "channels") {
const network = $(`#network-${data.target}`);
$.each(order, function(index, value) {
if (index === 0) { // Shouldn't attempt to move lobby
return true; // same as `continue` -> skip to next item
@ -44,7 +40,7 @@ socket.on("sync_sort", function(data) {
const channel = network.find(".chan[data-id=" + value + "]"); // Channel at position
$(channel).insertBefore(position);
channel.insertBefore(position);
});
}
});

View File

@ -21,7 +21,7 @@ module.exports = function() {
const order = [];
sidebar.find(".network").each(function() {
const id = $(this).data("id");
const id = $(this).data("uuid");
order.push(id);
});
@ -54,7 +54,7 @@ module.exports = function() {
socket.emit("sort", {
type: "channels",
target: network.data("id"),
target: network.data("uuid"),
order: order,
});

View File

@ -1,8 +1,6 @@
{{#each networks}}
<section
id="network-{{id}}"
class="network name-{{slugify name}} {{#if serverOptions.NETWORK}}network-{{slugify serverOptions.NETWORK}}{{/if}} {{#unless status.connected}}not-connected{{/unless}} {{#unless status.secure}}not-secure{{/unless}}"
data-id="{{id}}"
data-uuid="{{uuid}}"
data-nick="{{nick}}"
data-options="{{tojson serverOptions}}"

View File

@ -397,15 +397,18 @@ Client.prototype.sort = function(data) {
switch (data.type) {
case "networks":
this.networks.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
this.networks.sort((a, b) => order.indexOf(a.uuid) - order.indexOf(b.uuid));
// Sync order to connected clients
this.emit("sync_sort", {order: this.networks.map((obj) => obj.id), type: data.type, target: data.target});
this.emit("sync_sort", {
order: this.networks.map((obj) => obj.uuid),
type: data.type,
});
break;
case "channels": {
const network = _.find(this.networks, {id: data.target});
const network = _.find(this.networks, {uuid: data.target});
if (!network) {
return;
@ -414,7 +417,11 @@ Client.prototype.sort = function(data) {
network.channels.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
// Sync order to connected clients
this.emit("sync_sort", {order: network.channels.map((obj) => obj.id), type: data.type, target: data.target});
this.emit("sync_sort", {
order: network.channels.map((obj) => obj.id),
type: data.type,
target: network.uuid,
});
break;
}

View File

@ -9,8 +9,6 @@ const Helper = require("../helper");
module.exports = Network;
let id = 1;
/**
* @type {Object} List of keys which should not be sent to the client.
*/
@ -37,7 +35,6 @@ function Network(attr) {
channels: [],
ip: null,
hostname: null,
id: id++,
irc: null,
serverOptions: {
PREFIX: [],
@ -200,7 +197,7 @@ Network.prototype.edit = function(client, args) {
// Update UI nick straight away if IRC is not connected
client.emit("nick", {
network: this.id,
network: this.uuid,
nick: this.nick,
});
}

View File

@ -32,7 +32,7 @@ exports.input = function(network, chan, cmd, args) {
network.setNick(newNick);
this.emit("nick", {
network: network.id,
network: network.uuid,
nick: newNick,
});
}

View File

@ -49,7 +49,7 @@ exports.input = function(network, chan, cmd, args) {
});
this.emit("join", {
network: network.id,
network: network.uuid,
chan: newChan.getFilteredClone(true),
shouldOpen: true,
index: network.addChannel(newChan),

View File

@ -13,7 +13,7 @@ exports.input = function(network, chan, cmd, args) {
network.destroy();
client.save();
client.emit("quit", {
network: network.id,
network: network.uuid,
});
if (network.irc) {

View File

@ -38,7 +38,7 @@ module.exports = function(irc, network) {
name: chanName,
});
client.emit("join", {
network: network.id,
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});

View File

@ -106,7 +106,7 @@ module.exports = function(irc, network) {
if (Helper.config.debug.ircFramework) {
irc.on("debug", function(message) {
log.debug("[" + client.name + " (" + client.id + ") on " + network.name + " (#" + network.id + ")]", message);
log.debug(`[${client.name} (${client.id}) on ${network.name} (${network.uuid}]`, message);
});
}
@ -155,14 +155,14 @@ module.exports = function(irc, network) {
network.serverOptions.NETWORK = data.options.NETWORK;
client.emit("network_changed", {
network: network.id,
network: network.uuid,
serverOptions: network.serverOptions,
});
});
function sendStatus() {
const status = network.getNetworkStatus();
status.network = network.id;
status.network = network.uuid;
client.emit("network:status", status);
}

View File

@ -45,7 +45,7 @@ module.exports = function(irc, network) {
}
client.emit("nick", {
network: network.id,
network: network.uuid,
nick: irc.user.nick,
});
});
@ -64,7 +64,7 @@ module.exports = function(irc, network) {
}
client.emit("nick", {
network: network.id,
network: network.uuid,
nick: irc.user.nick,
});
});

View File

@ -17,7 +17,7 @@ module.exports = function(irc, network) {
});
client.emit("join", {
network: network.id,
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});

View File

@ -48,7 +48,7 @@ module.exports = function(irc, network) {
});
client.emit("join", {
network: network.id,
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});

View File

@ -69,7 +69,7 @@ module.exports = function(irc, network) {
});
client.emit("join", {
network: network.id,
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});

View File

@ -20,7 +20,7 @@ module.exports = function(irc, network) {
client.save();
client.emit("nick", {
network: network.id,
network: network.uuid,
nick: data.new_nick,
});
}

View File

@ -16,7 +16,7 @@ module.exports = function(irc, network) {
client.save();
client.emit("nick", {
network: network.id,
network: network.uuid,
nick: data.nick,
});
});

View File

@ -16,7 +16,7 @@ module.exports = function(irc, network) {
client.emit("join", {
shouldOpen: true,
network: network.id,
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});

View File

@ -120,12 +120,10 @@ 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",
id: 1000000,
guid: "newGuid",
});
expect(saveCalled).to.be.true;
expect(network.id).to.not.equal(1000000);
expect(network.guid).to.not.equal("newGuid");
expect(network.ip).to.be.null;
expect(network.hostname).to.be.null;
@ -227,7 +225,6 @@ describe("Network", function() {
"commands",
"host",
"hostname",
"id",
"ip",
"name",
"port",