@atlaskit/editor-plugin-collab-edit
Version:
Collab Edit plugin for @atlaskit/editor-core
43 lines (42 loc) • 2.51 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isStepFromAgentEdit = 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 asString = function asString(value) {
return typeof value === 'string' ? value : undefined;
};
var isStepFromAgentEdit = exports.isStepFromAgentEdit = function isStepFromAgentEdit(step, requester) {
if (!isAgentRemoteStep(step)) {
return false;
}
return step.agentType === requester.agentType && asString(step.agentId) === requester.agentId && asString(step.agentSourceId) === requester.agentSourceId && asString(step.agentNamedId) === requester.agentNamedId && asString(step.userId) === requester.actorUserId && asString(step.invocationId) === requester.invocationId;
};
var getAgentEditRequester = exports.getAgentEditRequester = function getAgentEditRequester(json, view) {
var _collabPluginState$ac;
var agentStep = json.find(isAgentRemoteStep);
if (!agentStep) {
return null;
}
var actorUserId = asString(agentStep.userId);
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: asString(agentStep.agentId),
agentName: asString(agentStep.agentName),
agentNamedId: asString(agentStep.agentNamedId),
agentSourceId: asString(agentStep.agentSourceId),
agentType: agentStep.agentType,
actorUserId: actorUserId,
invocationId: asString(agentStep.invocationId),
isThirdPartyAgent: typeof agentStep.isThirdPartyAgent === 'boolean' ? agentStep.isThirdPartyAgent : undefined,
isLocalUserRequester: actorUserId !== undefined && localUserId !== undefined && actorUserId === localUserId
};
};