UNPKG

@atlaskit/editor-plugin-collab-edit

Version:

Collab Edit plugin for @atlaskit/editor-core

29 lines (28 loc) 1.66 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getAgentEditRequester = void 0; var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); var _pluginKey = require("./plugin-key"); var isAgentRemoteStep = function isAgentRemoteStep(step) { return (0, _typeof2.default)(step) === 'object' && step !== null && typeof step.agentType === 'string'; }; var getAgentEditRequester = exports.getAgentEditRequester = function getAgentEditRequester(json, view) { var _collabPluginState$ac; var agentStep = json.find(isAgentRemoteStep); if (!agentStep) { return null; } var actorUserId = typeof agentStep.userId === 'string' ? agentStep.userId : undefined; var collabPluginState = _pluginKey.pluginKey.getState(view.state); var localSessionId = collabPluginState === null || collabPluginState === void 0 ? void 0 : collabPluginState.sessionId; var localUserId = localSessionId ? collabPluginState === null || collabPluginState === void 0 || (_collabPluginState$ac = collabPluginState.activeParticipants) === null || _collabPluginState$ac === void 0 || (_collabPluginState$ac = _collabPluginState$ac.get(localSessionId)) === null || _collabPluginState$ac === void 0 ? void 0 : _collabPluginState$ac.userId : undefined; return { agentId: typeof agentStep.agentId === 'string' ? agentStep.agentId : undefined, agentType: agentStep.agentType, actorUserId: actorUserId, isLocalUserRequester: actorUserId !== undefined && localUserId !== undefined && actorUserId === localUserId }; };