mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 21:27:46 +02:00
refactor attachments
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
+312
-302
File diff suppressed because it is too large
Load Diff
+312
-302
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user