2016-01-05 23:22:29 +00:00
|
|
|
/* global Strophe, APP, MD5, config, interfaceConfig */
|
2015-01-07 14:54:03 +00:00
|
|
|
var users = {};
|
|
|
|
|
|
|
|
var Avatar = {
|
|
|
|
|
2014-10-31 11:47:12 +00:00
|
|
|
/**
|
|
|
|
* Sets the user's avatar in the settings menu(if local user), contact list
|
|
|
|
* and thumbnail
|
2015-12-02 15:24:57 +00:00
|
|
|
* @param id id of the user
|
|
|
|
* @param email email or nickname to be used as a hash
|
2014-10-31 11:47:12 +00:00
|
|
|
*/
|
2015-12-02 15:24:57 +00:00
|
|
|
setUserAvatar: function (id, email) {
|
|
|
|
if (email) {
|
|
|
|
if (users[id] === email) {
|
2014-10-31 11:47:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-12-02 15:24:57 +00:00
|
|
|
users[id] = email;
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
2015-12-02 15:24:57 +00:00
|
|
|
var thumbUrl = this.getThumbUrl(id);
|
|
|
|
var contactListUrl = this.getContactListUrl(id);
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2015-07-20 17:32:04 +00:00
|
|
|
/**
|
|
|
|
* Returns image URL for the avatar to be displayed on large video area
|
2016-01-12 00:14:01 +00:00
|
|
|
* where current dominant speaker is presented.
|
2015-12-02 15:24:57 +00:00
|
|
|
* @param id id of the user for whom we want to obtain avatar URL
|
2015-07-20 17:32:04 +00:00
|
|
|
*/
|
2016-01-12 00:14:01 +00:00
|
|
|
getDominantSpeakerUrl: function (id) {
|
2015-12-02 15:24:57 +00:00
|
|
|
return this.getGravatarUrl(id, 100);
|
2015-07-20 17:32:04 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns image URL for the avatar to be displayed on small video thumbnail
|
2015-12-02 15:24:57 +00:00
|
|
|
* @param id id of the user for whom we want to obtain avatar URL
|
2015-07-20 17:32:04 +00:00
|
|
|
*/
|
2015-12-02 15:24:57 +00:00
|
|
|
getThumbUrl: function (id) {
|
|
|
|
return this.getGravatarUrl(id, 100);
|
2015-07-20 17:32:04 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns the URL for the avatar to be displayed as contactlist item
|
2015-12-02 15:24:57 +00:00
|
|
|
* @param id id of the user for whom we want to obtain avatar URL
|
2015-07-20 17:32:04 +00:00
|
|
|
*/
|
2015-12-02 15:24:57 +00:00
|
|
|
getContactListUrl: function (id) {
|
|
|
|
return this.getGravatarUrl(id, 30);
|
2015-07-20 17:32:04 +00:00
|
|
|
},
|
2015-12-02 15:24:57 +00:00
|
|
|
getGravatarUrl: function (id, size) {
|
|
|
|
if (!id) {
|
|
|
|
console.error("Get gravatar - id is undefined");
|
2015-07-20 17:32:04 +00:00
|
|
|
return null;
|
|
|
|
}
|
2016-01-05 23:22:29 +00:00
|
|
|
|
|
|
|
// Default to using gravatar.
|
|
|
|
var urlPref = 'https://www.gravatar.com/avatar/';
|
|
|
|
var urlSuf = "?d=wavatar&size=" + (size || "30");
|
|
|
|
|
|
|
|
// If we have a real email we will use it for the gravatar and we'll
|
|
|
|
// use the pre-configured URL if any. Otherwise, it's a random avatar.
|
2015-12-02 15:24:57 +00:00
|
|
|
var email = users[id];
|
2016-01-05 23:22:29 +00:00
|
|
|
if (email && email.indexOf('@')) {
|
|
|
|
id = email;
|
|
|
|
|
|
|
|
if (interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
|
|
|
|
urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
|
|
|
|
urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
|
|
|
|
}
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
2016-01-05 23:22:29 +00:00
|
|
|
|
2015-12-08 22:51:29 +00:00
|
|
|
if (!config.disableThirdPartyRequests) {
|
2016-01-05 23:22:29 +00:00
|
|
|
return urlPref +
|
2015-12-07 20:41:35 +00:00
|
|
|
MD5.hexdigest(id.trim().toLowerCase()) +
|
2016-01-05 23:22:29 +00:00
|
|
|
urlSuf;
|
2015-12-07 20:41:35 +00:00
|
|
|
} else {
|
|
|
|
return 'images/avatar2.png';
|
|
|
|
}
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
};
|
2014-10-31 11:47:12 +00:00
|
|
|
|
|
|
|
|
2015-12-07 20:41:35 +00:00
|
|
|
module.exports = Avatar;
|