From 32f0a7d9b2a540d25ba6b5e5766413cf52b05bca Mon Sep 17 00:00:00 2001 From: Kristina Date: Mon, 5 Aug 2024 19:16:25 +0400 Subject: [PATCH] Get rid of 'ne' in inbox queries (#6258) Signed-off-by: Kristina Fefelova --- models/notification/src/index.ts | 2 +- models/notification/src/migration.ts | 23 ++++++++++++++++++- .../src/components/inbox/Inbox.svelte | 4 ++-- .../src/inboxNotificationsClient.ts | 16 ++++++------- plugins/notification-resources/src/utils.ts | 2 +- plugins/notification/src/index.ts | 2 +- .../activity-resources/src/references.ts | 3 ++- .../notification-resources/src/index.ts | 1 + .../github/pod-github/src/notifications.ts | 1 + 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/models/notification/src/index.ts b/models/notification/src/index.ts index 2f7431ac37..19921bde15 100644 --- a/models/notification/src/index.ts +++ b/models/notification/src/index.ts @@ -228,7 +228,7 @@ export class TInboxNotification extends TDoc implements InboxNotification { isViewed!: boolean @Prop(TypeBoolean(), core.string.Boolean) - archived?: boolean + archived!: boolean title?: IntlString body?: IntlString diff --git a/models/notification/src/migration.ts b/models/notification/src/migration.ts index cc49e302b3..567f99608f 100644 --- a/models/notification/src/migration.ts +++ b/models/notification/src/migration.ts @@ -25,7 +25,8 @@ import notification, { notificationId, NotificationStatus, type BrowserNotification, - type DocNotifyContext + type DocNotifyContext, + type InboxNotification } from '@hcengineering/notification' import { DOMAIN_PREFERENCE } from '@hcengineering/preference' @@ -166,6 +167,26 @@ export const notificationOperation: MigrateOperation = { DOMAIN_USER_NOTIFY ) } + }, + { + state: 'fill-notification-archived-field-v1', + func: async (client) => { + await client.update( + DOMAIN_NOTIFICATION, + { _class: notification.class.ActivityInboxNotification, archived: { $exists: false } }, + { archived: false } + ) + await client.update( + DOMAIN_NOTIFICATION, + { _class: notification.class.CommonInboxNotification, archived: { $exists: false } }, + { archived: false } + ) + await client.update( + DOMAIN_NOTIFICATION, + { _class: notification.class.MentionInboxNotification, archived: { $exists: false } }, + { archived: false } + ) + } } ]) await client.deleteMany(DOMAIN_USER_NOTIFY, { diff --git a/plugins/notification-resources/src/components/inbox/Inbox.svelte b/plugins/notification-resources/src/components/inbox/Inbox.svelte index 495bbbdab8..0d6004c343 100644 --- a/plugins/notification-resources/src/components/inbox/Inbox.svelte +++ b/plugins/notification-resources/src/components/inbox/Inbox.svelte @@ -110,8 +110,8 @@ ) archivedOtherNotificationsQuery.query( - notification.class.InboxNotification, - { _class: { $ne: notification.class.ActivityInboxNotification }, archived: true, user: me._id }, + notification.class.CommonInboxNotification, + { archived: true, user: me._id }, (res) => { archivedOtherNotifications = res }, diff --git a/plugins/notification-resources/src/inboxNotificationsClient.ts b/plugins/notification-resources/src/inboxNotificationsClient.ts index 1e7ea66e24..dce208794e 100644 --- a/plugins/notification-resources/src/inboxNotificationsClient.ts +++ b/plugins/notification-resources/src/inboxNotificationsClient.ts @@ -34,6 +34,7 @@ import notification, { } from '@hcengineering/notification' import { createQuery, getClient } from '@hcengineering/presentation' import { derived, get, writable } from 'svelte/store' + import { isActivityNotification } from './utils' /** @@ -101,10 +102,9 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { } ) this.otherInboxNotificationsQuery.query( - notification.class.InboxNotification, + notification.class.CommonInboxNotification, { - _class: { $ne: notification.class.ActivityInboxNotification }, - archived: { $ne: true }, + archived: false, user: getCurrentAccount()._id }, (result: InboxNotification[]) => { @@ -120,7 +120,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { this.activityInboxNotificationsQuery.query( notification.class.ActivityInboxNotification, { - archived: { $ne: true }, + archived: false, user: getCurrentAccount()._id }, (result: ActivityInboxNotification[]) => { @@ -242,7 +242,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { notification.class.InboxNotification, { user: getCurrentAccount()._id, - archived: { $ne: true } + archived: false }, { projection: { _id: 1, _class: 1, space: 1 } } ) @@ -267,8 +267,8 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { notification.class.InboxNotification, { user: getCurrentAccount()._id, - isViewed: { $ne: true }, - archived: { $ne: true } + isViewed: false, + archived: false }, { projection: { _id: 1, _class: 1, space: 1 } } ) @@ -293,7 +293,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { { user: getCurrentAccount()._id, isViewed: true, - archived: { $ne: true } + archived: false }, { projection: { _id: 1, _class: 1, space: 1, docNotifyContext: 1 }, diff --git a/plugins/notification-resources/src/utils.ts b/plugins/notification-resources/src/utils.ts index 5b6a75f15b..a44b2764d8 100644 --- a/plugins/notification-resources/src/utils.ts +++ b/plugins/notification-resources/src/utils.ts @@ -186,7 +186,7 @@ export async function archiveContextNotifications (doc?: DocNotifyContext): Prom try { const notifications = await ops.findAll( notification.class.InboxNotification, - { docNotifyContext: doc._id, archived: { $ne: true } }, + { docNotifyContext: doc._id, archived: false }, { projection: { _id: 1, _class: 1, space: 1 } } ) diff --git a/plugins/notification/src/index.ts b/plugins/notification/src/index.ts index fe282ea777..80cfb0c486 100644 --- a/plugins/notification/src/index.ts +++ b/plugins/notification/src/index.ts @@ -234,7 +234,7 @@ export interface InboxNotification extends Doc { body?: IntlString intlParams?: Record intlParamsNotLocalized?: Record - archived?: boolean + archived: boolean } export interface ActivityInboxNotification extends InboxNotification { diff --git a/server-plugins/activity-resources/src/references.ts b/server-plugins/activity-resources/src/references.ts index f65d49b876..f2021a96cc 100644 --- a/server-plugins/activity-resources/src/references.ts +++ b/server-plugins/activity-resources/src/references.ts @@ -157,7 +157,8 @@ export async function getPersonNotificationTxes ( mentionedIn: reference.attachedDocId ?? reference.srcDocId, mentionedInClass: reference.attachedDocClass ?? reference.srcDocClass, user: receiver._id, - isViewed: false + isViewed: false, + archived: false } const sender = ( diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index 2d6012e6b3..2169d34523 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -381,6 +381,7 @@ export async function pushInboxNotifications ( user: account._id, isViewed: false, docNotifyContext: docNotifyContextId, + archived: false, ...data } const notificationTx = control.txFactory.createTxCreateDoc(_class, space, notificationData) diff --git a/services/github/pod-github/src/notifications.ts b/services/github/pod-github/src/notifications.ts index 310359a0b1..65be33bb17 100644 --- a/services/github/pod-github/src/notifications.ts +++ b/services/github/pod-github/src/notifications.ts @@ -38,6 +38,7 @@ export async function createNotification ( message: data.message, props: data.props, isViewed: false, + archived: false, docNotifyContext: docNotifyContext?._id as Ref }) }