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