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:
parent
efae9c4774
commit
53cee986c6
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.38.0",
|
"version": "3.38.1",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -423,6 +423,9 @@ Channel.prototype.acceptUser = function (user) {
|
||||||
// TODO: Drop legacy setAFK frame after a few months
|
// TODO: Drop legacy setAFK frame after a few months
|
||||||
self.broadcastAll("setAFK", { name: user.getName(), afk: afk });
|
self.broadcastAll("setAFK", { name: user.getName(), afk: afk });
|
||||||
})
|
})
|
||||||
|
user.on("effectiveRankChange", (newRank, oldRank) => {
|
||||||
|
this.maybeResendUserlist(user, newRank, oldRank);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Channel.prototype.partUser = function (user) {
|
Channel.prototype.partUser = function (user) {
|
||||||
|
@ -456,6 +459,15 @@ Channel.prototype.partUser = function (user) {
|
||||||
user.die();
|
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) {
|
Channel.prototype.packUserData = function (user) {
|
||||||
var base = {
|
var base = {
|
||||||
name: user.getName(),
|
name: user.getName(),
|
||||||
|
|
|
@ -754,7 +754,7 @@ PlaylistModule.prototype.handleAssignLeader = function (user, data) {
|
||||||
this.leader = null;
|
this.leader = null;
|
||||||
if (old.account.effectiveRank === 1.5) {
|
if (old.account.effectiveRank === 1.5) {
|
||||||
old.account.effectiveRank = old.account.oldRank;
|
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);
|
old.socket.emit("rank", old.account.effectiveRank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,7 +781,7 @@ PlaylistModule.prototype.handleAssignLeader = function (user, data) {
|
||||||
if (this.leader.account.effectiveRank < 1.5) {
|
if (this.leader.account.effectiveRank < 1.5) {
|
||||||
this.leader.account.oldRank = this.leader.account.effectiveRank;
|
this.leader.account.oldRank = this.leader.account.effectiveRank;
|
||||||
this.leader.account.effectiveRank = 1.5;
|
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);
|
this.leader.socket.emit("rank", 1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,9 +119,10 @@ RankModule.prototype.handleRankChange = function (user, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const oldRank = receiver.account.effectiveRank;
|
||||||
receiver.account.channelRank = rank;
|
receiver.account.channelRank = rank;
|
||||||
receiver.account.effectiveRank = Math.max(receiver.account.globalRank, 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);
|
receiver.socket.emit("rank", receiver.account.effectiveRank);
|
||||||
this.channel.logger.log("[mod] " + user.getName() + " set " + name + "'s rank " +
|
this.channel.logger.log("[mod] " + user.getName() + " set " + name + "'s rank " +
|
||||||
"to " + rank);
|
"to " + rank);
|
||||||
|
|
11
src/user.js
11
src/user.js
|
@ -302,10 +302,11 @@ User.prototype.login = function (name, pw) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const oldRank = self.account.effectiveRank;
|
||||||
self.account.user = user;
|
self.account.user = user;
|
||||||
self.account.update();
|
self.account.update();
|
||||||
self.socket.emit("rank", self.account.effectiveRank);
|
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.registrationTime = new Date(user.time);
|
||||||
self.setFlag(Flags.U_REGISTERED);
|
self.setFlag(Flags.U_REGISTERED);
|
||||||
self.socket.emit("login", {
|
self.socket.emit("login", {
|
||||||
|
@ -381,10 +382,11 @@ User.prototype.guestLogin = function (name) {
|
||||||
// Login succeeded
|
// Login succeeded
|
||||||
lastguestlogin[self.realip] = Date.now();
|
lastguestlogin[self.realip] = Date.now();
|
||||||
|
|
||||||
|
const oldRank = self.account.effectiveRank;
|
||||||
self.account.guestName = name;
|
self.account.guestName = name;
|
||||||
self.account.update();
|
self.account.update();
|
||||||
self.socket.emit("rank", self.account.effectiveRank);
|
self.socket.emit("rank", self.account.effectiveRank);
|
||||||
self.emit("effectiveRankChange", self.account.effectiveRank);
|
self.emit("effectiveRankChange", self.account.effectiveRank, oldRank);
|
||||||
self.socket.emit("login", {
|
self.socket.emit("login", {
|
||||||
success: true,
|
success: true,
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -427,12 +429,13 @@ User.prototype.getFirstSeenTime = function getFirstSeenTime() {
|
||||||
};
|
};
|
||||||
|
|
||||||
User.prototype.setChannelRank = function setRank(rank) {
|
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.channelRank = rank;
|
||||||
this.account.update();
|
this.account.update();
|
||||||
this.socket.emit("rank", this.account.effectiveRank);
|
this.socket.emit("rank", this.account.effectiveRank);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.emit("effectiveRankChange", this.account.effectiveRank);
|
this.emit("effectiveRankChange", this.account.effectiveRank, oldRank);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue