Remove duplicates uid in the user list

pull/1/head
yflory 8 years ago
parent cfc5d634f4
commit f34492be94

@ -242,20 +242,26 @@ define([
return $userlist[0];
};
// TODO deduplicate users by uid
var getOtherUsers = function(myUserName, userList, userData) {
var i = 0;
var i = 0; // duplicates counter
var list = [];
var myUid = userData[myUserName] ? userData[myUserName].uid : undefined;
var uids = [];
userList.forEach(function(user) {
if(user !== myUserName) {
var data = (userData) ? (userData[user] || null) : null;
var userName = (data) ? data.name : null;
if(userName) {
var userId = (data) ? data.uid : null;
if (userName && uids.indexOf(userId) === -1 && (!myUid || userId !== myUid)) {
uids.push(userId);
list.push(userName);
}
} else { i++; }
}
});
return list;
return {
list: list,
duplicates: i
};
};
var arrayIntersect = function(a, b) {
@ -293,11 +299,13 @@ define([
// may contain data about users that have already left the channel.
userList = readOnly === -1 ? userList : arrayIntersect(userList, Object.keys(userData));
var numberOfEditUsers = userList.length;
var numberOfViewUsers = numberOfUsers - numberOfEditUsers;
// Names of editing users
var editUsersNames = getOtherUsers(myUserName, userList, userData);
var others = getOtherUsers(myUserName, userList, userData);
var editUsersNames = others.list;
var duplicates = others.duplicates;
var numberOfEditUsers = userList.length - duplicates;
var numberOfViewUsers = numberOfUsers - numberOfEditUsers - duplicates;
// Number of anonymous editing users
var anonymous = numberOfEditUsers - editUsersNames.length;
@ -307,21 +315,19 @@ define([
var $editUsers = $userButtons.find('.' + USERLIST_CLS);
$editUsers.html('').append($usersTitle);
var editUsersList = '';
var $editUsersList = $('<pre>');
if (readOnly !== 1) {
if (readOnly !== 1) { // Yourself - edit
$editUsers.append('<span class="yourself">' + Messages.yourself + '</span>');
anonymous--;
}
if (editUsersNames.length > 0) {
// Editors
$editUsersList.text(editUsersNames.join('\n')); // .text() to avoid XSS
$editUsers.append($editUsersList);
}
if (anonymous > 0) {
if (anonymous > 0) { // Anonymous editors
var text = anonymous === 1 ? Messages.anonymousUser : Messages.anonymousUsers;
$editUsers.append('<span class="anonymous">' + anonymous + ' ' + text + '</span>');
}
if (numberOfViewUsers > 0) {
if (numberOfViewUsers > 0) { // Viewers
var viewText = '<span class="viewer">';
if (numberOfEditUsers > 0) {
$editUsers.append('<br>');

Loading…
Cancel
Save