Hoist sortUserlist outside of userlist population inner loop

This commit is contained in:
Calvin Montgomery 2018-05-24 23:49:28 -07:00
parent bfe0d75278
commit fdab26b792
4 changed files with 29 additions and 23 deletions

View File

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

View File

@ -487,32 +487,13 @@ Callbacks = {
userlist: function(data) {
$(".userlist_item").remove();
for(var i = 0; i < data.length; i++) {
Callbacks.addUser(data[i]);
CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data[i]);
}
sortUserlist();
},
addUser: function(data) {
var user = findUserlistItem(data.name);
// Remove previous instance of user, if there was one
if(user !== null)
user.remove();
var div = $("<div/>")
.addClass("userlist_item");
var icon = $("<span/>").appendTo(div);
var nametag = $("<span/>").text(data.name).appendTo(div);
div.data("name", data.name);
div.data("rank", data.rank);
div.data("leader", Boolean(data.leader));
div.data("profile", data.profile);
div.data("meta", data.meta);
if (data.meta.muted || data.meta.smuted) {
div.data("icon", "glyphicon-volume-off");
} else {
div.data("icon", false);
}
formatUserlistItem(div);
addUserDropdown(div, data);
div.appendTo($("#userlist"));
CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data);
sortUserlist();
},

View File

@ -76,6 +76,7 @@ CyTube.ui = {
CyTube.featureFlag = {
efficientEmotes: true
};
CyTube._internal_do_not_use_or_you_will_be_banned = {};
function getOpt(k) {
var v = NO_STORAGE ? readCookie(k) : localStorage.getItem(k);

View File

@ -3363,3 +3363,27 @@ CyTube.ui.changeVideoWidth = function uiChangeVideoWidth(direction) {
handleVideoResize();
};
CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList = function (data) {
var user = findUserlistItem(data.name);
// Remove previous instance of user, if there was one
if(user !== null)
user.remove();
var div = $("<div/>")
.addClass("userlist_item");
var icon = $("<span/>").appendTo(div);
var nametag = $("<span/>").text(data.name).appendTo(div);
div.data("name", data.name);
div.data("rank", data.rank);
div.data("leader", Boolean(data.leader));
div.data("profile", data.profile);
div.data("meta", data.meta);
if (data.meta.muted || data.meta.smuted) {
div.data("icon", "glyphicon-volume-off");
} else {
div.data("icon", false);
}
formatUserlistItem(div);
addUserDropdown(div, data);
div.appendTo($("#userlist"));
};