Kaynağa Gözat

Centralise display name normalisation

j8
Bettenbuk Zoltan 6 yıl önce
ebeveyn
işleme
79209535ea

+ 3
- 4
conference.js Dosyayı Görüntüle

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

+ 2
- 2
react/features/base/conference/actions.js Dosyayı Görüntüle

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

+ 7
- 4
react/features/base/participants/actions.js Dosyayı Görüntüle

17
     PARTICIPANT_UPDATED,
17
     PARTICIPANT_UPDATED,
18
     PIN_PARTICIPANT
18
     PIN_PARTICIPANT
19
 } from './actionTypes';
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
  * Create an action for when dominant speaker changes.
23
  * Create an action for when dominant speaker changes.
369
  * }}
368
  * }}
370
  */
369
  */
371
 export function participantUpdated(participant = {}) {
370
 export function participantUpdated(participant = {}) {
371
+    const participantToUpdate = {
372
+        ...participant
373
+    };
374
+
372
     if (participant.name) {
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
     return {
379
     return {
377
         type: PARTICIPANT_UPDATED,
380
         type: PARTICIPANT_UPDATED,
378
-        participant
381
+        participant: participantToUpdate
379
     };
382
     };
380
 }
383
 }
381
 
384
 

+ 16
- 0
react/features/base/participants/functions.js Dosyayı Görüntüle

6
 import {
6
 import {
7
     DEFAULT_AVATAR_RELATIVE_PATH,
7
     DEFAULT_AVATAR_RELATIVE_PATH,
8
     LOCAL_PARTICIPANT_DEFAULT_ID,
8
     LOCAL_PARTICIPANT_DEFAULT_ID,
9
+    MAX_DISPLAY_NAME_LENGTH,
9
     PARTICIPANT_ROLE
10
     PARTICIPANT_ROLE
10
 } from './constants';
11
 } from './constants';
11
 
12
 
94
     return participants.find(p => p.local);
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
  * Returns participant by ID from Redux state.
114
  * Returns participant by ID from Redux state.
99
  *
115
  *

Loading…
İptal
Kaydet