Ver código fonte

feat(avatars): use initials service for getting images (#2312)

* feat(avatars): use initial service for getting images

* squash: capitalize and minor refactor of string concat
master
virtuacoplenny 7 anos atrás
pai
commit
2ea5ad68a5
1 arquivos alterados com 28 adições e 5 exclusões
  1. 28
    5
      react/features/base/participants/functions.js

+ 28
- 5
react/features/base/participants/functions.js Ver arquivo

@@ -24,11 +24,12 @@ declare var interfaceConfig: Object;
24 24
  * @returns {string} The URL of the image for the avatar of the specified
25 25
  * participant.
26 26
  */
27
-export function getAvatarURL({ avatarID, avatarURL, email, id }: {
27
+export function getAvatarURL({ avatarID, avatarURL, email, id, name }: {
28 28
         avatarID: string,
29 29
         avatarURL: string,
30 30
         email: string,
31
-        id: string
31
+        id: string,
32
+        name: string
32 33
 }) {
33 34
     // If disableThirdPartyRequests disables third-party avatar services, we are
34 35
     // restricted to a stock image of ours.
@@ -68,9 +69,8 @@ export function getAvatarURL({ avatarID, avatarURL, email, id }: {
68 69
         if (urlPrefix) {
69 70
             urlSuffix = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
70 71
         } else {
71
-            // Otherwise, use a default (meeples, of course).
72
-            urlPrefix = 'https://abotars.jitsi.net/meeple/';
73
-            urlSuffix = '';
72
+            urlPrefix = 'https://avatar-cdn.jitsi.net/';
73
+            urlSuffix = `/${_getInitials(name) || ' '}/200/avatar.png`;
74 74
         }
75 75
     }
76 76
 
@@ -223,3 +223,26 @@ function _getAllParticipants(stateful) {
223 223
             ? stateful
224 224
             : toState(stateful)['features/base/participants'] || []);
225 225
 }
226
+
227
+/**
228
+ * Gets the initials from a name, assuming a westernized name.
229
+ *
230
+ * @param {string} name - The name from which to parse initials.
231
+ * @private
232
+ * @returns {string}
233
+ */
234
+function _getInitials(name) {
235
+    if (!name) {
236
+        return '';
237
+    }
238
+
239
+    const nameParts = name.toUpperCase().split(' ');
240
+    const firstName = nameParts[0];
241
+    let initials = firstName[0];
242
+
243
+    if (nameParts.length > 1) {
244
+        initials += nameParts[nameParts.length - 1];
245
+    }
246
+
247
+    return initials;
248
+}

Carregando…
Cancelar
Salvar