Browse Source

feat(Participant): reuse avatar URL generation logic

It was moved to js-utils, so make use of it.
j8
Saúl Ibarra Corretgé 7 years ago
parent
commit
057b300074
3 changed files with 17 additions and 38 deletions
  1. 1
    0
      package.json
  2. 13
    35
      react/features/base/participants/functions.js
  3. 3
    3
      webpack.config.js

+ 1
- 0
package.json View File

47
     "jquery-contextmenu": "2.4.5",
47
     "jquery-contextmenu": "2.4.5",
48
     "jquery-i18next": "1.2.0",
48
     "jquery-i18next": "1.2.0",
49
     "js-md5": "0.6.1",
49
     "js-md5": "0.6.1",
50
+    "js-utils": "github:jitsi/js-utils#446497893023aa8dec403e0e4e35a22cae6bc87d",
50
     "jsc-android": "224109.1.0",
51
     "jsc-android": "224109.1.0",
51
     "jsrsasign": "8.0.12",
52
     "jsrsasign": "8.0.12",
52
     "jwt-decode": "2.2.0",
53
     "jwt-decode": "2.2.0",

+ 13
- 35
react/features/base/participants/functions.js View File

1
 // @flow
1
 // @flow
2
-import md5 from 'js-md5';
2
+import { getAvatarURL as _getAvatarURL } from 'js-utils/avatar';
3
 
3
 
4
 import { toState } from '../redux';
4
 import { toState } from '../redux';
5
 
5
 
42
         return avatarURL;
42
         return avatarURL;
43
     }
43
     }
44
 
44
 
45
-    let key = email || avatarID;
46
-    let urlPrefix;
47
-    let urlSuffix;
48
-
49
-    // If the ID looks like an e-mail address, we'll use Gravatar because it
50
-    // supports e-mail addresses.
51
-    if (key && key.indexOf('@') > 0) {
52
-        urlPrefix = 'https://www.gravatar.com/avatar/';
53
-        urlSuffix = '?d=wavatar&size=200';
54
-    } else {
55
-        // Otherwise, we do not have much a choice but a random avatar (fetched
56
-        // from a configured avatar service).
57
-        if (!key) {
58
-            key = id;
59
-            if (!key) {
60
-                return undefined;
61
-            }
62
-        }
63
-
64
-        // The deployment is allowed to choose the avatar service which is to
65
-        // generate the random avatars.
66
-        urlPrefix
67
-            = typeof interfaceConfig === 'object'
68
-                && interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
69
-        if (urlPrefix) {
70
-            urlSuffix = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
71
-        } else {
72
-            // Otherwise, use a default (meeples, of course).
73
-            urlPrefix = 'https://abotars.jitsi.net/meeple/';
74
-            urlSuffix = '';
75
-        }
76
-    }
77
-
78
-    return urlPrefix + md5.hex(key.trim().toLowerCase()) + urlSuffix;
45
+    // The deployment is allowed to choose the avatar service which is to
46
+    // generate the random avatars.
47
+    const avatarService
48
+        = typeof interfaceConfig === 'object'
49
+                && interfaceConfig.RANDOM_AVATAR_URL_PREFIX
50
+            ? {
51
+                urlPrefix: interfaceConfig.RANDOM_AVATAR_URL_PREFIX,
52
+                urlSuffix: interfaceConfig.RANDOM_AVATAR_URL_SUFFIX }
53
+            : undefined;
54
+
55
+    // eslint-disable-next-line object-property-newline
56
+    return _getAvatarURL({ avatarID, email, id }, avatarService);
79
 }
57
 }
80
 
58
 
81
 /**
59
 /**

+ 3
- 3
webpack.config.js View File

15
     = process.argv.indexOf('-p') !== -1
15
     = process.argv.indexOf('-p') !== -1
16
         || process.argv.indexOf('--optimize-minimize') !== -1;
16
         || process.argv.indexOf('--optimize-minimize') !== -1;
17
 
17
 
18
-// eslint-disable-next-line camelcase
19
-const node_modules = `${__dirname}/node_modules/`;
20
 const plugins = [
18
 const plugins = [
21
     new webpack.LoaderOptionsPlugin({
19
     new webpack.LoaderOptionsPlugin({
22
         debug: !minimize,
20
         debug: !minimize,
62
             // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
60
             // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
63
             // as well.
61
             // as well.
64
 
62
 
65
-            exclude: node_modules, // eslint-disable-line camelcase
63
+            exclude: [
64
+                new RegExp(`${__dirname}/node_modules/(?!js-utils)`)
65
+            ],
66
             loader: 'babel-loader',
66
             loader: 'babel-loader',
67
             options: {
67
             options: {
68
                 // XXX The require.resolve bellow solves failures to locate the
68
                 // XXX The require.resolve bellow solves failures to locate the

Loading…
Cancel
Save