Skip to content

Commit

Permalink
Remove wrong unused code (#5996)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
  • Loading branch information
kristina-fefelova authored Jul 3, 2024
1 parent b836039 commit fad6383
Showing 1 changed file with 0 additions and 92 deletions.
92 changes: 0 additions & 92 deletions plugins/activity-resources/src/references.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import core, {
type Class,
type Data,
type Doc,
type DocumentQuery,
Expand Down Expand Up @@ -76,94 +75,3 @@ export async function updateReferences (

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)
}
}

0 comments on commit fad6383

Please sign in to comment.