Generate uuid per network
This commit is contained in:
parent
d1648823c3
commit
731b29c059
@ -59,6 +59,7 @@
|
|||||||
"thelounge-ldapjs-non-maintained-fork": "1.0.2",
|
"thelounge-ldapjs-non-maintained-fork": "1.0.2",
|
||||||
"ua-parser-js": "0.7.17",
|
"ua-parser-js": "0.7.17",
|
||||||
"urijs": "1.19.1",
|
"urijs": "1.19.1",
|
||||||
|
"uuid": "3.2.1",
|
||||||
"web-push": "3.3.0",
|
"web-push": "3.3.0",
|
||||||
"yarn": "1.5.1"
|
"yarn": "1.5.1"
|
||||||
},
|
},
|
||||||
|
@ -174,6 +174,7 @@ Client.prototype.connect = function(args) {
|
|||||||
args.hostname = args.hostname || (client.config && client.config.hostname) || client.hostname;
|
args.hostname = args.hostname || (client.config && client.config.hostname) || client.hostname;
|
||||||
|
|
||||||
const network = new Network({
|
const network = new Network({
|
||||||
|
uuid: args.uuid,
|
||||||
name: args.name || (Helper.config.displayNetwork ? "" : Helper.config.defaults.name) || "",
|
name: args.name || (Helper.config.displayNetwork ? "" : Helper.config.defaults.name) || "",
|
||||||
host: args.host || "",
|
host: args.host || "",
|
||||||
port: parseInt(args.port, 10) || (args.tls ? 6697 : 6667),
|
port: parseInt(args.port, 10) || (args.tls ? 6697 : 6667),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
|
const uuidv4 = require("uuid/v4");
|
||||||
const Chan = require("./chan");
|
const Chan = require("./chan");
|
||||||
|
|
||||||
module.exports = Network;
|
module.exports = Network;
|
||||||
@ -42,6 +43,10 @@ function Network(attr) {
|
|||||||
chanCache: [],
|
chanCache: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!this.uuid) {
|
||||||
|
this.uuid = uuidv4();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.name) {
|
if (!this.name) {
|
||||||
this.name = this.host;
|
this.name = this.host;
|
||||||
}
|
}
|
||||||
@ -125,6 +130,7 @@ Network.prototype.getNetworkStatus = function() {
|
|||||||
|
|
||||||
Network.prototype.export = function() {
|
Network.prototype.export = function() {
|
||||||
const network = _.pick(this, [
|
const network = _.pick(this, [
|
||||||
|
"uuid",
|
||||||
"awayMessage",
|
"awayMessage",
|
||||||
"nick",
|
"nick",
|
||||||
"name",
|
"name",
|
||||||
|
@ -306,6 +306,7 @@ function initializeClient(socket, client, token, lastMessage) {
|
|||||||
// prevent people from overriding webirc settings
|
// prevent people from overriding webirc settings
|
||||||
data.ip = null;
|
data.ip = null;
|
||||||
data.hostname = null;
|
data.hostname = null;
|
||||||
|
data.uuid = null;
|
||||||
|
|
||||||
client.connect(data);
|
client.connect(data);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ describe("Network", function() {
|
|||||||
describe("#export()", function() {
|
describe("#export()", function() {
|
||||||
it("should produce an valid object", function() {
|
it("should produce an valid object", function() {
|
||||||
const network = new Network({
|
const network = new Network({
|
||||||
|
uuid: "hello world",
|
||||||
awayMessage: "I am away",
|
awayMessage: "I am away",
|
||||||
name: "networkName",
|
name: "networkName",
|
||||||
channels: [
|
channels: [
|
||||||
@ -24,6 +25,7 @@ describe("Network", function() {
|
|||||||
network.setNick("chillin`");
|
network.setNick("chillin`");
|
||||||
|
|
||||||
expect(network.export()).to.deep.equal({
|
expect(network.export()).to.deep.equal({
|
||||||
|
uuid: "hello world",
|
||||||
awayMessage: "I am away",
|
awayMessage: "I am away",
|
||||||
name: "networkName",
|
name: "networkName",
|
||||||
host: "",
|
host: "",
|
||||||
@ -47,6 +49,15 @@ describe("Network", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should generate uuid (v4) for each network", function() {
|
||||||
|
const network1 = new Network();
|
||||||
|
const network2 = new Network();
|
||||||
|
|
||||||
|
expect(network1.uuid).to.have.lengthOf(36);
|
||||||
|
expect(network2.uuid).to.have.lengthOf(36);
|
||||||
|
expect(network1.uuid).to.not.equal(network2.uuid);
|
||||||
|
});
|
||||||
|
|
||||||
it("lobby should be at the top", function() {
|
it("lobby should be at the top", function() {
|
||||||
const network = new Network({
|
const network = new Network({
|
||||||
name: "Super Nice Network",
|
name: "Super Nice Network",
|
||||||
@ -126,6 +137,7 @@ describe("Network", function() {
|
|||||||
"status",
|
"status",
|
||||||
"tls",
|
"tls",
|
||||||
"rejectUnauthorized",
|
"rejectUnauthorized",
|
||||||
|
"uuid",
|
||||||
"username"
|
"username"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user