瀏覽代碼

Merge pull request #826 from jitsi/fix-random-avatar

Fixes random avatar
master
hristoterezov 8 年之前
父節點
當前提交
19362d1904
共有 4 個文件被更改,包括 60 次插入8 次删除
  1. 8
    0
      conference.js
  2. 20
    6
      modules/UI/UI.js
  3. 16
    2
      modules/UI/avatar/Avatar.js
  4. 16
    0
      modules/settings/Settings.js

+ 8
- 0
conference.js 查看文件

@@ -48,6 +48,7 @@ const commands = {
48 48
     CONNECTION_QUALITY: "stats",
49 49
     EMAIL: "email",
50 50
     AVATAR_URL: "avatar-url",
51
+    AVATAR_ID: "avatar-id",
51 52
     ETHERPAD: "etherpad",
52 53
     SHARED_VIDEO: "shared-video",
53 54
     CUSTOM_ROLE: "custom-role"
@@ -758,6 +759,8 @@ export default {
758 759
         let avatarUrl = APP.settings.getAvatarUrl();
759 760
         avatarUrl && sendData(this.commands.defaults.AVATAR_URL,
760 761
             avatarUrl);
762
+        !email && sendData(
763
+             this.commands.defaults.AVATAR_ID, APP.settings.getAvatarId());
761 764
 
762 765
         let nick = APP.settings.getDisplayName();
763 766
         if (config.useNicks && !nick) {
@@ -1257,6 +1260,11 @@ export default {
1257 1260
             APP.UI.setUserAvatarUrl(from, data.value);
1258 1261
         });
1259 1262
 
1263
+        room.addCommandListener(this.commands.defaults.AVATAR_ID,
1264
+            (data, from) => {
1265
+                APP.UI.setUserAvatarID(from, data.value);
1266
+            });
1267
+
1260 1268
         APP.UI.addListener(UIEvents.NICKNAME_CHANGED, changeLocalDisplayName);
1261 1269
 
1262 1270
         APP.UI.addListener(UIEvents.START_MUTED_CHANGED,

+ 20
- 6
modules/UI/UI.js 查看文件

@@ -308,7 +308,12 @@ UI.initConference = function () {
308 308
     }
309 309
 
310 310
     // Make sure we configure our avatar id, before creating avatar for us
311
-    UI.setUserEmail(id, Settings.getEmail());
311
+    let email = Settings.getEmail();
312
+    if (email) {
313
+        UI.setUserEmail(id, email);
314
+    } else {
315
+        UI.setUserAvatarID(id, Settings.getAvatarId());
316
+    }
312 317
 
313 318
     Toolbar.checkAutoEnableDesktopSharing();
314 319
 
@@ -839,7 +844,7 @@ UI.dockToolbar = function (isDock) {
839 844
 /**
840 845
  * Updates the avatar for participant.
841 846
  * @param {string} id user id
842
- * @param {stirng} avatarUrl the URL for the avatar
847
+ * @param {string} avatarUrl the URL for the avatar
843 848
  */
844 849
 function changeAvatar(id, avatarUrl) {
845 850
     VideoLayout.changeUserAvatar(id, avatarUrl);
@@ -852,7 +857,7 @@ function changeAvatar(id, avatarUrl) {
852 857
 /**
853 858
  * Update user email.
854 859
  * @param {string} id user id
855
- * @param {stirng} email user email
860
+ * @param {string} email user email
856 861
  */
857 862
 UI.setUserEmail = function (id, email) {
858 863
     // update avatar
@@ -861,11 +866,22 @@ UI.setUserEmail = function (id, email) {
861 866
     changeAvatar(id, Avatar.getAvatarUrl(id));
862 867
 };
863 868
 
869
+/**
870
+ * Update user avtar id.
871
+ * @param {string} id user id
872
+ * @param {string} avatarId user's avatar id
873
+ */
874
+UI.setUserAvatarID = function (id, avatarId) {
875
+    // update avatar
876
+    Avatar.setUserAvatarID(id, avatarId);
877
+
878
+    changeAvatar(id, Avatar.getAvatarUrl(id));
879
+};
864 880
 
865 881
 /**
866 882
  * Update user avatar URL.
867 883
  * @param {string} id user id
868
- * @param {stirng} url user avatar url
884
+ * @param {string} url user avatar url
869 885
  */
870 886
 UI.setUserAvatarUrl = function (id, url) {
871 887
     // update avatar
@@ -1440,8 +1456,6 @@ UI.enableMicrophoneButton = function () {
1440 1456
     Toolbar.markAudioIconAsDisabled(false);
1441 1457
 };
1442 1458
 
1443
-let bottomToolbarEnabled = null;
1444
-
1445 1459
 UI.showRingOverLay = function () {
1446 1460
     RingOverlay.show(APP.tokenData.callee);
1447 1461
     FilmStrip.toggleFilmStrip(false);

+ 16
- 2
modules/UI/avatar/Avatar.js 查看文件

@@ -37,6 +37,15 @@ export default {
37 37
         this._setUserProp(id, "url", url);
38 38
     },
39 39
 
40
+    /**
41
+     * Sets the user's avatar id.
42
+     * @param id id of the user
43
+     * @param avatarId an id to be used for the avatar
44
+     */
45
+    setUserAvatarID: function (id, avatarId) {
46
+        this._setUserProp(id, "avatarId", avatarId);
47
+    },
48
+
40 49
     /**
41 50
      * Returns the URL of the image for the avatar of a particular user,
42 51
      * identified by its id.
@@ -55,11 +64,16 @@ export default {
55 64
         let avatarId = null;
56 65
         const user = users[userId];
57 66
 
67
+        // The priority is url, email and lowest is avatarId
58 68
         if(user) {
59 69
             if(user.url)
60
-                return users[userId].url;
70
+                return user.url;
61 71
 
62
-            avatarId = users[userId].email;
72
+            if (user.email)
73
+                avatarId = user.email;
74
+            else {
75
+                avatarId = user.avatarId;
76
+            }
63 77
         }
64 78
 
65 79
         // If the ID looks like an email, we'll use gravatar.

+ 16
- 0
modules/settings/Settings.js 查看文件

@@ -3,6 +3,7 @@
3 3
 import UIUtil from '../UI/util/UIUtil';
4 4
 
5 5
 let email = '';
6
+let avatarId = '';
6 7
 let displayName = '';
7 8
 let language = null;
8 9
 let cameraDeviceId = '';
@@ -35,6 +36,13 @@ if (supportsLocalStorage()) {
35 36
     }
36 37
 
37 38
     email = UIUtil.unescapeHtml(window.localStorage.email || '');
39
+    avatarId = UIUtil.unescapeHtml(window.localStorage.avatarId || '');
40
+    if (!avatarId) {
41
+        // if there is no avatar id, we generate a unique one and use it forever
42
+        avatarId = generateUniqueId();
43
+        window.localStorage.avatarId = avatarId;
44
+    }
45
+
38 46
     localFlipX = JSON.parse(window.localStorage.localFlipX || true);
39 47
     displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
40 48
     language = window.localStorage.language;
@@ -105,6 +113,14 @@ export default {
105 113
         return email;
106 114
     },
107 115
 
116
+    /**
117
+     * Returns avatar id of the local user.
118
+     * @returns {string} avatar id
119
+     */
120
+    getAvatarId: function () {
121
+        return avatarId;
122
+    },
123
+
108 124
     /**
109 125
      * Sets new avatarUrl for local user and saves it to the local storage.
110 126
      * @param {string} newAvatarUrl new avatarUrl for the local user

Loading…
取消
儲存