mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-15 12:55:59 +00:00
Remove wrong unused code (#5996)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
b836039903
commit
fad6383426
@ -1,5 +1,4 @@
|
|||||||
import core, {
|
import core, {
|
||||||
type Class,
|
|
||||||
type Data,
|
type Data,
|
||||||
type Doc,
|
type Doc,
|
||||||
type DocumentQuery,
|
type DocumentQuery,
|
||||||
@ -76,94 +75,3 @@ export async function updateReferences (
|
|||||||
|
|
||||||
await updateReferencesList(client, query, references, space)
|
await updateReferencesList(client, query, references, space)
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractReferences (
|
|
||||||
srcDocId: Ref<Doc>,
|
|
||||||
srcDocClass: Ref<Class<Doc>>,
|
|
||||||
attachedDocId: Ref<Doc> | undefined,
|
|
||||||
attachedDocClass: Ref<Class<Doc>> | undefined,
|
|
||||||
kids: NodeListOf<ChildNode>
|
|
||||||
): Array<Data<ActivityReference>> {
|
|
||||||
const result: Array<Data<ActivityReference>> = []
|
|
||||||
|
|
||||||
const nodes: Array<NodeListOf<ChildNode>> = [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<Doc>
|
|
||||||
const atoClass = el.getAttribute('data-objectclass') as Ref<Class<Doc>>
|
|
||||||
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<Doc>,
|
|
||||||
srcDocClass: Ref<Class<Doc>>,
|
|
||||||
attachedDocId: Ref<Doc> | undefined,
|
|
||||||
attachedDocClass: Ref<Class<Doc>> | undefined,
|
|
||||||
content: string
|
|
||||||
): Array<Data<ActivityReference>> {
|
|
||||||
const parser = new DOMParser()
|
|
||||||
const doc = parser.parseFromString(content, 'text/html')
|
|
||||||
|
|
||||||
return extractReferences(
|
|
||||||
srcDocId,
|
|
||||||
srcDocClass,
|
|
||||||
attachedDocId,
|
|
||||||
attachedDocClass,
|
|
||||||
doc.childNodes as NodeListOf<HTMLElement>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export async function createReferences (
|
|
||||||
client: TxOperations,
|
|
||||||
srcDocId: Ref<Doc>,
|
|
||||||
srcDocClass: Ref<Class<Doc>>,
|
|
||||||
attachedDocId: Ref<Doc> | undefined,
|
|
||||||
attachedDocClass: Ref<Class<Doc>> | undefined,
|
|
||||||
content: string,
|
|
||||||
space: Ref<Space>
|
|
||||||
): Promise<void> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user