From df0fc769d944d62893b2292a360b8ae1eb636345 Mon Sep 17 00:00:00 2001 From: Xaekai Date: Thu, 15 Jun 2017 21:48:17 -0700 Subject: [PATCH] Single source of truth for AFK Resolves #678 --- src/channel/channel.js | 4 ++++ src/user.js | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/channel/channel.js b/src/channel/channel.js index 519458fc..64f49b9c 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -417,6 +417,10 @@ Channel.prototype.acceptUser = function (user) { if (!this.is(Flags.C_REGISTERED)) { user.socket.emit("channelNotRegistered"); } + + user.on('afk', function(){ + self.sendUserMeta(self.users, user, -1); + }) }; Channel.prototype.partUser = function (user) { diff --git a/src/user.js b/src/user.js index ebe71d67..75d65c93 100644 --- a/src/user.js +++ b/src/user.js @@ -226,10 +226,7 @@ User.prototype.setAFK = function (afk) { this.channel.modules.voteskip.update(); } - this.channel.broadcastAll("setAFK", { - name: this.getName(), - afk: afk - }); + this.emit('afk', afk); }; /* Automatically tag a user as AFK after a period of inactivity */ @@ -424,7 +421,7 @@ User.prototype.getFirstSeenTime = function getFirstSeenTime() { return this.socket.ipSessionFirstSeen.getTime(); } else { LOGGER.error(`User "${this.getName()}" (IP: ${this.realip}) has neither ` + - "an IP sesion first seen time nor a registered account."); + "an IP session first seen time nor a registered account."); return Date.now(); } };