diff --git a/lib/channel.js b/lib/channel.js index 9962e33c..61dd79c8 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -556,7 +556,7 @@ Channel.prototype.join = function (user) { self.sendVoteskipUpdate(self.users); self.sendUsercount(self.users); - user.once("channelRank", function () { + user.whenChannelRank(function () { if (!self.registered) { afterLogin(); return; diff --git a/lib/user.js b/lib/user.js index 1d5d5fe0..69edf303 100644 --- a/lib/user.js +++ b/lib/user.js @@ -16,6 +16,7 @@ function User(socket) { self.loggingIn = false; self.rank = -1; self.global_rank = -1; + self.hasChannelRank = false; self.channel = null; self.name = ""; self.canonicalName = ""; @@ -94,6 +95,10 @@ function User(socket) { self.initAdminCallbacks(); } }); + + self.once("channelRank", function () { + self.hasChannelRank = true; + }); } /** @@ -474,6 +479,14 @@ User.prototype.whenLoggedIn = function (fn) { } }; +User.prototype.whenChannelRank = function (fn) { + if (this.hasChannelRank) { + fn(); + } else { + this.once("channelRank", fn); + } +}; + User.prototype.login = function (name, pw) { var self = this; self.loggingIn = true;