From 7bf2a7c8d1600614474d5dda256d853f8445a964 Mon Sep 17 00:00:00 2001 From: Kristina Date: Sat, 3 Aug 2024 10:11:06 +0400 Subject: [PATCH] Remove slow trigger (#6240) Signed-off-by: Kristina Fefelova --- desktop-package/package.json | 2 +- desktop/package.json | 2 +- models/server-notification/src/index.ts | 8 --- .../src/activityMessagesUtils.ts | 2 +- plugins/chunter-resources/src/utils.ts | 12 ++++- .../notification-resources/src/index.ts | 53 ------------------- server-plugins/notification/src/index.ts | 1 - 7 files changed, 14 insertions(+), 66 deletions(-) diff --git a/desktop-package/package.json b/desktop-package/package.json index 0b7e3cb98d..2291d5c053 100644 --- a/desktop-package/package.json +++ b/desktop-package/package.json @@ -1,6 +1,6 @@ { "name": "desktop", - "version": "0.6.266", + "version": "0.6.271", "main": "dist/main/electron.js", "author": "Hardcore Engineering ", "template": "@hcengineering/default-package", diff --git a/desktop/package.json b/desktop/package.json index 686f32fe53..b6aa591571 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/desktop", - "version": "0.6.266", + "version": "0.6.271", "main": "dist/main/electron.js", "template": "@hcengineering/webpack-package", "scripts": { diff --git a/models/server-notification/src/index.ts b/models/server-notification/src/index.ts index 6fc68eab55..d6e371b5a4 100644 --- a/models/server-notification/src/index.ts +++ b/models/server-notification/src/index.ts @@ -72,14 +72,6 @@ export function createModel (builder: Builder): void { TNotificationProviderResources ) - builder.createDoc(serverCore.class.Trigger, core.space.Model, { - trigger: serverNotification.trigger.OnActivityNotificationViewed, - txMatch: { - _class: core.class.TxUpdateDoc, - objectClass: notification.class.ActivityInboxNotification - } - }) - builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverNotification.trigger.OnAttributeCreate, txMatch: { diff --git a/plugins/activity-resources/src/activityMessagesUtils.ts b/plugins/activity-resources/src/activityMessagesUtils.ts index 72d7ca9644..4d503fd869 100644 --- a/plugins/activity-resources/src/activityMessagesUtils.ts +++ b/plugins/activity-resources/src/activityMessagesUtils.ts @@ -579,7 +579,7 @@ export function isActivityMessage (message?: Doc): message is ActivityMessage { return getClient().getHierarchy().isDerived(message._class, activity.class.ActivityMessage) } -export function isReactionMessage (message?: ActivityMessage): boolean { +export function isReactionMessage (message?: ActivityMessage): message is DocUpdateMessage { if (message === undefined) { return false } diff --git a/plugins/chunter-resources/src/utils.ts b/plugins/chunter-resources/src/utils.ts index ea07a1bc0b..05baaf95ce 100644 --- a/plugins/chunter-resources/src/utils.ts +++ b/plugins/chunter-resources/src/utils.ts @@ -46,6 +46,7 @@ import { getClient } from '@hcengineering/presentation' import { type AnySvelteComponent } from '@hcengineering/ui' import { classIcon, getDocLinkTitle, getDocTitle } from '@hcengineering/view-resources' import { get, writable, type Unsubscriber } from 'svelte/store' +import { isReactionMessage } from '@hcengineering/activity-resources' import ChannelIcon from './components/ChannelIcon.svelte' import DirectIcon from './components/DirectIcon.svelte' @@ -439,7 +440,16 @@ export async function readChannelMessages ( const allIds = getAllIds(messages).filter((id) => !readMessages.has(id)) const notifications = get(inboxClient.activityInboxNotifications) - .filter(({ _id, attachedTo }) => allIds.includes(attachedTo)) + .filter(({ attachedTo, $lookup, isViewed }) => { + if (isViewed) return false + const includes = allIds.includes(attachedTo) + if (includes) return true + const msg = $lookup?.attachedTo + if (isReactionMessage(msg)) { + return allIds.includes(msg.attachedTo as Ref) + } + return false + }) .map((n) => n._id) const relatedMentions = get(inboxClient.otherInboxNotifications) diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index a3113231f4..2d6012e6b3 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -1516,58 +1516,6 @@ export async function removeDocInboxNotifications (_id: Ref, co ) } -async function OnActivityNotificationViewed ( - tx: TxUpdateDoc, - control: TriggerControl -): Promise { - if (tx.objectClass !== notification.class.ActivityInboxNotification || tx.operations.isViewed !== true) { - return [] - } - - const inboxNotification = ( - await control.findAll( - notification.class.ActivityInboxNotification, - { - _id: tx.objectId as Ref - }, - { projection: { _id: 1, attachedTo: 1, user: 1 } } - ) - )[0] - - if (inboxNotification === undefined) { - return [] - } - - // Read reactions notifications when message is read - const { attachedTo, user } = inboxNotification - - const reactionMessages = await control.findAll( - activity.class.DocUpdateMessage, - { - attachedTo, - objectClass: activity.class.Reaction - }, - { projection: { _id: 1 } } - ) - - if (reactionMessages.length === 0) { - return [] - } - - const reactionNotifications = await control.findAll( - notification.class.ActivityInboxNotification, - { - attachedTo: { $in: reactionMessages.map(({ _id }) => _id) }, - user - }, - { projection: { _id: 1, _class: 1, space: 1 } } - ) - - return reactionNotifications.map(({ _id, _class, space }) => - control.txFactory.createTxUpdateDoc(_class, space, _id, { isViewed: true }) - ) -} - export async function getCollaborators ( doc: Doc, control: TriggerControl, @@ -1659,7 +1607,6 @@ export default async () => ({ trigger: { OnAttributeCreate, OnAttributeUpdate, - OnActivityNotificationViewed, OnDocRemove }, function: { diff --git a/server-plugins/notification/src/index.ts b/server-plugins/notification/src/index.ts index a6561a3760..331cf45822 100644 --- a/server-plugins/notification/src/index.ts +++ b/server-plugins/notification/src/index.ts @@ -180,7 +180,6 @@ export default plugin(serverNotificationId, { OnAttributeCreate: '' as Resource, OnAttributeUpdate: '' as Resource, OnReactionChanged: '' as Resource, - OnActivityNotificationViewed: '' as Resource, OnDocRemove: '' as Resource }, function: {