mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	refractor: Move get_visible_email from popovers.js to people.js.
This commit moves the get_visible_email function to people.js as this function will be used in other places and people.js seems relevant file for this. Tests are added to get full coverage.
This commit is contained in:
		@@ -1056,3 +1056,27 @@ run_test('emails_strings_to_user_ids_array', function () {
 | 
			
		||||
    user_ids = people.emails_strings_to_user_ids_array('dummyuser@example.com');
 | 
			
		||||
    assert.equal(user_ids, undefined);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('get_visible_email', function () {
 | 
			
		||||
    const steven = {
 | 
			
		||||
        email: 'steven@example.com',
 | 
			
		||||
        delivery_email: 'steven-delivery@example.com',
 | 
			
		||||
        user_id: 7,
 | 
			
		||||
        full_name: 'Steven',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const maria = {
 | 
			
		||||
        email: 'maria@example.com',
 | 
			
		||||
        user_id: 728,
 | 
			
		||||
        full_name: 'Maria',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    people.add(steven);
 | 
			
		||||
    people.add(maria);
 | 
			
		||||
 | 
			
		||||
    let email = people.get_visible_email(steven);
 | 
			
		||||
    assert.equal(email, steven.delivery_email);
 | 
			
		||||
 | 
			
		||||
    email = people.get_visible_email(maria);
 | 
			
		||||
    assert.equal(email, maria.email);
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -102,6 +102,13 @@ exports.update_email = function (user_id, new_email) {
 | 
			
		||||
    // still work correctly.
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.get_visible_email = function (user) {
 | 
			
		||||
    if (user.delivery_email) {
 | 
			
		||||
        return user.delivery_email;
 | 
			
		||||
    }
 | 
			
		||||
    return user.email;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.get_user_id = function (email) {
 | 
			
		||||
    const person = exports.get_by_email(email);
 | 
			
		||||
    if (person === undefined) {
 | 
			
		||||
 
 | 
			
		||||
@@ -149,13 +149,6 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {
 | 
			
		||||
    return profile_field;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function get_visible_email(user) {
 | 
			
		||||
    if (user.delivery_email) {
 | 
			
		||||
        return user.delivery_email;
 | 
			
		||||
    }
 | 
			
		||||
    return user.email;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function render_user_info_popover(user, popover_element, is_sender_popover, private_msg_class,
 | 
			
		||||
                                  template_class, popover_placement) {
 | 
			
		||||
    const is_me = people.is_my_user_id(user.user_id);
 | 
			
		||||
@@ -184,7 +177,7 @@ function render_user_info_popover(user, popover_element, is_sender_popover, priv
 | 
			
		||||
        sent_by_uri: hash_util.by_sender_uri(user.email),
 | 
			
		||||
        show_email: settings_data.show_email(),
 | 
			
		||||
        show_user_profile: !(user.is_bot || page_params.custom_profile_fields.length === 0),
 | 
			
		||||
        user_email: get_visible_email(user),
 | 
			
		||||
        user_email: people.get_visible_email(user),
 | 
			
		||||
        user_full_name: user.full_name,
 | 
			
		||||
        user_id: user.user_id,
 | 
			
		||||
        user_last_seen_time_status: buddy_data.user_last_seen_time_status(user.user_id),
 | 
			
		||||
@@ -307,7 +300,7 @@ exports.show_user_profile = function (user) {
 | 
			
		||||
 | 
			
		||||
    const args = {
 | 
			
		||||
        full_name: user.full_name,
 | 
			
		||||
        email: get_visible_email(user),
 | 
			
		||||
        email: people.get_visible_email(user),
 | 
			
		||||
        profile_data: profile_data,
 | 
			
		||||
        user_avatar: "avatar/" + user.email + "/medium",
 | 
			
		||||
        is_me: people.is_current_user(user.email),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user