Browse Source

Uses a single avatar URL, allows to override gravatar with a custom URL for avatars in interface_config.js.

j8
Boris Grozev 9 years ago
parent
commit
a2c41392dd

+ 3
- 1
interface_config.js View File

27
     /**
27
     /**
28
      * Whether to only show the filmstrip (and hide the toolbar).
28
      * Whether to only show the filmstrip (and hide the toolbar).
29
      */
29
      */
30
-    filmStripOnly: false
30
+    filmStripOnly: false,
31
+    RANDOM_AVATAR_URL_PREFIX: false,
32
+    RANDOM_AVATAR_URL_SUFFIX: false
31
 };
33
 };

+ 4
- 4
modules/UI/UI.js View File

896
     }
896
     }
897
 };
897
 };
898
 
898
 
899
-UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
900
-    VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
901
-    ContactList.userAvatarChanged(resourceJid, contactListUrl);
899
+UI.userAvatarChanged = function (resourceJid, avatarUrl) {
900
+    VideoLayout.userAvatarChanged(resourceJid, avatarUrl);
901
+    ContactList.userAvatarChanged(resourceJid, avatarUrl);
902
     if(resourceJid === APP.xmpp.myResource())
902
     if(resourceJid === APP.xmpp.myResource())
903
-        SettingsMenu.changeAvatar(thumbUrl);
903
+        SettingsMenu.changeAvatar(avatarUrl);
904
 };
904
 };
905
 
905
 
906
 UI.setVideoMute = setVideoMute;
906
 UI.setVideoMute = setVideoMute;

+ 37
- 41
modules/UI/avatar/Avatar.js View File

1
-/* global Strophe, APP, MD5, config */
1
+/* global Strophe, APP, MD5, config, interfaceConfig */
2
 var Settings = require("../../settings/Settings");
2
 var Settings = require("../../settings/Settings");
3
 
3
 
4
 var users = {};
4
 var users = {};
18
             }
18
             }
19
             users[jid] = id;
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
         var resourceJid = Strophe.getResourceFromJid(jid);
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
      * @param jid full MUC jid of the user for whom we want to obtain avatar URL
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
             return 'images/avatar2.png';
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
 module.exports = Avatar;
68
 module.exports = Avatar;

+ 3
- 3
modules/UI/side_pannels/contactlist/ContactList.js View File

32
 function createAvatar(jid) {
32
 function createAvatar(jid) {
33
     var avatar = document.createElement('img');
33
     var avatar = document.createElement('img');
34
     avatar.className = "icon-avatar avatar";
34
     avatar.className = "icon-avatar avatar";
35
-    avatar.src = Avatar.getContactListUrl(jid);
35
+    avatar.src = Avatar.getAvatarUrl(jid);
36
 
36
 
37
     return avatar;
37
     return avatar;
38
 }
38
 }
181
             contactName.html(displayName);
181
             contactName.html(displayName);
182
     },
182
     },
183
 
183
 
184
-    userAvatarChanged: function (resourceJid, contactListUrl) {
184
+    userAvatarChanged: function (resourceJid, avatarUrl) {
185
         // set the avatar in the contact list
185
         // set the avatar in the contact list
186
         var contact = $('#' + resourceJid + '>img');
186
         var contact = $('#' + resourceJid + '>img');
187
         if (contact && contact.length > 0) {
187
         if (contact && contact.length > 0) {
188
-            contact.get(0).src = contactListUrl;
188
+            contact.get(0).src = avatarUrl;
189
         }
189
         }
190
 
190
 
191
     }
191
     }

+ 1
- 1
modules/UI/videolayout/LargeVideo.js View File

242
 function updateActiveSpeakerAvatarSrc() {
242
 function updateActiveSpeakerAvatarSrc() {
243
     var avatar = $("#activeSpeakerAvatar")[0];
243
     var avatar = $("#activeSpeakerAvatar")[0];
244
     var jid = currentSmallVideo.peerJid;
244
     var jid = currentSmallVideo.peerJid;
245
-    var url = Avatar.getActiveSpeakerUrl(jid);
245
+    var url = Avatar.getAvatarUrl(jid);
246
     if (avatar.src === url)
246
     if (avatar.src === url)
247
         return;
247
         return;
248
     if (jid) {
248
     if (jid) {

+ 1
- 1
modules/UI/videolayout/SmallVideo.js View File

369
     if (!this.hasAvatar) {
369
     if (!this.hasAvatar) {
370
         if (this.peerJid) {
370
         if (this.peerJid) {
371
             // Init avatar
371
             // Init avatar
372
-            this.avatarChanged(Avatar.getThumbUrl(this.peerJid));
372
+            this.avatarChanged(Avatar.getAvatarUrl(this.peerJid));
373
         } else {
373
         } else {
374
             console.error("Unable to init avatar - no peerjid", this);
374
             console.error("Unable to init avatar - no peerjid", this);
375
             return;
375
             return;

+ 3
- 3
modules/UI/videolayout/VideoLayout.js View File

1005
         }
1005
         }
1006
     };
1006
     };
1007
 
1007
 
1008
-    my.userAvatarChanged = function(resourceJid, thumbUrl) {
1008
+    my.userAvatarChanged = function(resourceJid, avatarUrl) {
1009
         var smallVideo = VideoLayout.getSmallVideo(resourceJid);
1009
         var smallVideo = VideoLayout.getSmallVideo(resourceJid);
1010
         if(smallVideo)
1010
         if(smallVideo)
1011
-            smallVideo.avatarChanged(thumbUrl);
1011
+            smallVideo.avatarChanged(avatarUrl);
1012
         else
1012
         else
1013
             console.warn(
1013
             console.warn(
1014
                 "Missed avatar update - no small video yet for " + resourceJid);
1014
                 "Missed avatar update - no small video yet for " + resourceJid);
1015
-        LargeVideo.updateAvatar(resourceJid, thumbUrl);
1015
+        LargeVideo.updateAvatar(resourceJid, avatarUrl);
1016
     };
1016
     };
1017
 
1017
 
1018
     my.createEtherpadIframe = function(src, onloadHandler)
1018
     my.createEtherpadIframe = function(src, onloadHandler)

Loading…
Cancel
Save