|
@@ -1,4 +1,4 @@
|
1
|
|
-/* global Strophe, APP, MD5, config */
|
|
1
|
+/* global Strophe, APP, MD5, config, interfaceConfig */
|
2
|
2
|
var Settings = require("../../settings/Settings");
|
3
|
3
|
|
4
|
4
|
var users = {};
|
|
@@ -18,55 +18,51 @@ var Avatar = {
|
18
|
18
|
}
|
19
|
19
|
users[jid] = id;
|
20
|
20
|
}
|
21
|
|
- var thumbUrl = this.getThumbUrl(jid);
|
22
|
|
- var contactListUrl = this.getContactListUrl(jid);
|
|
21
|
+ var avatarUrl = this.getAvatarUrl(jid);
|
23
|
22
|
var resourceJid = Strophe.getResourceFromJid(jid);
|
24
|
23
|
|
25
|
|
- APP.UI.userAvatarChanged(resourceJid, thumbUrl, contactListUrl);
|
|
24
|
+ APP.UI.userAvatarChanged(resourceJid, avatarUrl);
|
26
|
25
|
},
|
27
|
26
|
/**
|
28
|
|
- * Returns image URL for the avatar to be displayed on large video area
|
29
|
|
- * where current active speaker is presented.
|
|
27
|
+ * Returns the URL of the image for the avatar of a particular user,
|
|
28
|
+ * identified by its jid
|
|
29
|
+ * @param jid
|
30
|
30
|
* @param jid full MUC jid of the user for whom we want to obtain avatar URL
|
31
|
31
|
*/
|
32
|
|
- getActiveSpeakerUrl: function (jid) {
|
33
|
|
- return this.getGravatarUrl(jid, 100);
|
34
|
|
- },
|
35
|
|
- /**
|
36
|
|
- * Returns image URL for the avatar to be displayed on small video thumbnail
|
37
|
|
- * @param jid full MUC jid of the user for whom we want to obtain avatar URL
|
38
|
|
- */
|
39
|
|
- getThumbUrl: function (jid) {
|
40
|
|
- return this.getGravatarUrl(jid, 100);
|
41
|
|
- },
|
42
|
|
- /**
|
43
|
|
- * Returns the URL for the avatar to be displayed as contactlist item
|
44
|
|
- * @param jid full MUC jid of the user for whom we want to obtain avatar URL
|
45
|
|
- */
|
46
|
|
- getContactListUrl: function (jid) {
|
47
|
|
- return this.getGravatarUrl(jid, 30);
|
48
|
|
- },
|
49
|
|
- getGravatarUrl: function (jid, size) {
|
50
|
|
- if (!jid) {
|
51
|
|
- console.error("Get gravatar - jid is undefined");
|
52
|
|
- return null;
|
53
|
|
- }
|
54
|
|
- var id = users[jid];
|
55
|
|
- if (!id) {
|
56
|
|
- console.warn(
|
57
|
|
- "No avatar stored yet for " + jid + " - using JID as ID");
|
58
|
|
- id = jid;
|
59
|
|
- }
|
60
|
|
- if (!config.disableThirdPartyRequests) {
|
61
|
|
- return 'https://www.gravatar.com/avatar/' +
|
62
|
|
- MD5.hexdigest(id.trim().toLowerCase()) +
|
63
|
|
- "?d=wavatar&size=" + (size || "30");
|
64
|
|
- } else {
|
|
32
|
+ getAvatarUrl: function (jid) {
|
|
33
|
+ if (config.disableThirdPartyRequests) {
|
65
|
34
|
return 'images/avatar2.png';
|
|
35
|
+ } else {
|
|
36
|
+ if (!jid) {
|
|
37
|
+ console.error("Get avatar - jid is undefined");
|
|
38
|
+ return null;
|
|
39
|
+ }
|
|
40
|
+ var id = users[jid];
|
|
41
|
+
|
|
42
|
+ // If the ID looks like an email, we'll use gravatar.
|
|
43
|
+ // Otherwise, it's a random avatar, and we'll use the configured
|
|
44
|
+ // URL.
|
|
45
|
+ var random = !id || id.indexOf('@') < 0;
|
|
46
|
+
|
|
47
|
+ if (!id) {
|
|
48
|
+ console.warn(
|
|
49
|
+ "No avatar stored yet for " + jid + " - using JID as ID");
|
|
50
|
+ id = jid;
|
|
51
|
+ }
|
|
52
|
+ id = MD5.hexdigest(id.trim().toLowerCase());
|
|
53
|
+
|
|
54
|
+ // Default to using gravatar.
|
|
55
|
+ var urlPref = 'https://www.gravatar.com/avatar/';
|
|
56
|
+ var urlSuf = "?d=wavatar&size=100";
|
|
57
|
+
|
|
58
|
+ if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
|
|
59
|
+ urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
|
|
60
|
+ urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ return urlPref + id + urlSuf;
|
66
|
64
|
}
|
67
|
65
|
}
|
68
|
|
-
|
69
|
66
|
};
|
70
|
67
|
|
71
|
|
-
|
72
|
68
|
module.exports = Avatar;
|