Resend userlist if rank changes meta visibility

Fixes #681.  Technically, resending the entire userlist is not
necessary; it would be sufficient to resent setUserMeta, but there's not
currently a bulk frame for that so sending the userlist is probably more
efficient.
This commit is contained in:
Calvin Montgomery 2017-06-17 09:38:19 -07:00
parent efae9c4774
commit 53cee986c6
5 changed files with 24 additions and 8 deletions

View file

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.38.0",
"version": "3.38.1",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View file

@ -423,6 +423,9 @@ Channel.prototype.acceptUser = function (user) {
// TODO: Drop legacy setAFK frame after a few months
self.broadcastAll("setAFK", { name: user.getName(), afk: afk });
})
user.on("effectiveRankChange", (newRank, oldRank) => {
this.maybeResendUserlist(user, newRank, oldRank);
});
};
Channel.prototype.partUser = function (user) {
@ -456,6 +459,15 @@ Channel.prototype.partUser = function (user) {
user.die();
};
Channel.prototype.maybeResendUserlist = function maybeResendUserlist(user, newRank, oldRank) {
if ((newRank >= 2 && oldRank < 2)
|| (newRank < 2 && oldRank >= 2)
|| (newRank >= 255 && oldRank < 255)
|| (newRank < 255 && oldRank >= 255)) {
this.sendUserlist([user]);
}
};
Channel.prototype.packUserData = function (user) {
var base = {
name: user.getName(),

View file

@ -754,7 +754,7 @@ PlaylistModule.prototype.handleAssignLeader = function (user, data) {
this.leader = null;
if (old.account.effectiveRank === 1.5) {
old.account.effectiveRank = old.account.oldRank;
old.emit("effectiveRankChange", old.account.effectiveRank);
old.emit("effectiveRankChange", old.account.effectiveRank, 1.5);
old.socket.emit("rank", old.account.effectiveRank);
}
@ -781,7 +781,7 @@ PlaylistModule.prototype.handleAssignLeader = function (user, data) {
if (this.leader.account.effectiveRank < 1.5) {
this.leader.account.oldRank = this.leader.account.effectiveRank;
this.leader.account.effectiveRank = 1.5;
this.leader.emit("effectiveRankChange", 1.5);
this.leader.emit("effectiveRankChange", 1.5, this.leader.account.oldRank);
this.leader.socket.emit("rank", 1.5);
}

View file

@ -119,9 +119,10 @@ RankModule.prototype.handleRankChange = function (user, data) {
return;
}
const oldRank = receiver.account.effectiveRank;
receiver.account.channelRank = rank;
receiver.account.effectiveRank = Math.max(receiver.account.globalRank, rank);
receiver.emit("effectiveRankChange", receiver.account.effectiveRank);
receiver.emit("effectiveRankChange", receiver.account.effectiveRank, oldRank);
receiver.socket.emit("rank", receiver.account.effectiveRank);
this.channel.logger.log("[mod] " + user.getName() + " set " + name + "'s rank " +
"to " + rank);

View file

@ -302,10 +302,11 @@ User.prototype.login = function (name, pw) {
return;
}
const oldRank = self.account.effectiveRank;
self.account.user = user;
self.account.update();
self.socket.emit("rank", self.account.effectiveRank);
self.emit("effectiveRankChange", self.account.effectiveRank);
self.emit("effectiveRankChange", self.account.effectiveRank, oldRank);
self.registrationTime = new Date(user.time);
self.setFlag(Flags.U_REGISTERED);
self.socket.emit("login", {
@ -381,10 +382,11 @@ User.prototype.guestLogin = function (name) {
// Login succeeded
lastguestlogin[self.realip] = Date.now();
const oldRank = self.account.effectiveRank;
self.account.guestName = name;
self.account.update();
self.socket.emit("rank", self.account.effectiveRank);
self.emit("effectiveRankChange", self.account.effectiveRank);
self.emit("effectiveRankChange", self.account.effectiveRank, oldRank);
self.socket.emit("login", {
success: true,
name: name,
@ -427,12 +429,13 @@ User.prototype.getFirstSeenTime = function getFirstSeenTime() {
};
User.prototype.setChannelRank = function setRank(rank) {
const changed = this.account.effectiveRank !== rank;
const oldRank = this.account.effectiveRank;
const changed = oldRank !== rank;
this.account.channelRank = rank;
this.account.update();
this.socket.emit("rank", this.account.effectiveRank);
if (changed) {
this.emit("effectiveRankChange", this.account.effectiveRank);
this.emit("effectiveRankChange", this.account.effectiveRank, oldRank);
}
};