mirror of https://github.com/calzoneman/sync.git
Start refactoring leader and rank
This commit is contained in:
parent
7fc50db879
commit
30c5f67d4d
|
@ -1004,13 +1004,15 @@ Channel.prototype.sendUserlist = function(user) {
|
|||
users.push({
|
||||
name: this.users[i].name,
|
||||
rank: this.users[i].rank,
|
||||
leader: this.users[i] == this.leader,
|
||||
meta: this.users[i].meta,
|
||||
profile: this.users[i].profile
|
||||
});
|
||||
}
|
||||
}
|
||||
user.socket.emit("userlist", users);
|
||||
if (this.leader !== null) {
|
||||
user.socket.emit("setLeader", this.leader.name);
|
||||
}
|
||||
}
|
||||
|
||||
// Send the last 15 messages for context
|
||||
|
@ -1101,7 +1103,6 @@ Channel.prototype.broadcastNewUser = function(user) {
|
|||
self.sendAll("addUser", {
|
||||
name: user.name,
|
||||
rank: user.rank,
|
||||
leader: self.leader == user,
|
||||
meta: user.meta,
|
||||
profile: user.profile
|
||||
});
|
||||
|
@ -1130,7 +1131,6 @@ Channel.prototype.broadcastUserUpdate = function(user) {
|
|||
this.sendAll("updateUser", {
|
||||
name: user.name,
|
||||
rank: user.rank,
|
||||
leader: this.leader == user,
|
||||
meta: user.meta,
|
||||
profile: user.profile
|
||||
});
|
||||
|
@ -2354,15 +2354,20 @@ Channel.prototype.changeLeader = function(name) {
|
|||
if(old.rank == 1.5) {
|
||||
old.rank = old.oldrank;
|
||||
}
|
||||
this.broadcastUserUpdate(old);
|
||||
this.sendAll("setUserRank", {
|
||||
name: name,
|
||||
rank: old.rank
|
||||
});
|
||||
}
|
||||
if(name == "") {
|
||||
this.sendAll("setLeader", "");
|
||||
this.logger.log("*** Resuming autolead");
|
||||
this.playlist.lead(true);
|
||||
return;
|
||||
}
|
||||
for(var i = 0; i < this.users.length; i++) {
|
||||
if(this.users[i].name == name) {
|
||||
this.sendAll("setLeader", name);
|
||||
this.logger.log("*** Assigned leader: " + name);
|
||||
this.playlist.lead(false);
|
||||
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].rank = 1.5;
|
||||
}
|
||||
this.broadcastUserUpdate(this.leader);
|
||||
this.sendAll("setUserRank", {
|
||||
name: name,
|
||||
rank: this.users[i].rank
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -673,6 +673,10 @@ Callbacks = {
|
|||
.addClass("userlist_item");
|
||||
var flair = $("<span/>").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);
|
||||
addUserDropdown(div, data);
|
||||
div.appendTo($("#userlist"));
|
||||
|
@ -682,13 +686,44 @@ Callbacks = {
|
|||
setLeader: function (name) {
|
||||
$(".userlist_item").each(function () {
|
||||
$(this).find(".icon-star-empty").remove();
|
||||
if ($(this).data("leader")) {
|
||||
$(this).data("leader", false);
|
||||
addUserDropdown($(this));
|
||||
}
|
||||
});
|
||||
if (name === "")
|
||||
return;
|
||||
var user = findUserlistItem(name);
|
||||
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) {
|
||||
|
@ -712,6 +747,7 @@ Callbacks = {
|
|||
}
|
||||
var user = findUserlistItem(data.name);
|
||||
if(user !== null) {
|
||||
user.data("rank", data.rank);
|
||||
formatUserlistItem(user, data);
|
||||
addUserDropdown(user, data);
|
||||
if(USEROPTS.sort_rank)
|
||||
|
|
|
@ -77,7 +77,13 @@ function findUserlistItem(name) {
|
|||
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]);
|
||||
name.removeClass();
|
||||
name.css("font-style", "");
|
||||
|
@ -109,7 +115,6 @@ function formatUserlistItem(div, data) {
|
|||
name.mouseleave(function() {
|
||||
profile.remove();
|
||||
});
|
||||
|
||||
var flair = div.children()[0];
|
||||
flair.innerHTML = "";
|
||||
// denote current leader with a star
|
||||
|
@ -138,11 +143,10 @@ function getNameColor(rank) {
|
|||
return "";
|
||||
}
|
||||
|
||||
function addUserDropdown(entry, data) {
|
||||
entry.data("dropdown-info", data);
|
||||
var name = data.name,
|
||||
rank = data.rank,
|
||||
leader = data.leader;
|
||||
function addUserDropdown(entry) {
|
||||
var name = entry.data("name"),
|
||||
rank = entry.data("rank"),
|
||||
leader = entry.data("leader");
|
||||
entry.find(".user-dropdown").remove();
|
||||
var menu = $("<div/>")
|
||||
.addClass("user-dropdown")
|
||||
|
@ -285,7 +289,10 @@ function calcUserBreakdown() {
|
|||
};
|
||||
var total = 0;
|
||||
$("#userlist .userlist_item").each(function (index, item) {
|
||||
var data = $(item).data("dropdown-info");
|
||||
var data = {
|
||||
rank: $(item).data("rank")
|
||||
};
|
||||
|
||||
if(data.rank >= 255)
|
||||
breakdown["Site Admins"]++;
|
||||
else if(data.rank >= 3)
|
||||
|
@ -312,8 +319,8 @@ function sortUserlist() {
|
|||
var slice = Array.prototype.slice;
|
||||
var list = slice.call($("#userlist .userlist_item"));
|
||||
list.sort(function (a, b) {
|
||||
var r1 = $(a).data("dropdown-info").rank;
|
||||
var r2 = $(b).data("dropdown-info").rank;
|
||||
var r1 = $(a).data("rank");
|
||||
var r2 = $(b).data("rank");
|
||||
var afk1 = $(a).find(".icon-time").length > 0;
|
||||
var afk2 = $(b).find(".icon-time").length > 0;
|
||||
var name1 = a.children[1].innerHTML.toLowerCase();
|
||||
|
@ -1132,7 +1139,7 @@ function handlePermissionChange() {
|
|||
}
|
||||
var users = $("#userlist").children();
|
||||
for(var i = 0; i < users.length; i++) {
|
||||
addUserDropdown($(users[i]), $(users[i]).data("dropdown-info"));
|
||||
addUserDropdown($(users[i]));
|
||||
}
|
||||
|
||||
$("#chatline").attr("disabled", !hasPermission("chat"));
|
||||
|
|
Loading…
Reference in New Issue