mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Simplify buddy list status level sorting.
Introducing the level function makes it a bit more clear that active users get sorted to the top. It also shaves a couple milliseconds for large buddy lists, although that is mostly negligible compared to name sorting and rendering.
This commit is contained in:
		@@ -182,16 +182,22 @@ exports.huddle_fraction_present = function (huddle) {
 | 
			
		||||
function compare_function(a, b) {
 | 
			
		||||
    var presence_info = exports.presence_info;
 | 
			
		||||
 | 
			
		||||
    if (presence_info[a].status === 'active' && presence_info[b].status !== 'active') {
 | 
			
		||||
        return -1;
 | 
			
		||||
    } else if (presence_info[b].status === 'active' && presence_info[a].status !== 'active') {
 | 
			
		||||
    function level(status) {
 | 
			
		||||
        switch (status) {
 | 
			
		||||
            case 'active':
 | 
			
		||||
                return 1;
 | 
			
		||||
            case 'idle':
 | 
			
		||||
                return 2;
 | 
			
		||||
            default:
 | 
			
		||||
                return 3;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (presence_info[a].status === 'idle' && presence_info[b].status !== 'idle') {
 | 
			
		||||
        return -1;
 | 
			
		||||
    } else if (presence_info[b].status === 'idle' && presence_info[a].status !== 'idle') {
 | 
			
		||||
        return 1;
 | 
			
		||||
    var level_a = level(presence_info[a].status);
 | 
			
		||||
    var level_b = level(presence_info[b].status);
 | 
			
		||||
    var diff = level_a - level_b;
 | 
			
		||||
    if (diff !== 0) {
 | 
			
		||||
        return diff;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Sort equivalent PM names alphabetically
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user