diff --git a/plugins/activity-resources/src/references.ts b/plugins/activity-resources/src/references.ts index da36affd42..2eadd90bb3 100644 --- a/plugins/activity-resources/src/references.ts +++ b/plugins/activity-resources/src/references.ts @@ -1,5 +1,4 @@ import core, { - type Class, type Data, type Doc, type DocumentQuery, @@ -76,94 +75,3 @@ export async function updateReferences ( await updateReferencesList(client, query, references, space) } - -function extractReferences ( - srcDocId: Ref, - srcDocClass: Ref>, - attachedDocId: Ref | undefined, - attachedDocClass: Ref> | undefined, - kids: NodeListOf -): Array> { - const result: Array> = [] - - const nodes: Array> = [kids] - while (true) { - const nds = nodes.shift() - if (nds === undefined) { - break - } - nds.forEach((kid) => { - if ( - kid.nodeType === Node.ELEMENT_NODE && - (kid as HTMLElement).localName === 'span' && - (kid as HTMLElement).getAttribute('data-type') === 'reference' - ) { - const el = kid as HTMLElement - const ato = el.getAttribute('data-id') as Ref - const atoClass = el.getAttribute('data-objectclass') as Ref> - const e = result.find((e) => e.attachedTo === ato && e.attachedToClass === atoClass) - if (e === undefined && ato !== attachedDocId && ato !== srcDocId) { - result.push({ - attachedTo: ato, - attachedToClass: atoClass, - collection: 'references', - srcDocId, - srcDocClass, - message: el.parentElement?.innerHTML ?? '', - attachedDocId, - attachedDocClass - }) - } - } - nodes.push(kid.childNodes) - }) - } - return result -} - -/** - * @public - */ -export function getReferences ( - srcDocId: Ref, - srcDocClass: Ref>, - attachedDocId: Ref | undefined, - attachedDocClass: Ref> | undefined, - content: string -): Array> { - const parser = new DOMParser() - const doc = parser.parseFromString(content, 'text/html') - - return extractReferences( - srcDocId, - srcDocClass, - attachedDocId, - attachedDocClass, - doc.childNodes as NodeListOf - ) -} - -/** - * @public - */ -export async function createReferences ( - client: TxOperations, - srcDocId: Ref, - srcDocClass: Ref>, - attachedDocId: Ref | undefined, - attachedDocClass: Ref> | undefined, - content: string, - space: Ref -): Promise { - const hierarchy = client.getHierarchy() - - const references = getReferences(srcDocId, srcDocClass, attachedDocId, attachedDocClass, content) - for (const ref of references) { - if (hierarchy.isDerived(ref.attachedToClass, contact.class.Person)) { - continue - } - - const { attachedTo, attachedToClass, collection, ...adata } = ref - await client.addCollection(activity.class.ActivityReference, space, attachedTo, attachedToClass, collection, adata) - } -}