Centralise display name normalisation
This commit is contained in:
parent
4bddae0bdb
commit
79209535ea
|
@ -76,10 +76,10 @@ import {
|
|||
dominantSpeakerChanged,
|
||||
getAvatarURLByParticipantId,
|
||||
getLocalParticipant,
|
||||
getNormalizedDisplayName,
|
||||
getParticipantById,
|
||||
localParticipantConnectionStatusChanged,
|
||||
localParticipantRoleChanged,
|
||||
MAX_DISPLAY_NAME_LENGTH,
|
||||
participantConnectionStatusChanged,
|
||||
participantPresenceChanged,
|
||||
participantRoleChanged,
|
||||
|
@ -1847,7 +1847,7 @@ export default {
|
|||
JitsiConferenceEvents.DISPLAY_NAME_CHANGED,
|
||||
(id, displayName) => {
|
||||
const formattedDisplayName
|
||||
= displayName.substr(0, MAX_DISPLAY_NAME_LENGTH);
|
||||
= getNormalizedDisplayName(displayName);
|
||||
|
||||
APP.store.dispatch(participantUpdated({
|
||||
conference: room,
|
||||
|
@ -2633,8 +2633,7 @@ export default {
|
|||
* @param nickname {string} the new display name
|
||||
*/
|
||||
changeLocalDisplayName(nickname = '') {
|
||||
const formattedNickname
|
||||
= nickname.trim().substr(0, MAX_DISPLAY_NAME_LENGTH);
|
||||
const formattedNickname = getNormalizedDisplayName(nickname);
|
||||
const { id, name } = getLocalParticipant(APP.store.getState());
|
||||
|
||||
if (formattedNickname === name) {
|
||||
|
|
|
@ -10,8 +10,8 @@ import { getName } from '../../app';
|
|||
import { JitsiConferenceEvents } from '../lib-jitsi-meet';
|
||||
import { setAudioMuted, setVideoMuted } from '../media';
|
||||
import {
|
||||
MAX_DISPLAY_NAME_LENGTH,
|
||||
dominantSpeakerChanged,
|
||||
getNormalizedDisplayName,
|
||||
participantConnectionStatusChanged,
|
||||
participantPresenceChanged,
|
||||
participantRoleChanged,
|
||||
|
@ -131,7 +131,7 @@ function _addConferenceListeners(conference, dispatch) {
|
|||
(id, displayName) => dispatch(participantUpdated({
|
||||
conference,
|
||||
id,
|
||||
name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)
|
||||
name: getNormalizedDisplayName(displayName)
|
||||
})));
|
||||
|
||||
conference.on(
|
||||
|
|
|
@ -17,8 +17,7 @@ import {
|
|||
PARTICIPANT_UPDATED,
|
||||
PIN_PARTICIPANT
|
||||
} from './actionTypes';
|
||||
import { MAX_DISPLAY_NAME_LENGTH } from './constants';
|
||||
import { getLocalParticipant } from './functions';
|
||||
import { getLocalParticipant, getNormalizedDisplayName } from './functions';
|
||||
|
||||
/**
|
||||
* Create an action for when dominant speaker changes.
|
||||
|
@ -369,13 +368,17 @@ export function participantRoleChanged(id, role) {
|
|||
* }}
|
||||
*/
|
||||
export function participantUpdated(participant = {}) {
|
||||
const participantToUpdate = {
|
||||
...participant
|
||||
};
|
||||
|
||||
if (participant.name) {
|
||||
participant.name = participant.name.substr(0, MAX_DISPLAY_NAME_LENGTH);
|
||||
participantToUpdate.name = getNormalizedDisplayName(participant.name);
|
||||
}
|
||||
|
||||
return {
|
||||
type: PARTICIPANT_UPDATED,
|
||||
participant
|
||||
participant: participantToUpdate
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { toState } from '../redux';
|
|||
import {
|
||||
DEFAULT_AVATAR_RELATIVE_PATH,
|
||||
LOCAL_PARTICIPANT_DEFAULT_ID,
|
||||
MAX_DISPLAY_NAME_LENGTH,
|
||||
PARTICIPANT_ROLE
|
||||
} from './constants';
|
||||
|
||||
|
@ -94,6 +95,21 @@ export function getLocalParticipant(stateful: Object | Function) {
|
|||
return participants.find(p => p.local);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a display name so then no invalid values (padding, length...etc)
|
||||
* can be set.
|
||||
*
|
||||
* @param {string} name - The display name to set.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getNormalizedDisplayName(name: string) {
|
||||
if (!name || !name.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return name.trim().substring(0, MAX_DISPLAY_NAME_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participant by ID from Redux state.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue