UNPKG

@azure/communication-react

Version:

React library for building modern communication user experiences utilizing Azure Communication Services

44 lines 1.96 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { getUserId, getDisplayName, getParticipants } from './baseSelectors'; import * as reselect from 'reselect'; import { toFlatCommunicationIdentifier } from "../../acs-ui-common/src"; import { getIdentifierKind } from '@azure/communication-common'; const convertChatParticipantsToCommunicationParticipants = (chatParticipants) => { return chatParticipants.map((participant) => { return { userId: toFlatCommunicationIdentifier(participant.id), displayName: participant.displayName, // ACS users can not remove Teams users. // Removing phone numbers or unknown types of users is undefined. isRemovable: getIdentifierKind(participant.id).kind === 'communicationUser' }; }); }; /** * get the moderator to help updating its display name if they are the local user or removing them from list of participants otherwise */ const getModerator = (participants) => { return participants.find(p => p.displayName === undefined); }; /** * Selector for {@link ParticipantList} component. * * @public */ export const chatParticipantListSelector = reselect.createSelector([getUserId, getParticipants, getDisplayName], (userId, chatParticipants, displayName) => { let participants = convertChatParticipantsToCommunicationParticipants(Object.values(chatParticipants)); // Update the moderator display name if they are the local user, otherwise remove them from list of participants const moderator = getModerator(participants); if ((moderator === null || moderator === void 0 ? void 0 : moderator.userId) === userId) { moderator.displayName = displayName; } else { participants = participants.filter(p => p.displayName); } return { myUserId: userId, participants: participants }; }); //# sourceMappingURL=chatParticipantListSelector.js.map