diff --git a/src/client.js b/src/client.js index aa3b7045..554f2b6c 100644 --- a/src/client.js +++ b/src/client.js @@ -66,8 +66,9 @@ function Client(manager, name, config) { if (typeof config !== "object") { config = {}; } + _.merge(this, { - awayMessage: "", + awayMessage: config.awayMessage || "", lastActiveChannel: -1, attachedClients: {}, config: config, @@ -482,8 +483,6 @@ Client.prototype.clientAttach = function(socketId) { var client = this; var save = false; - client.attachedClients[socketId] = client.lastActiveChannel; - if (client.awayMessage && _.size(client.attachedClients) === 0) { client.networks.forEach(function(network) { // Only remove away on client attachment if @@ -494,6 +493,8 @@ Client.prototype.clientAttach = function(socketId) { }); } + client.attachedClients[socketId] = client.lastActiveChannel; + // Update old networks to store ip and hostmask client.networks.forEach(network => { if (!network.ip) { @@ -539,7 +540,6 @@ Client.prototype.save = _.debounce(function SaveClient() { const client = this; let json = {}; - json.awayMessage = client.awayMessage; json.networks = this.networks.map(n => n.export()); client.manager.updateUser(client.name, json); }, 1000, {maxWait: 10000}); diff --git a/src/clientManager.js b/src/clientManager.js index a0f94f0f..6e73af19 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -104,6 +104,7 @@ ClientManager.prototype.addUser = function(name, password, enableLog) { user: name, password: password || "", log: enableLog, + awayMessage: "", networks: [] }; fs.writeFileSync( diff --git a/src/plugins/inputs/away.js b/src/plugins/inputs/away.js index 34c58596..aa4d604b 100644 --- a/src/plugins/inputs/away.js +++ b/src/plugins/inputs/away.js @@ -14,4 +14,6 @@ exports.input = function(network, chan, cmd, args) { } network.awayMessage = reason; + + this.save(); };