mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-05 10:29:51 +03:00
Fix extra notify marker in chat (#6500)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
55b51b0fd0
commit
cabc77acb1
@ -150,6 +150,7 @@ export async function getCommonNotificationTxes (
|
|||||||
control,
|
control,
|
||||||
res,
|
res,
|
||||||
receiver,
|
receiver,
|
||||||
|
sender,
|
||||||
attachedTo,
|
attachedTo,
|
||||||
attachedToClass,
|
attachedToClass,
|
||||||
space,
|
space,
|
||||||
@ -333,6 +334,7 @@ export async function pushInboxNotifications (
|
|||||||
control: TriggerControl,
|
control: TriggerControl,
|
||||||
res: Tx[],
|
res: Tx[],
|
||||||
receiver: ReceiverInfo,
|
receiver: ReceiverInfo,
|
||||||
|
sender: SenderInfo,
|
||||||
objectId: Ref<Doc>,
|
objectId: Ref<Doc>,
|
||||||
objectClass: Ref<Class<Doc>>,
|
objectClass: Ref<Class<Doc>>,
|
||||||
objectSpace: Ref<Space>,
|
objectSpace: Ref<Space>,
|
||||||
@ -354,6 +356,7 @@ export async function pushInboxNotifications (
|
|||||||
objectClass,
|
objectClass,
|
||||||
objectSpace,
|
objectSpace,
|
||||||
receiver,
|
receiver,
|
||||||
|
sender._id,
|
||||||
shouldUpdateTimestamp ? modifiedOn : undefined,
|
shouldUpdateTimestamp ? modifiedOn : undefined,
|
||||||
tx
|
tx
|
||||||
)
|
)
|
||||||
@ -614,6 +617,7 @@ export async function pushActivityInboxNotifications (
|
|||||||
control,
|
control,
|
||||||
res,
|
res,
|
||||||
receiver,
|
receiver,
|
||||||
|
sender,
|
||||||
activityMessage.attachedTo,
|
activityMessage.attachedTo,
|
||||||
activityMessage.attachedToClass,
|
activityMessage.attachedToClass,
|
||||||
object.space,
|
object.space,
|
||||||
@ -679,6 +683,7 @@ async function createNotifyContext (
|
|||||||
objectClass: Ref<Class<Doc>>,
|
objectClass: Ref<Class<Doc>>,
|
||||||
objectSpace: Ref<Space>,
|
objectSpace: Ref<Space>,
|
||||||
receiver: ReceiverInfo,
|
receiver: ReceiverInfo,
|
||||||
|
sender: Ref<Account>,
|
||||||
updateTimestamp?: Timestamp,
|
updateTimestamp?: Timestamp,
|
||||||
tx?: TxCUD<Doc>
|
tx?: TxCUD<Doc>
|
||||||
): Promise<Ref<DocNotifyContext>> {
|
): Promise<Ref<DocNotifyContext>> {
|
||||||
@ -689,7 +694,8 @@ async function createNotifyContext (
|
|||||||
objectSpace,
|
objectSpace,
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
tx: tx?._id,
|
tx: tx?._id,
|
||||||
lastUpdateTimestamp: updateTimestamp
|
lastUpdateTimestamp: updateTimestamp,
|
||||||
|
lastViewedTimestamp: sender === receiver._id ? updateTimestamp : undefined
|
||||||
})
|
})
|
||||||
await ctx.with('apply', {}, () => control.apply(control.ctx, [createTx]))
|
await ctx.with('apply', {}, () => control.apply(control.ctx, [createTx]))
|
||||||
if (receiver.account?.email !== undefined) {
|
if (receiver.account?.email !== undefined) {
|
||||||
@ -776,6 +782,7 @@ export async function getNotificationTxes (
|
|||||||
message.attachedToClass,
|
message.attachedToClass,
|
||||||
object.space,
|
object.space,
|
||||||
receiver,
|
receiver,
|
||||||
|
sender._id,
|
||||||
params.shouldUpdateTimestamp ? originTx.modifiedOn : undefined,
|
params.shouldUpdateTimestamp ? originTx.modifiedOn : undefined,
|
||||||
tx
|
tx
|
||||||
)
|
)
|
||||||
@ -1646,7 +1653,7 @@ async function updateCollaborators (
|
|||||||
if (info === undefined) continue
|
if (info === undefined) continue
|
||||||
const context = getDocNotifyContext(control, contexts, objectId, info._id)
|
const context = getDocNotifyContext(control, contexts, objectId, info._id)
|
||||||
if (context !== undefined) continue
|
if (context !== undefined) continue
|
||||||
await createNotifyContext(ctx, control, objectId, objectClass, objectSpace, info, undefined, tx)
|
await createNotifyContext(ctx, control, objectId, objectClass, objectSpace, info, tx.modifiedBy, undefined, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
await removeContexts(ctx, contexts, removedCollaborators as Ref<PersonAccount>[], control)
|
await removeContexts(ctx, contexts, removedCollaborators as Ref<PersonAccount>[], control)
|
||||||
@ -1795,17 +1802,11 @@ async function OnActivityMessageRemove (message: ActivityMessage, control: Trigg
|
|||||||
}
|
}
|
||||||
|
|
||||||
const contexts = await control.findAll(control.ctx, notification.class.DocNotifyContext, {
|
const contexts = await control.findAll(control.ctx, notification.class.DocNotifyContext, {
|
||||||
objectId: message.attachedTo
|
objectId: message.attachedTo,
|
||||||
|
lastUpdateTimestamp: message.createdOn
|
||||||
})
|
})
|
||||||
if (contexts.length === 0) return []
|
if (contexts.length === 0) return []
|
||||||
|
|
||||||
const isLastUpdate = contexts.some((context) => {
|
|
||||||
const { lastUpdateTimestamp = 0, lastViewedTimestamp = 0 } = context
|
|
||||||
return lastUpdateTimestamp === message.createdOn && lastViewedTimestamp < lastUpdateTimestamp
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!isLastUpdate) return []
|
|
||||||
|
|
||||||
const lastMessage = (
|
const lastMessage = (
|
||||||
await control.findAll(
|
await control.findAll(
|
||||||
control.ctx,
|
control.ctx,
|
||||||
@ -1819,13 +1820,11 @@ async function OnActivityMessageRemove (message: ActivityMessage, control: Trigg
|
|||||||
const res: Tx[] = []
|
const res: Tx[] = []
|
||||||
|
|
||||||
for (const context of contexts) {
|
for (const context of contexts) {
|
||||||
if (context.lastUpdateTimestamp === message.createdOn) {
|
const tx = control.txFactory.createTxUpdateDoc(context._class, context.space, context._id, {
|
||||||
const tx = control.txFactory.createTxUpdateDoc(context._class, context.space, context._id, {
|
lastUpdateTimestamp: lastMessage.createdOn ?? lastMessage.modifiedOn
|
||||||
lastUpdateTimestamp: lastMessage.createdOn ?? lastMessage.modifiedOn
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.push(tx)
|
res.push(tx)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user