mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Transitions the frontend of the web app to no longer use the user status `away` field for setting a user's activity status to be 'unavailable' (which is now a deprecated way to access a user's `presence_enabled` setting). Instead we now directly use and update the user's `presence_enabled` setting for this feature. Renames frontend code related to the feature to `invisible_mode` vs `away`. We lose node test coverage in `user_status.js` because we are now using `channel.patch` to send these user setting updates to the server. Removes the temporary updates to `server_events_dispatch.py` (and related tests) made in a previous commit, since we no longer have or need the `away_user_ids` set.
		
			
				
	
	
		
			95 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import * as channel from "./channel";
 | 
						|
import * as emoji from "./emoji";
 | 
						|
import {user_settings} from "./user_settings";
 | 
						|
 | 
						|
const user_info = new Map();
 | 
						|
const user_status_emoji_info = new Map();
 | 
						|
 | 
						|
export function server_update_status(opts) {
 | 
						|
    channel.post({
 | 
						|
        url: "/json/users/me/status",
 | 
						|
        data: {
 | 
						|
            status_text: opts.status_text,
 | 
						|
            emoji_name: opts.emoji_name,
 | 
						|
            emoji_code: opts.emoji_code,
 | 
						|
            reaction_type: opts.reaction_type,
 | 
						|
        },
 | 
						|
        success() {
 | 
						|
            if (opts.success) {
 | 
						|
                opts.success();
 | 
						|
            }
 | 
						|
        },
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
export function server_invisible_mode_on() {
 | 
						|
    channel.patch({
 | 
						|
        url: "/json/settings",
 | 
						|
        data: {
 | 
						|
            presence_enabled: false,
 | 
						|
        },
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
export function server_invisible_mode_off() {
 | 
						|
    channel.patch({
 | 
						|
        url: "/json/settings",
 | 
						|
        data: {
 | 
						|
            presence_enabled: true,
 | 
						|
        },
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
export function get_status_text(user_id) {
 | 
						|
    return user_info.get(user_id);
 | 
						|
}
 | 
						|
 | 
						|
export function set_status_text(opts) {
 | 
						|
    if (!opts.status_text) {
 | 
						|
        user_info.delete(opts.user_id);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    user_info.set(opts.user_id, opts.status_text);
 | 
						|
}
 | 
						|
 | 
						|
export function get_status_emoji(user_id) {
 | 
						|
    return user_status_emoji_info.get(user_id);
 | 
						|
}
 | 
						|
 | 
						|
export function set_status_emoji(opts) {
 | 
						|
    if (!opts.emoji_name) {
 | 
						|
        user_status_emoji_info.delete(opts.user_id);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    user_status_emoji_info.set(opts.user_id, {
 | 
						|
        emoji_alt_code: user_settings.emojiset === "text",
 | 
						|
        ...emoji.get_emoji_details_for_rendering({
 | 
						|
            emoji_name: opts.emoji_name,
 | 
						|
            emoji_code: opts.emoji_code,
 | 
						|
            reaction_type: opts.reaction_type,
 | 
						|
        }),
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
export function initialize(params) {
 | 
						|
    user_info.clear();
 | 
						|
 | 
						|
    for (const [str_user_id, dct] of Object.entries(params.user_status)) {
 | 
						|
        // JSON does not allow integer keys, so we
 | 
						|
        // convert them here.
 | 
						|
        const user_id = Number.parseInt(str_user_id, 10);
 | 
						|
 | 
						|
        if (dct.status_text) {
 | 
						|
            user_info.set(user_id, dct.status_text);
 | 
						|
        }
 | 
						|
 | 
						|
        if (dct.emoji_name) {
 | 
						|
            user_status_emoji_info.set(user_id, {
 | 
						|
                ...emoji.get_emoji_details_for_rendering(dct),
 | 
						|
            });
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |