@atlaskit/editor-plugin-collab-edit
Version:
Collab Edit plugin for @atlaskit/editor-core
31 lines • 2.04 kB
JavaScript
import { pluginKey } from './plugin-key';
const isAgentRemoteStep = step => typeof step === 'object' && step !== null && typeof step.agentType === 'string';
const asString = value => typeof value === 'string' ? value : undefined;
export const 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;
};
export const getAgentEditRequester = (json, view) => {
var _collabPluginState$ac, _collabPluginState$ac2;
const agentStep = json.find(isAgentRemoteStep);
if (!agentStep) {
return null;
}
const actorUserId = asString(agentStep.userId);
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: asString(agentStep.agentId),
agentName: asString(agentStep.agentName),
agentNamedId: asString(agentStep.agentNamedId),
agentSourceId: asString(agentStep.agentSourceId),
agentType: agentStep.agentType,
actorUserId,
invocationId: asString(agentStep.invocationId),
isThirdPartyAgent: typeof agentStep.isThirdPartyAgent === 'boolean' ? agentStep.isThirdPartyAgent : undefined,
isLocalUserRequester: actorUserId !== undefined && localUserId !== undefined && actorUserId === localUserId
};
};