mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 21:50:34 +03:00
UBERF-4692: remove activity messages on doc remove (#4227)
This commit is contained in:
parent
58854ee3b0
commit
f0dbfe3971
@ -35,4 +35,8 @@ export function createModel (builder: Builder): void {
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverActivity.trigger.ActivityMessagesHandler
|
||||
})
|
||||
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverActivity.trigger.OnDocRemoved
|
||||
})
|
||||
}
|
||||
|
@ -263,10 +263,33 @@ async function ActivityMessagesHandler (tx: TxCUD<Doc>, control: TriggerControl)
|
||||
return await generateDocUpdateMessages(tx, control)
|
||||
}
|
||||
|
||||
async function OnDocRemoved (originTx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
|
||||
const tx = TxProcessor.extractTx(originTx) as TxCUD<Doc>
|
||||
|
||||
if (tx._class !== core.class.TxRemoveDoc) {
|
||||
return []
|
||||
}
|
||||
|
||||
const activityDocMixin = control.hierarchy.classHierarchyMixin(tx.objectClass, activity.mixin.ActivityDoc)
|
||||
|
||||
if (activityDocMixin === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
const messages = await control.findAll(
|
||||
activity.class.ActivityMessage,
|
||||
{ attachedTo: tx.objectId },
|
||||
{ projection: { _id: 1, _class: 1, space: 1 } }
|
||||
)
|
||||
|
||||
return messages.map((message) => control.txFactory.createTxRemoveDoc(message._class, message.space, message._id))
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export default async () => ({
|
||||
trigger: {
|
||||
// OnReactionChanged,
|
||||
ActivityMessagesHandler
|
||||
ActivityMessagesHandler,
|
||||
OnDocRemoved
|
||||
}
|
||||
})
|
||||
|
@ -29,6 +29,7 @@ export const serverActivityId = 'server-activity' as Plugin
|
||||
*/
|
||||
export default plugin(serverActivityId, {
|
||||
trigger: {
|
||||
ActivityMessagesHandler: '' as Resource<TriggerFunc>
|
||||
ActivityMessagesHandler: '' as Resource<TriggerFunc>,
|
||||
OnDocRemoved: '' as Resource<TriggerFunc>
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user