From 76cf81381b50fc80c94564abcf079823c5e32c30 Mon Sep 17 00:00:00 2001 From: Kristina Date: Fri, 15 Mar 2024 08:08:07 +0400 Subject: [PATCH] Adjust archiveAll/readAll (#4972) Signed-off-by: Kristina Fefelova --- .../src/inboxNotificationsClient.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/plugins/notification-resources/src/inboxNotificationsClient.ts b/plugins/notification-resources/src/inboxNotificationsClient.ts index 02cd062b82..72ac5877c0 100644 --- a/plugins/notification-resources/src/inboxNotificationsClient.ts +++ b/plugins/notification-resources/src/inboxNotificationsClient.ts @@ -258,10 +258,16 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { const ops = getClient().apply(generateId()) try { - const inboxNotifications = get(this.inboxNotifications) ?? [] + const inboxNotifications = await ops.findAll( + notification.class.InboxNotification, + { + user: getCurrentAccount()._id + }, + { projection: { _id: 1, _class: 1, space: 1 } } + ) const contexts = get(this.docNotifyContexts) ?? [] for (const notification of inboxNotifications) { - await ops.remove(notification) + await ops.removeDoc(notification._class, notification.space, notification._id) } for (const context of contexts) { @@ -278,12 +284,17 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { const ops = getClient().apply(generateId()) try { - const inboxNotifications = get(this.inboxNotifications) ?? [] + const inboxNotifications = await ops.findAll( + notification.class.InboxNotification, + { + user: getCurrentAccount()._id, + isViewed: { $ne: true } + }, + { projection: { _id: 1, _class: 1, space: 1 } } + ) const contexts = get(this.docNotifyContexts) ?? [] for (const notification of inboxNotifications) { - if (!notification.isViewed) { - await ops.update(notification, { isViewed: true }) - } + await ops.updateDoc(notification._class, notification.space, notification._id, { isViewed: true }) } for (const context of contexts) { await ops.update(context, { lastViewedTimestamp: Date.now() }) @@ -299,13 +310,18 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { const ops = getClient().apply(generateId()) try { - const inboxNotifications = get(this.inboxNotifications) ?? [] + const inboxNotifications = await ops.findAll( + notification.class.InboxNotification, + { + user: getCurrentAccount()._id, + isViewed: true + }, + { projection: { _id: 1, _class: 1, space: 1 } } + ) const contexts = get(this.docNotifyContexts) ?? [] for (const notification of inboxNotifications) { - if (notification.isViewed) { - await ops.update(notification, { isViewed: false }) - } + await ops.updateDoc(notification._class, notification.space, notification._id, { isViewed: false }) } for (const context of contexts) { await ops.update(context, { lastViewedTimestamp: 0 })