Start refactoring leader and rank

This commit is contained in:
calzoneman 2013-11-08 22:12:17 -06:00
parent 7fc50db879
commit 30c5f67d4d
3 changed files with 68 additions and 17 deletions

View File

@ -1004,13 +1004,15 @@ Channel.prototype.sendUserlist = function(user) {
users.push({ users.push({
name: this.users[i].name, name: this.users[i].name,
rank: this.users[i].rank, rank: this.users[i].rank,
leader: this.users[i] == this.leader,
meta: this.users[i].meta, meta: this.users[i].meta,
profile: this.users[i].profile profile: this.users[i].profile
}); });
} }
} }
user.socket.emit("userlist", users); user.socket.emit("userlist", users);
if (this.leader !== null) {
user.socket.emit("setLeader", this.leader.name);
}
} }
// Send the last 15 messages for context // Send the last 15 messages for context
@ -1101,7 +1103,6 @@ Channel.prototype.broadcastNewUser = function(user) {
self.sendAll("addUser", { self.sendAll("addUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
leader: self.leader == user,
meta: user.meta, meta: user.meta,
profile: user.profile profile: user.profile
}); });
@ -1130,7 +1131,6 @@ Channel.prototype.broadcastUserUpdate = function(user) {
this.sendAll("updateUser", { this.sendAll("updateUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
leader: this.leader == user,
meta: user.meta, meta: user.meta,
profile: user.profile profile: user.profile
}); });
@ -2354,15 +2354,20 @@ Channel.prototype.changeLeader = function(name) {
if(old.rank == 1.5) { if(old.rank == 1.5) {
old.rank = old.oldrank; old.rank = old.oldrank;
} }
this.broadcastUserUpdate(old); this.sendAll("setUserRank", {
name: name,
rank: old.rank
});
} }
if(name == "") { if(name == "") {
this.sendAll("setLeader", "");
this.logger.log("*** Resuming autolead"); this.logger.log("*** Resuming autolead");
this.playlist.lead(true); this.playlist.lead(true);
return; return;
} }
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
if(this.users[i].name == name) { if(this.users[i].name == name) {
this.sendAll("setLeader", name);
this.logger.log("*** Assigned leader: " + name); this.logger.log("*** Assigned leader: " + name);
this.playlist.lead(false); this.playlist.lead(false);
this.leader = this.users[i]; this.leader = this.users[i];
@ -2370,7 +2375,10 @@ Channel.prototype.changeLeader = function(name) {
this.users[i].oldrank = this.users[i].rank; this.users[i].oldrank = this.users[i].rank;
this.users[i].rank = 1.5; this.users[i].rank = 1.5;
} }
this.broadcastUserUpdate(this.leader); this.sendAll("setUserRank", {
name: name,
rank: this.users[i].rank
});
} }
} }
} }

View File

