瀏覽代碼

feat(Participant): reuse avatar URL generation logic

It was moved to js-utils, so make use of it.
master
Saúl Ibarra Corretgé 6 年之前
父節點
當前提交
057b300074
共有 3 個檔案被更改,包括 17 行新增38 行删除
  1. 1
    0
      package.json
  2. 13
    35
      react/features/base/participants/functions.js
  3. 3
    3
      webpack.config.js

+ 1
- 0
package.json 查看文件

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

+ 13
- 35
react/features/base/participants/functions.js 查看文件

@@ -1,5 +1,5 @@
1 1
 // @flow
2
-import md5 from 'js-md5';
2
+import { getAvatarURL as _getAvatarURL } from 'js-utils/avatar';
3 3
 
4 4
 import { toState } from '../redux';
5 5
 
@@ -42,40 +42,18 @@ export function getAvatarURL({ avatarID, avatarURL, email, id }: {
42 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 查看文件

@@ -15,8 +15,6 @@ const minimize
15 15
     = process.argv.indexOf('-p') !== -1
16 16
         || process.argv.indexOf('--optimize-minimize') !== -1;
17 17
 
18
-// eslint-disable-next-line camelcase
19
-const node_modules = `${__dirname}/node_modules/`;
20 18
 const plugins = [
21 19
     new webpack.LoaderOptionsPlugin({
22 20
         debug: !minimize,
@@ -62,7 +60,9 @@ const config = {
62 60
             // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
63 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 66
             loader: 'babel-loader',
67 67
             options: {
68 68
                 // XXX The require.resolve bellow solves failures to locate the

Loading…
取消
儲存