mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
Fix duplicates of inbox notifications and notify contexts (#4383)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
96bd320f59
commit
c6d6b48318
@ -209,8 +209,9 @@ export function sortActivityMessages<T extends ActivityMessage> (messages: T[],
|
|||||||
function canCombineMessage (message: ActivityMessage): boolean {
|
function canCombineMessage (message: ActivityMessage): boolean {
|
||||||
const hasReactions = message.reactions !== undefined && message.reactions > 0
|
const hasReactions = message.reactions !== undefined && message.reactions > 0
|
||||||
const isPinned = message.isPinned === true
|
const isPinned = message.isPinned === true
|
||||||
|
const hasReplies = message.replies !== undefined && message.replies > 0
|
||||||
|
|
||||||
return !hasReactions && !isPinned
|
return !hasReactions && !isPinned && !hasReplies
|
||||||
}
|
}
|
||||||
|
|
||||||
function groupByTime<T extends ActivityMessage> (messages: T[]): T[][] {
|
function groupByTime<T extends ActivityMessage> (messages: T[]): T[][] {
|
||||||
|
@ -31,6 +31,7 @@ import core, {
|
|||||||
MixinUpdate,
|
MixinUpdate,
|
||||||
Ref,
|
Ref,
|
||||||
RefTo,
|
RefTo,
|
||||||
|
Space,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
Tx,
|
Tx,
|
||||||
TxCollectionCUD,
|
TxCollectionCUD,
|
||||||
@ -389,7 +390,9 @@ export async function pushInboxNotifications (
|
|||||||
control: TriggerControl,
|
control: TriggerControl,
|
||||||
res: Tx[],
|
res: Tx[],
|
||||||
targetUser: Ref<Account>,
|
targetUser: Ref<Account>,
|
||||||
object: Doc,
|
attachedTo: Ref<Doc>,
|
||||||
|
attachedToClass: Ref<Class<Doc>>,
|
||||||
|
space: Ref<Space>,
|
||||||
docNotifyContexts: DocNotifyContext[],
|
docNotifyContexts: DocNotifyContext[],
|
||||||
data: Partial<Data<InboxNotification>>,
|
data: Partial<Data<InboxNotification>>,
|
||||||
_class: Ref<Class<InboxNotification>>,
|
_class: Ref<Class<InboxNotification>>,
|
||||||
@ -404,10 +407,10 @@ export async function pushInboxNotifications (
|
|||||||
let docNotifyContextId: Ref<DocNotifyContext>
|
let docNotifyContextId: Ref<DocNotifyContext>
|
||||||
|
|
||||||
if (docNotifyContext === undefined) {
|
if (docNotifyContext === undefined) {
|
||||||
const createContextTx = control.txFactory.createTxCreateDoc(notification.class.DocNotifyContext, object.space, {
|
const createContextTx = control.txFactory.createTxCreateDoc(notification.class.DocNotifyContext, space, {
|
||||||
user: targetUser,
|
user: targetUser,
|
||||||
attachedTo: object._id,
|
attachedTo,
|
||||||
attachedToClass: object._class,
|
attachedToClass,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
lastUpdateTimestamp: shouldUpdateTimestamp ? modifiedOn : undefined
|
lastUpdateTimestamp: shouldUpdateTimestamp ? modifiedOn : undefined
|
||||||
})
|
})
|
||||||
@ -426,7 +429,7 @@ export async function pushInboxNotifications (
|
|||||||
|
|
||||||
if (!isHidden) {
|
if (!isHidden) {
|
||||||
res.push(
|
res.push(
|
||||||
control.txFactory.createTxCreateDoc(_class, object.space, {
|
control.txFactory.createTxCreateDoc(_class, space, {
|
||||||
user: targetUser,
|
user: targetUser,
|
||||||
isViewed: false,
|
isViewed: false,
|
||||||
docNotifyContext: docNotifyContextId,
|
docNotifyContext: docNotifyContextId,
|
||||||
@ -469,7 +472,9 @@ export async function pushActivityInboxNotifications (
|
|||||||
control,
|
control,
|
||||||
res,
|
res,
|
||||||
targetUser,
|
targetUser,
|
||||||
object,
|
activityMessage.attachedTo,
|
||||||
|
activityMessage.attachedToClass,
|
||||||
|
activityMessage.space,
|
||||||
docNotifyContexts,
|
docNotifyContexts,
|
||||||
data,
|
data,
|
||||||
notification.class.ActivityInboxNotification,
|
notification.class.ActivityInboxNotification,
|
||||||
@ -547,7 +552,9 @@ export async function createCollabDocInfo (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const targets = new Set(collaborators)
|
const targets = new Set(collaborators)
|
||||||
const notifyContexts = await control.findAll(notification.class.DocNotifyContext, { attachedTo: object._id })
|
const notifyContexts = await control.findAll(notification.class.DocNotifyContext, {
|
||||||
|
attachedTo: activityMessage.attachedTo
|
||||||
|
})
|
||||||
|
|
||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
res = res.concat(
|
res = res.concat(
|
||||||
@ -714,6 +721,17 @@ async function collectionCollabDoc (
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isNotificationPushed = (res as TxCUD<Doc>[])
|
||||||
|
.filter(
|
||||||
|
(ctx: TxCUD<Doc>): ctx is TxCreateDoc<ActivityInboxNotification> =>
|
||||||
|
ctx._class === core.class.TxCreateDoc && ctx.objectClass === notification.class.ActivityInboxNotification
|
||||||
|
)
|
||||||
|
.some(({ attributes }) => attributes.attachedTo === activityMessage._id)
|
||||||
|
|
||||||
|
if (isNotificationPushed) {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
const mixin = control.hierarchy.classHierarchyMixin(tx.objectClass, notification.mixin.ClassCollaborators)
|
const mixin = control.hierarchy.classHierarchyMixin(tx.objectClass, notification.mixin.ClassCollaborators)
|
||||||
|
|
||||||
if (mixin === undefined) {
|
if (mixin === undefined) {
|
||||||
|
Loading…
Reference in New Issue
Block a user