UNPKG

@atlaskit/editor-plugin-collab-edit

Version:

Collab Edit plugin for @atlaskit/editor-core

19 lines 1.29 kB
import { pluginKey } from './plugin-key'; const isAgentRemoteStep = step => typeof step === 'object' && step !== null && typeof step.agentType === 'string'; export const getAgentEditRequester = (json, view) => { var _collabPluginState$ac, _collabPluginState$ac2; const agentStep = json.find(isAgentRemoteStep); if (!agentStep) { return null; } const actorUserId = typeof agentStep.userId === 'string' ? agentStep.userId : undefined; const collabPluginState = pluginKey.getState(view.state); const localSessionId = collabPluginState === null || collabPluginState === void 0 ? void 0 : collabPluginState.sessionId; const localUserId = localSessionId ? collabPluginState === null || collabPluginState === void 0 ? void 0 : (_collabPluginState$ac = collabPluginState.activeParticipants) === null || _collabPluginState$ac === void 0 ? void 0 : (_collabPluginState$ac2 = _collabPluginState$ac.get(localSessionId)) === null || _collabPluginState$ac2 === void 0 ? void 0 : _collabPluginState$ac2.userId : undefined; return { agentId: typeof agentStep.agentId === 'string' ? agentStep.agentId : undefined, agentType: agentStep.agentType, actorUserId, isLocalUserRequester: actorUserId !== undefined && localUserId !== undefined && actorUserId === localUserId }; };