mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	buddy list: Make small realms show all users.
For small-ish realms (<= 250 users), we ensure that the presence info includes all realm users the front end knows about, even in cases where the server sends down a slimmed version of presence data. We make the users "offline" by default, of course. This commit sets us up to optimize larger realms without concerns of breaking small realms. Small realms may want to continue to show all users, even users who may have been offline several weeks, since it doesn't clutter their API as much as it would for big realms.
This commit is contained in:
		@@ -66,16 +66,23 @@ var norbert = {
 | 
			
		||||
    full_name: 'Norbert Oswald',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
global.people.add(alice);
 | 
			
		||||
global.people.add(fred);
 | 
			
		||||
global.people.add(jill);
 | 
			
		||||
global.people.add(mark);
 | 
			
		||||
global.people.add(norbert);
 | 
			
		||||
global.people.add(me);
 | 
			
		||||
global.people.initialize_current_user(me.user_id);
 | 
			
		||||
var zoe = {
 | 
			
		||||
    email: 'zoe@example.com',
 | 
			
		||||
    user_id: 6,
 | 
			
		||||
    full_name: 'Zoe Yang',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var people = global.people;
 | 
			
		||||
 | 
			
		||||
people.add_in_realm(alice);
 | 
			
		||||
people.add_in_realm(fred);
 | 
			
		||||
people.add_in_realm(jill);
 | 
			
		||||
people.add_in_realm(mark);
 | 
			
		||||
people.add_in_realm(norbert);
 | 
			
		||||
people.add_in_realm(zoe);
 | 
			
		||||
people.add_in_realm(me);
 | 
			
		||||
people.initialize_current_user(me.user_id);
 | 
			
		||||
 | 
			
		||||
var activity = require('js/activity.js');
 | 
			
		||||
var compose_fade = require('js/compose_fade.js');
 | 
			
		||||
 | 
			
		||||
@@ -289,6 +296,10 @@ global.compile_template('user_presence_rows');
 | 
			
		||||
    assert.deepEqual(presence.presence_info[fred.user_id],
 | 
			
		||||
        { status: 'idle', mobile: false, last_active: 500}
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(presence.presence_info[zoe.user_id],
 | 
			
		||||
        { status: 'offline', mobile: false, last_active: undefined}
 | 
			
		||||
    );
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
presence.presence_info = {};
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,8 @@ exports.presence_info = {};
 | 
			
		||||
 */
 | 
			
		||||
var OFFLINE_THRESHOLD_SECS = 140;
 | 
			
		||||
 | 
			
		||||
var BIG_REALM_COUNT = 250;
 | 
			
		||||
 | 
			
		||||
var MOBILE_DEVICES = ["Android", "ZulipiOS", "ios"];
 | 
			
		||||
 | 
			
		||||
function is_mobile(device) {
 | 
			
		||||
@@ -106,6 +108,40 @@ exports.set_info = function (presences, server_timestamp) {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
    exports.update_info_for_small_realm();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.update_info_for_small_realm = function () {
 | 
			
		||||
    if (people.get_realm_count() >= BIG_REALM_COUNT) {
 | 
			
		||||
        // For big realms, we don't want to bloat our buddy
 | 
			
		||||
        // lists with lots of long-time-inactive users.
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // For small realms, we create presence info for users
 | 
			
		||||
    // that the server didn't include in its presence update.
 | 
			
		||||
    var presence_info = exports.presence_info;
 | 
			
		||||
    var persons = people.get_realm_persons();
 | 
			
		||||
 | 
			
		||||
    _.each(persons, function (person) {
 | 
			
		||||
        var user_id = person.user_id;
 | 
			
		||||
 | 
			
		||||
        if (people.is_my_user_id(user_id)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (presence_info[user_id]) {
 | 
			
		||||
            // this is normal, we have data for active
 | 
			
		||||
            // users that we don't want to clobber.
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        presence_info[user_id] = {
 | 
			
		||||
            status: "offline",
 | 
			
		||||
            mobile: false,
 | 
			
		||||
            last_active: undefined,
 | 
			
		||||
        };
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.last_active_date = function (user_id) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user