Avatar.js code cleanup
This commit is contained in:
parent
a0355ea080
commit
6df1fcef40
|
@ -1,7 +1,8 @@
|
||||||
/* global Strophe, APP, MD5, config, interfaceConfig */
|
/* global MD5, config, interfaceConfig */
|
||||||
var users = {};
|
|
||||||
|
|
||||||
var Avatar = {
|
let users = {};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the user's avatar in the settings menu(if local user), contact list
|
* Sets the user's avatar in the settings menu(if local user), contact list
|
||||||
|
@ -16,48 +17,46 @@ var Avatar = {
|
||||||
}
|
}
|
||||||
users[id] = email;
|
users[id] = email;
|
||||||
}
|
}
|
||||||
var avatarUrl = this.getAvatarUrl(id);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URL of the image for the avatar of a particular user,
|
* Returns the URL of the image for the avatar of a particular user,
|
||||||
+ identified by its jid
|
* identified by its id.
|
||||||
* @param jid
|
* @param {string} userId user id
|
||||||
*/
|
*/
|
||||||
getAvatarUrl: function (jid) {
|
getAvatarUrl: function (userId) {
|
||||||
if (config.disableThirdPartyRequests) {
|
if (config.disableThirdPartyRequests) {
|
||||||
return 'images/avatar2.png';
|
return 'images/avatar2.png';
|
||||||
} else {
|
}
|
||||||
if (!jid) {
|
|
||||||
console.error("Get avatar - jid is undefined");
|
if (!userId) {
|
||||||
|
console.error("Get avatar - id is undefined");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var id = users[jid];
|
|
||||||
|
let avatarId = users[userId];
|
||||||
|
|
||||||
// If the ID looks like an email, we'll use gravatar.
|
// If the ID looks like an email, we'll use gravatar.
|
||||||
// Otherwise, it's a random avatar, and we'll use the configured
|
// Otherwise, it's a random avatar, and we'll use the configured
|
||||||
// URL.
|
// URL.
|
||||||
var random = !id || id.indexOf('@') < 0;
|
let random = !avatarId || avatarId.indexOf('@') < 0;
|
||||||
|
|
||||||
if (!id) {
|
if (!avatarId) {
|
||||||
console.warn(
|
console.warn(
|
||||||
"No avatar stored yet for " + jid + " - using JID as ID");
|
`No avatar stored yet for ${userId} - using ID as avatar ID`);
|
||||||
id = jid;
|
avatarId = userId;
|
||||||
}
|
}
|
||||||
id = MD5.hexdigest(id.trim().toLowerCase());
|
avatarId = MD5.hexdigest(avatarId.trim().toLowerCase());
|
||||||
|
|
||||||
// Default to using gravatar.
|
// Default to using gravatar.
|
||||||
var urlPref = 'https://www.gravatar.com/avatar/';
|
let urlPref = 'https://www.gravatar.com/avatar/';
|
||||||
var urlSuf = "?d=wavatar&size=100";
|
let urlSuf = "?d=wavatar&size=100";
|
||||||
|
|
||||||
if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
|
if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
|
||||||
urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
|
urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
|
||||||
urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
|
urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlPref + id + urlSuf;
|
return urlPref + avatarId + urlSuf;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = Avatar;
|
|
||||||
|
|
Loading…
Reference in New Issue