refactor attachments

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov
2021-10-23 16:03:37 +02:00
parent 7cdaaf9224
commit b3e88daf3c
15 changed files with 1022 additions and 942 deletions
+26 -3
View File
@@ -14,8 +14,9 @@
// limitations under the License.
//
import type { Tx, TxCreateDoc, Data, Ref, Doc, TxFactory } from '@anticrm/core'
import type { Message, Backlink } from '@anticrm/chunter'
import type { Tx, TxCreateDoc, Data, Ref, Doc, TxFactory, Class } from '@anticrm/core'
import type { FindAll } from '@anticrm/server-core'
import type { Message, Backlink, Attachment } from '@anticrm/chunter'
import core from '@anticrm/core'
import chunter from '@anticrm/chunter'
@@ -26,6 +27,7 @@ function extractBacklinks (backlinkId: Ref<Doc>, message: string, kids: NodeList
if (kid.nodeName === 'span') {
result.push({
attachedTo: kid.getAttribute('data-id') as Ref<Doc>,
attachedToClass: kid.getAttribute('data-class') as Ref<Class<Doc>>,
backlinkId,
backlinkClass: chunter.class.Message,
message
@@ -57,9 +59,30 @@ export async function OnMessage (tx: Tx, txFactory: TxFactory): Promise<Tx[]> {
return []
}
interface WithAttachements extends Doc {
attachments: number
}
/**
* @public
*/
export async function OnAttachment (tx: Tx, txFactory: TxFactory, findAll: FindAll<Doc>): Promise<Tx[]> {
if (tx._class === core.class.TxCreateDoc) {
const createTx = tx as TxCreateDoc<Attachment>
if (createTx.objectClass === chunter.class.Attachment) {
const _id = createTx.attributes.attachedTo as Ref<WithAttachements>
const _class = createTx.attributes.attachedToClass as Ref<Class<WithAttachements>>
const attachedTo = (await findAll(_class, { _id }))[0]
return [txFactory.createTxUpdateDoc(_class, attachedTo.space, _id, { $inc: { attachments: 1 } })]
}
}
return []
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({
trigger: {
OnMessage
OnMessage,
OnAttachment
}
})
File diff suppressed because it is too large Load Diff
+312 -302
View File
File diff suppressed because it is too large Load Diff