Merge pull request #1104 from thelounge/xpaw/fix-autoaway

Fix away message disappearing
This commit is contained in:
Jérémie Astori 2017-04-28 18:15:52 +02:00 committed by GitHub
commit 26ccd2f1f8
3 changed files with 7 additions and 4 deletions

View File

@ -66,8 +66,9 @@ function Client(manager, name, config) {
if (typeof config !== "object") { if (typeof config !== "object") {
config = {}; config = {};
} }
_.merge(this, { _.merge(this, {
awayMessage: "", awayMessage: config.awayMessage || "",
lastActiveChannel: -1, lastActiveChannel: -1,
attachedClients: {}, attachedClients: {},
config: config, config: config,
@ -482,8 +483,6 @@ Client.prototype.clientAttach = function(socketId) {
var client = this; var client = this;
var save = false; var save = false;
client.attachedClients[socketId] = client.lastActiveChannel;
if (client.awayMessage && _.size(client.attachedClients) === 0) { if (client.awayMessage && _.size(client.attachedClients) === 0) {
client.networks.forEach(function(network) { client.networks.forEach(function(network) {
// Only remove away on client attachment if // 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 // Update old networks to store ip and hostmask
client.networks.forEach(network => { client.networks.forEach(network => {
if (!network.ip) { if (!network.ip) {
@ -539,7 +540,6 @@ Client.prototype.save = _.debounce(function SaveClient() {
const client = this; const client = this;
let json = {}; let json = {};
json.awayMessage = client.awayMessage;
json.networks = this.networks.map(n => n.export()); json.networks = this.networks.map(n => n.export());
client.manager.updateUser(client.name, json); client.manager.updateUser(client.name, json);
}, 1000, {maxWait: 10000}); }, 1000, {maxWait: 10000});

View File

@ -104,6 +104,7 @@ ClientManager.prototype.addUser = function(name, password, enableLog) {
user: name, user: name,
password: password || "", password: password || "",
log: enableLog, log: enableLog,
awayMessage: "",
networks: [] networks: []
}; };
fs.writeFileSync( fs.writeFileSync(

View File

@ -14,4 +14,6 @@ exports.input = function(network, chan, cmd, args) {
} }
network.awayMessage = reason; network.awayMessage = reason;
this.save();
}; };