Quellcode durchsuchen

Centralise display name normalisation

j8
Bettenbuk Zoltan vor 6 Jahren
Ursprung
Commit
79209535ea

+ 3
- 4
conference.js Datei anzeigen

@@ -76,10 +76,10 @@ import {
76 76
     dominantSpeakerChanged,
77 77
     getAvatarURLByParticipantId,
78 78
     getLocalParticipant,
79
+    getNormalizedDisplayName,
79 80
     getParticipantById,
80 81
     localParticipantConnectionStatusChanged,
81 82
     localParticipantRoleChanged,
82
-    MAX_DISPLAY_NAME_LENGTH,
83 83
     participantConnectionStatusChanged,
84 84
     participantPresenceChanged,
85 85
     participantRoleChanged,
@@ -1847,7 +1847,7 @@ export default {
1847 1847
             JitsiConferenceEvents.DISPLAY_NAME_CHANGED,
1848 1848
             (id, displayName) => {
1849 1849
                 const formattedDisplayName
1850
-                    = displayName.substr(0, MAX_DISPLAY_NAME_LENGTH);
1850
+                    = getNormalizedDisplayName(displayName);
1851 1851
 
1852 1852
                 APP.store.dispatch(participantUpdated({
1853 1853
                     conference: room,
@@ -2633,8 +2633,7 @@ export default {
2633 2633
      * @param nickname {string} the new display name
2634 2634
      */
2635 2635
     changeLocalDisplayName(nickname = '') {
2636
-        const formattedNickname
2637
-            = nickname.trim().substr(0, MAX_DISPLAY_NAME_LENGTH);
2636
+        const formattedNickname = getNormalizedDisplayName(nickname);
2638 2637
         const { id, name } = getLocalParticipant(APP.store.getState());
2639 2638
 
2640 2639
         if (formattedNickname === name) {

+ 2
- 2
react/features/base/conference/actions.js Datei anzeigen

@@ -10,8 +10,8 @@ import { getName } from '../../app';
10 10
 import { JitsiConferenceEvents } from '../lib-jitsi-meet';
11 11
 import { setAudioMuted, setVideoMuted } from '../media';
12 12
 import {
13
-    MAX_DISPLAY_NAME_LENGTH,
14 13
     dominantSpeakerChanged,
14
+    getNormalizedDisplayName,
15 15
     participantConnectionStatusChanged,
16 16
     participantPresenceChanged,
17 17
     participantRoleChanged,
@@ -131,7 +131,7 @@ function _addConferenceListeners(conference, dispatch) {
131 131
         (id, displayName) => dispatch(participantUpdated({
132 132
             conference,
133 133
             id,
134
-            name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)
134
+            name: getNormalizedDisplayName(displayName)
135 135
         })));
136 136
 
137 137
     conference.on(

+ 7
- 4
react/features/base/participants/actions.js Datei anzeigen

@@ -17,8 +17,7 @@ import {
17 17
     PARTICIPANT_UPDATED,
18 18
     PIN_PARTICIPANT
19 19
 } from './actionTypes';
20
-import { MAX_DISPLAY_NAME_LENGTH } from './constants';
21
-import { getLocalParticipant } from './functions';
20
+import { getLocalParticipant, getNormalizedDisplayName } from './functions';
22 21
 
23 22
 /**
24 23
  * Create an action for when dominant speaker changes.
@@ -369,13 +368,17 @@ export function participantRoleChanged(id, role) {
369 368
  * }}
370 369
  */
371 370
 export function participantUpdated(participant = {}) {
371
+    const participantToUpdate = {
372
+        ...participant
373
+    };
374
+
372 375
     if (participant.name) {
373
-        participant.name = participant.name.substr(0, MAX_DISPLAY_NAME_LENGTH);
376
+        participantToUpdate.name = getNormalizedDisplayName(participant.name);
374 377
     }
375 378
 
376 379
     return {
377 380
         type: PARTICIPANT_UPDATED,
378
-        participant
381
+        participant: participantToUpdate
379 382
     };
380 383
 }
381 384
 

+ 16
- 0
react/features/base/participants/functions.js Datei anzeigen

@@ -6,6 +6,7 @@ import { toState } from '../redux';
6 6
 import {
7 7
     DEFAULT_AVATAR_RELATIVE_PATH,
8 8
     LOCAL_PARTICIPANT_DEFAULT_ID,
9
+    MAX_DISPLAY_NAME_LENGTH,
9 10
     PARTICIPANT_ROLE
10 11
 } from './constants';
11 12
 
@@ -94,6 +95,21 @@ export function getLocalParticipant(stateful: Object | Function) {
94 95
     return participants.find(p => p.local);
95 96
 }
96 97
 
98
+/**
99
+ * Normalizes a display name so then no invalid values (padding, length...etc)
100
+ * can be set.
101
+ *
102
+ * @param {string} name - The display name to set.
103
+ * @returns {string}
104
+ */
105
+export function getNormalizedDisplayName(name: string) {
106
+    if (!name || !name.trim()) {
107
+        return undefined;
108
+    }
109
+
110
+    return name.trim().substring(0, MAX_DISPLAY_NAME_LENGTH);
111
+}
112
+
97 113
 /**
98 114
  * Returns participant by ID from Redux state.
99 115
  *

Laden…
Abbrechen
Speichern