mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	desktop-presence: Use system presence data from electron-bridge.
Combined with work in the desktop app, this makes it possible for the desktop app to clearly indicate to other users whether the current user is active on the system and thus would see a desktop notification, not just whether they are active in the current Zulip window. Essentially rewritten by tabbott to add unit tests and consider the desktop app data authoritative.
This commit is contained in:
		@@ -894,3 +894,26 @@ run_test('away_status', () => {
 | 
			
		||||
    activity.on_revoke_away(alice.user_id);
 | 
			
		||||
    assert(!user_status.is_away(alice.user_id));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('electron_bridge', () => {
 | 
			
		||||
    activity.client_is_active = false;
 | 
			
		||||
    window.electron_bridge = undefined;
 | 
			
		||||
    assert.equal(activity.compute_active_status(), activity.IDLE);
 | 
			
		||||
 | 
			
		||||
    activity.client_is_active = true;
 | 
			
		||||
    assert.equal(activity.compute_active_status(), activity.ACTIVE);
 | 
			
		||||
 | 
			
		||||
    window.electron_bridge = {
 | 
			
		||||
        idle_on_system: true,
 | 
			
		||||
    };
 | 
			
		||||
    assert.equal(activity.compute_active_status(), activity.IDLE);
 | 
			
		||||
    activity.client_is_active = false;
 | 
			
		||||
    assert.equal(activity.compute_active_status(), activity.IDLE);
 | 
			
		||||
 | 
			
		||||
    window.electron_bridge = {
 | 
			
		||||
        idle_on_system: false,
 | 
			
		||||
    };
 | 
			
		||||
    assert.equal(activity.compute_active_status(), activity.ACTIVE);
 | 
			
		||||
    activity.client_is_active = true;
 | 
			
		||||
    assert.equal(activity.compute_active_status(), activity.ACTIVE);
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -262,23 +262,42 @@ exports.update_huddles = function () {
 | 
			
		||||
    show_huddles();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.compute_active_status = function () {
 | 
			
		||||
    // The overall algorithm intent for the `status` field is to send
 | 
			
		||||
    // `ACTIVE` (aka green circle) if we know the user is at their
 | 
			
		||||
    // computer, and IDLE (aka orange circle) if the user might not
 | 
			
		||||
    // be:
 | 
			
		||||
    //
 | 
			
		||||
    // * For the webapp, we just know whether this window has focus.
 | 
			
		||||
    // * For the electron desktop app, we also know whether the
 | 
			
		||||
    //   user is active or idle elsewhere on their system.
 | 
			
		||||
    //
 | 
			
		||||
    // The check for `idle_on_system === undefined` is feature
 | 
			
		||||
    // detection; older desktop app releases never set that property.
 | 
			
		||||
    if (window.electron_bridge !== undefined
 | 
			
		||||
            && window.electron_bridge.idle_on_system !== undefined) {
 | 
			
		||||
        if (window.electron_bridge.idle_on_system) {
 | 
			
		||||
            return exports.IDLE;
 | 
			
		||||
        }
 | 
			
		||||
        return exports.ACTIVE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (exports.client_is_active) {
 | 
			
		||||
        return exports.ACTIVE;
 | 
			
		||||
    }
 | 
			
		||||
    return exports.IDLE;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function send_presence_to_server(want_redraw) {
 | 
			
		||||
    var status;
 | 
			
		||||
    if (reload_state.is_in_progress()) {
 | 
			
		||||
        blueslip.log("Skipping querying presence because reload in progress");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (exports.client_is_active) {
 | 
			
		||||
        status = exports.ACTIVE;
 | 
			
		||||
    } else {
 | 
			
		||||
        status = exports.IDLE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    channel.post({
 | 
			
		||||
        url: '/json/users/me/presence',
 | 
			
		||||
        data: {
 | 
			
		||||
            status: status,
 | 
			
		||||
            status: exports.compute_active_status(),
 | 
			
		||||
            ping_only: !want_redraw,
 | 
			
		||||
            new_user_input: exports.new_user_input,
 | 
			
		||||
        },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user