UBERF-4692: remove activity messages on doc remove (#4227)

This commit is contained in:
Kristina 2023-12-20 19:05:52 +04:00 committed by GitHub
parent 58854ee3b0
commit f0dbfe3971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -35,4 +35,8 @@ export function createModel (builder: Builder): void {
builder.createDoc(serverCore.class.Trigger, core.space.Model, { builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverActivity.trigger.ActivityMessagesHandler trigger: serverActivity.trigger.ActivityMessagesHandler
}) })
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverActivity.trigger.OnDocRemoved
})
} }

View File

@ -263,10 +263,33 @@ async function ActivityMessagesHandler (tx: TxCUD<Doc>, control: TriggerControl)
return await generateDocUpdateMessages(tx, control) 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 // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({ export default async () => ({
trigger: { trigger: {
// OnReactionChanged, // OnReactionChanged,
ActivityMessagesHandler ActivityMessagesHandler,
OnDocRemoved
} }
}) })

View File

@ -29,6 +29,7 @@ export const serverActivityId = 'server-activity' as Plugin
*/ */
export default plugin(serverActivityId, { export default plugin(serverActivityId, {
trigger: { trigger: {
ActivityMessagesHandler: '' as Resource<TriggerFunc> ActivityMessagesHandler: '' as Resource<TriggerFunc>,
OnDocRemoved: '' as Resource<TriggerFunc>
} }
}) })