@ -673,6 +673,10 @@ Callbacks = {
.addClass("userlist_item"); .addClass("userlist_item");
var flair = $("<span/>").appendTo(div); var flair = $("<span/>").appendTo(div);
var nametag = $("<span/>").text(data.name).appendTo(div); var nametag = $("<span/>").text(data.name).appendTo(div);
div.data("name", data.name);
div.data("rank", data.rank);
div.data("leader", false);
div.data("profile", data.profile);
formatUserlistItem(div, data); formatUserlistItem(div, data);
addUserDropdown(div, data); addUserDropdown(div, data);
div.appendTo($("#userlist")); div.appendTo($("#userlist"));
@ -682,13 +686,44 @@ Callbacks = {
setLeader: function (name) { setLeader: function (name) {
$(".userlist_item").each(function () { $(".userlist_item").each(function () {
$(this).find(".icon-star-empty").remove(); $(this).find(".icon-star-empty").remove();
if ($(this).data("leader")) {
$(this).data("leader", false);
addUserDropdown($(this));
}
}); });
if (name === "") if (name === "")
return; return;
var user = findUserlistItem(name); var user = findUserlistItem(name);
if (user) { if (user) {
$("<i/>").addClass("icon-star-empty").prependTo(user.children()[0]); user.data("leader", true);
formatUserlistItem(user);
addUserDropdown(user);
} }
if (name === CLIENT.name) {
CLIENT.leader = true;
// I'm a leader! Set up sync function
if(LEADTMR)
clearInterval(LEADTMR);
LEADTMR = setInterval(sendVideoUpdate, 5000);
} else {
CLIENT.leader = false;
if(LEADTMR)
clearInterval(LEADTMR);
LEADTMR = false;
}
},
setUserRank: function (data) {
var user = findUserlistItem(data.name);
if (user === null) {
return;
}
user.data("rank", data.rank);
formatUserlistItem(user);
addUserDropdown(user);
if(USEROPTS.sort_rank)
sortUserlist();
}, },
updateUser: function(data) { updateUser: function(data) {
@ -712,6 +747,7 @@ Callbacks = {
} }
var user = findUserlistItem(data.name); var user = findUserlistItem(data.name);
if(user !== null) { if(user !== null) {
user.data("rank", data.rank);
formatUserlistItem(user, data); formatUserlistItem(user, data);
addUserDropdown(user, data); addUserDropdown(user, data);
if(USEROPTS.sort_rank) if(USEROPTS.sort_rank)

View File

@ -77,7 +77,13 @@ function findUserlistItem(name) {
return null; return null;
} }
function formatUserlistItem(div, data) { function formatUserlistItem(div) {
var data = {
name: div.data("name") || "",
rank: div.data("rank"),
profile: div.data("profile") || { image: "", text: ""},
leader: div.data("leader") || false
};
var name = $(div.children()[1]); var name = $(div.children()[1]);
name.removeClass(); name.removeClass();
name.css("font-style", ""); name.css("font-style", "");
@ -109,7 +115,6 @@ function formatUserlistItem(div, data) {
name.mouseleave(function() { name.mouseleave(function() {
profile.remove(); profile.remove();
}); });
var flair = div.children()[0]; var flair = div.children()[0];
flair.innerHTML = ""; flair.innerHTML = "";
// denote current leader with a star // denote current leader with a star
@ -138,11 +143,10 @@ function getNameColor(rank) {
return ""; return "";
} }
function addUserDropdown(entry, data) { function addUserDropdown(entry) {
entry.data("dropdown-info", data); var name = entry.data("name"),
var name = data.name, rank = entry.data("rank"),
rank = data.rank, leader = entry.data("leader");
leader = data.leader;
entry.find(".user-dropdown").remove(); entry.find(".user-dropdown").remove();
var menu = $("<div/>") var menu = $("<div/>")
.addClass("user-dropdown") .addClass("user-dropdown")
@ -285,7 +289,10 @@ function calcUserBreakdown() {
}; };
var total = 0; var total = 0;
$("#userlist .userlist_item").each(function (index, item) { $("#userlist .userlist_item").each(function (index, item) {
var data = $(item).data("dropdown-info"); var data = {
rank: $(item).data("rank")
};
if(data.rank >= 255) if(data.rank >= 255)
breakdown["Site Admins"]++; breakdown["Site Admins"]++;
else if(data.rank >= 3) else if(data.rank >= 3)
@ -312,8 +319,8 @@ function sortUserlist() {
var slice = Array.prototype.slice; var slice = Array.prototype.slice;
var list = slice.call($("#userlist .userlist_item")); var list = slice.call($("#userlist .userlist_item"));
list.sort(function (a, b) { list.sort(function (a, b) {
var r1 = $(a).data("dropdown-info").rank; var r1 = $(a).data("rank");
var r2 = $(b).data("dropdown-info").rank; var r2 = $(b).data("rank");
var afk1 = $(a).find(".icon-time").length > 0; var afk1 = $(a).find(".icon-time").length > 0;
var afk2 = $(b).find(".icon-time").length > 0; var afk2 = $(b).find(".icon-time").length > 0;
var name1 = a.children[1].innerHTML.toLowerCase(); var name1 = a.children[1].innerHTML.toLowerCase();
@ -1132,7 +1139,7 @@ function handlePermissionChange() {
} }
var users = $("#userlist").children(); var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) { for(var i = 0; i < users.length; i++) {
addUserDropdown($(users[i]), $(users[i]).data("dropdown-info")); addUserDropdown($(users[i]));
} }
$("#chatline").attr("disabled", !hasPermission("chat")); $("#chatline").attr("disabled", !hasPermission("chat"));