Fix activity messages generation and display (#4469)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-01-29 18:54:21 +07:00
committed by GitHub
parent b78c4138a4
commit f94089b7dd
7 changed files with 75 additions and 50 deletions
@@ -186,7 +186,7 @@ async function pushDocUpdateMessages (
)
}
if (attributesUpdates.length === 0) {
if (attributesUpdates.length === 0 && rawMessage.action !== 'update') {
res.push(getDocUpdateMessageTx(control, originTx, object, rawMessage, modifiedBy))
}
@@ -254,14 +254,12 @@ export async function generateDocUpdateMessages (
case core.class.TxCollectionCUD: {
const actualTx = TxProcessor.extractTx(tx) as TxCUD<Doc>
res = await generateDocUpdateMessages(actualTx, control, res, tx, objectCache)
if ([core.class.TxCreateDoc, core.class.TxRemoveDoc].includes(actualTx._class)) {
if ([core.class.TxCreateDoc, core.class.TxRemoveDoc, core.class.TxUpdateDoc].includes(actualTx._class)) {
let doc = objectCache?.docs?.get(tx.objectId)
if (doc === undefined) {
doc = (await control.findAll(tx.objectClass, { _id: tx.objectId }, { limit: 1 }))[0]
}
if (doc !== undefined) {
return await pushDocUpdateMessages(control, res, doc ?? undefined, originTx ?? tx, undefined, objectCache)
}
return await pushDocUpdateMessages(control, res, doc ?? undefined, originTx ?? tx, undefined, objectCache)
}
return res
}
+29 -3
View File
@@ -189,6 +189,17 @@ export async function getTxAttributesUpdates (
return []
}
let updateObject = object
if (updateObject._id !== tx.objectId) {
updateObject =
objectCache?.docs?.get(tx.objectId) ?? (await control.findAll(tx.objectClass, { _id: tx.objectId }))[0]
}
if (updateObject === undefined) {
return []
}
const hierarchy = control.hierarchy
const keys = getAvailableAttributesKeys(tx, hierarchy)
@@ -201,7 +212,14 @@ export async function getTxAttributesUpdates (
const isMixin = hierarchy.isDerived(tx._class, core.class.TxMixin)
const mixin = isMixin ? (tx as TxMixin<Doc, Doc>).mixin : undefined
const { doc, prevDoc } = await getDocDiff(control, object._class, object._id, originTx._id, mixin, objectCache)
const { doc, prevDoc } = await getDocDiff(
control,
updateObject._class,
updateObject._id,
originTx._id,
mixin,
objectCache
)
for (const key of keys) {
let attrValue = modifiedAttributes[key]
@@ -212,7 +230,7 @@ export async function getTxAttributesUpdates (
let attrClass: Ref<Class<Doc>> | undefined = mixin
const clazz = hierarchy.findAttribute(object._class, key)
const clazz = hierarchy.findAttribute(updateObject._class, key)
if (clazz !== undefined && 'to' in clazz.type) {
attrClass = clazz.type.to as Ref<Class<Doc>>
@@ -247,10 +265,18 @@ export async function getTxAttributesUpdates (
}
}
let setAttr = []
if (Array.isArray(attrValue)) {
setAttr = attrValue
} else if (key in modifiedAttributes) {
setAttr = [attrValue]
}
result.push({
attrKey: key,
attrClass,
set: Array.isArray(attrValue) ? attrValue : [attrValue],
set: setAttr,
added,
removed,
prevValue,