<commit_before>/* global Strophe, APP, MD5, config, interfaceConfig */
var users = {};

var Avatar = {

    /**
     * Sets the user's avatar in the settings menu(if local user), contact list
     * and thumbnail
     * @param id id of the user
     * @param email email or nickname to be used as a hash
     */
  setUserAvatar: function (id, email) {
        if (email) {
            if (users[id] === email) {
                return;
            }
            users[id] = email;
        }
        var avatarUrl = this.getAvatarUrl(id);
    },
    /**
     * Returns the URL of the image for the avatar of a particular user,
     + identified by its jid
     * @param jid
     */
    getAvatarUrl: function (jid) {
        if (config.disableThirdPartyRequests) {
            return 'images/avatar2.png';
        } else {
            if (!jid) {
                console.error("Get avatar - jid is undefined");
                    return null;
            }
            var id = users[jid];

            // If the ID looks like an email, we'll use gravatar.
            // Otherwise, it's a random avatar, and we'll use the configured
            // URL.
            var random = !id || id.indexOf('@') < 0;

            if (!id) {
                console.warn(
                "No avatar stored yet for " + jid + " - using JID as ID");
                id = jid;
            }
            id = MD5.hexdigest(id.trim().toLowerCase());

            // Default to using gravatar.
            var urlPref = 'https://www.gravatar.com/avatar/';
            var urlSuf = "?d=wavatar&size=100";

            if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
                urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
                urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
            }

            return urlPref + id + urlSuf;
        }
    }
};


module.exports = Avatar;
<commit_msg>Avatar.js code cleanup<commit_after>/* global MD5, config, interfaceConfig */

let users = {};

export default {

    /**
     * Sets the user's avatar in the settings menu(if local user), contact list
     * and thumbnail
     * @param id id of the user
     * @param email email or nickname to be used as a hash
     */
    setUserAvatar: function (id, email) {
        if (email) {
            if (users[id] === email) {
                return;
            }
            users[id] = email;
        }
    },

    /**
     * Returns the URL of the image for the avatar of a particular user,
     * identified by its id.
     * @param {string} userId user id
     */
    getAvatarUrl: function (userId) {
        if (config.disableThirdPartyRequests) {
            return 'images/avatar2.png';
        }

        if (!userId) {
            console.error("Get avatar - id is undefined");
            return null;
        }

        let avatarId = users[userId];

        // If the ID looks like an email, we'll use gravatar.
        // Otherwise, it's a random avatar, and we'll use the configured
        // URL.
        let random = !avatarId || avatarId.indexOf('@') < 0;

        if (!avatarId) {
            console.warn(
                `No avatar stored yet for ${userId} - using ID as avatar ID`);
            avatarId = userId;
        }
        avatarId = MD5.hexdigest(avatarId.trim().toLowerCase());

        // Default to using gravatar.
        let urlPref = 'https://www.gravatar.com/avatar/';
        let urlSuf = "?d=wavatar&size=100";

        if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
            urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
            urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
        }

        return urlPref + avatarId + urlSuf;
    }
};

{'fraction_non_alphanumeric': 0.10707559860102232, 'fraction_numerical': 0.003766478342749529, 'mean_word_length': 1.6481481481481481, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7120734', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1078, 'n_words': 322}