1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 23:35:46 +01:00

Sort usernames case-insensitively in user interface.

This commit is contained in:
Juliusz Chroboczek 2020-10-08 15:11:52 +02:00
parent 90ba4814c8
commit 2b4372ad87

View file

@ -1067,6 +1067,25 @@ function resizePeers() {
/** @type{Object<string,string>} */
let users = {};
/**
* Lexicographic order, with case differences secondary.
* @param{string} a
* @param{string} b
*/
function stringCompare(a, b) {
let la = a.toLowerCase()
let lb = b.toLowerCase()
if(la < lb)
return -1;
else if(la > lb)
return +1;
else if(a < b)
return -1;
else if(a > b)
return +1;
return 0
}
/**
* @param {string} id
* @param {string} name
@ -1088,8 +1107,8 @@ function addUser(id, name) {
let us = div.children;
for(let i = 0; i < us.length; i++) {
let child = us[i];
let childname = users[child.id.slice('user-'.length)];
if(!childname || childname > name) {
let childname = users[child.id.slice('user-'.length)] || null;
if(!childname || stringCompare(childname, name) > 0) {
div.insertBefore(user, child);
return;
}