2015-09-11 03:05:53 +00:00
|
|
|
/* global Strophe, APP, MD5 */
|
2015-02-13 09:38:37 +00:00
|
|
|
var Settings = require("../../settings/Settings");
|
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
|
|
|
|
* @param jid jid of the user
|
|
|
|
* @param id email or userID to be used as a hash
|
|
|
|
*/
|
2015-01-07 14:54:03 +00:00
|
|
|
setUserAvatar: function (jid, id) {
|
|
|
|
if (id) {
|
|
|
|
if (users[jid] === id) {
|
2014-10-31 11:47:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
users[jid] = id;
|
|
|
|
}
|
2015-07-20 17:32:04 +00:00
|
|
|
var thumbUrl = this.getThumbUrl(jid);
|
|
|
|
var contactListUrl = this.getContactListUrl(jid);
|
2014-10-31 11:47:12 +00:00
|
|
|
var resourceJid = Strophe.getResourceFromJid(jid);
|
|
|
|
|
2015-06-29 14:24:21 +00:00
|
|
|
APP.UI.userAvatarChanged(resourceJid, thumbUrl, contactListUrl);
|
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
|
|
|
|
* where current active speaker is presented.
|
|
|
|
* @param jid full MUC jid of the user for whom we want to obtain avatar URL
|
|
|
|
*/
|
|
|
|
getActiveSpeakerUrl: function (jid) {
|
|
|
|
return this.getGravatarUrl(jid, 100);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns image URL for the avatar to be displayed on small video thumbnail
|
|
|
|
* @param jid full MUC jid of the user for whom we want to obtain avatar URL
|
|
|
|
*/
|
|
|
|
getThumbUrl: function (jid) {
|
|
|
|
return this.getGravatarUrl(jid, 100);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns the URL for the avatar to be displayed as contactlist item
|
|
|
|
* @param jid full MUC jid of the user for whom we want to obtain avatar URL
|
|
|
|
*/
|
|
|
|
getContactListUrl: function (jid) {
|
|
|
|
return this.getGravatarUrl(jid, 30);
|
|
|
|
},
|
|
|
|
getGravatarUrl: function (jid, size) {
|
|
|
|
if (!jid) {
|
|
|
|
console.error("Get gravatar - jid is undefined");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var id = users[jid];
|
|
|
|
if (!id) {
|
2015-07-30 08:31:02 +00:00
|
|
|
console.warn(
|
|
|
|
"No avatar stored yet for " + jid + " - using JID as ID");
|
|
|
|
id = jid;
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
2015-06-29 14:24:21 +00:00
|
|
|
return 'https://www.gravatar.com/avatar/' +
|
|
|
|
MD5.hexdigest(id.trim().toLowerCase()) +
|
|
|
|
"?d=wavatar&size=" + (size || "30");
|
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-01-07 14:54:03 +00:00
|
|
|
module.exports = Avatar;
|