UNPKG

@atlaskit/editor-plugin-avatar-group

Version:

Avatar Group plugin for @atlaskit/editor-core.

58 lines 2.86 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import React from 'react'; import memoizeOne from 'memoize-one'; import { avatarGroupMessages } from '@atlaskit/editor-common/messages'; import { fg } from '@atlaskit/platform-feature-flags'; import { ColoredAvatarItem } from './colored-avatar-item'; var getUserNameForAttribution = function getUserNameForAttribution(participant, participants) { var _participants$find; var userNamesById = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var actingUserId = participant.actingUserId; if (!fg('platform_move_presence_agents') || !actingUserId) { return undefined; } var currentParticipantName = (_participants$find = participants.find(function (user) { return user.sessionId !== participant.sessionId && user.userId === actingUserId && user.isHydrated; })) === null || _participants$find === void 0 ? void 0 : _participants$find.name; return currentParticipantName !== null && currentParticipantName !== void 0 ? currentParticipantName : userNamesById[actingUserId]; }; var getAvatarName = function getAvatarName(participant, participants, formatMessage, userNamesById) { var participantName = participant.name || formatMessage(avatarGroupMessages.anonymousCollaborator); var userNameForAttribution = getUserNameForAttribution(participant, participants, userNamesById); if (!userNameForAttribution) { return participantName; } return formatMessage(avatarGroupMessages.agentWithUser, { agentName: participantName, userName: userNameForAttribution }); }; var toAvatar = function toAvatar(participant, api, formatMessage, participants) { var userNamesById = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; return { name: getAvatarName(participant, participants, formatMessage, userNamesById), src: participant.avatar, size: 'medium', presence: /*#__PURE__*/React.createElement(ColoredAvatarItem, { api: api, name: participant.name, sessionId: participant.sessionId, presenceId: participant.presenceId }) }; }; var _default_1 = memoizeOne(toAvatar, function participantEquals(_ref, _ref2) { var _ref3 = _slicedToArray(_ref, 5), a = _ref3[0], aParticipants = _ref3[3], _ref3$ = _ref3[4], aUserNamesById = _ref3$ === void 0 ? {} : _ref3$; var _ref4 = _slicedToArray(_ref2, 5), b = _ref4[0], bParticipants = _ref4[3], _ref4$ = _ref4[4], bUserNamesById = _ref4$ === void 0 ? {} : _ref4$; var actingUserId = a.actingUserId; return a.name === b.name && a.avatar === b.avatar && a.sessionId === b.sessionId && actingUserId === b.actingUserId && (!actingUserId || getUserNameForAttribution(a, aParticipants, aUserNamesById) === getUserNameForAttribution(b, bParticipants, bUserNamesById)); }); export default _default_1;