From 58f56c1161159ceab70562ab7a7f107b1670355e Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 14 Feb 2024 21:31:15 +0400 Subject: [PATCH] UBERF-5467: remove hidden notifications and use Lazy on inbox (#4632) Signed-off-by: Kristina Fefelova --- models/notification/src/migration.ts | 44 +++++++ packages/ui/src/components/ListView.svelte | 123 +++++++++--------- .../ui/src/components/ListViewItem.svelte | 78 +++++++++++ .../components/inbox/InboxFlatListView.svelte | 9 +- .../inbox/InboxGroupedListView.svelte | 9 +- plugins/notification-resources/src/utils.ts | 3 +- 6 files changed, 201 insertions(+), 65 deletions(-) create mode 100644 packages/ui/src/components/ListViewItem.svelte diff --git a/models/notification/src/migration.ts b/models/notification/src/migration.ts index bfe0dacccb..48ea1cc525 100644 --- a/models/notification/src/migration.ts +++ b/models/notification/src/migration.ts @@ -133,6 +133,10 @@ async function getInboxNotifications ( } async function getInboxData (client: MigrationClient, docUpdate: DocUpdates): Promise { + if (docUpdate.hidden) { + return + } + if (!client.hierarchy.hasClass(docUpdate.attachedToClass)) { console.log('cannot find class: ', docUpdate.attachedToClass) return @@ -195,6 +199,40 @@ async function migrateInboxNotifications (client: MigrationClient): Promise { + const processedIds: Ref[] = [] + + while (true) { + const contexts = await client.find( + DOMAIN_NOTIFICATION, + { + _class: notification.class.DocNotifyContext, + _id: { $nin: processedIds }, + hidden: true + }, + { limit: 500 } + ) + + if (contexts.length === 0) { + return + } + + const ids = contexts.map(({ _id }) => _id) + + processedIds.push(...ids) + + await client.deleteMany(DOMAIN_NOTIFICATION, { + _class: notification.class.CommonInboxNotification, + docNotifyContext: { $in: ids } + }) + + await client.deleteMany(DOMAIN_NOTIFICATION, { + _class: notification.class.ActivityInboxNotification, + docNotifyContext: { $in: ids } + }) + } +} + export const notificationOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise { await tryMigrate(client, notificationId, [ @@ -203,6 +241,12 @@ export const notificationOperation: MigrateOperation = { func: migrateInboxNotifications } ]) + await tryMigrate(client, notificationId, [ + { + state: 'remove-hidden-notifications', + func: removeHiddenNotifications + } + ]) }, async upgrade (client: MigrationUpgradeClient): Promise { await createSpace(client) diff --git a/packages/ui/src/components/ListView.svelte b/packages/ui/src/components/ListView.svelte index d70edc4d41..55a7840a60 100644 --- a/packages/ui/src/components/ListView.svelte +++ b/packages/ui/src/components/ListView.svelte @@ -15,6 +15,8 @@ + + + + +
{}} + bind:this={element} + on:click +> + +
+ + diff --git a/plugins/notification-resources/src/components/inbox/InboxFlatListView.svelte b/plugins/notification-resources/src/components/inbox/InboxFlatListView.svelte index abb44d593c..9b301f9713 100644 --- a/plugins/notification-resources/src/components/inbox/InboxFlatListView.svelte +++ b/plugins/notification-resources/src/components/inbox/InboxFlatListView.svelte @@ -71,7 +71,14 @@
- + {@const notification = notifications[itemIndex]}
diff --git a/plugins/notification-resources/src/components/inbox/InboxGroupedListView.svelte b/plugins/notification-resources/src/components/inbox/InboxGroupedListView.svelte index cacb502552..fd35c2f1e6 100644 --- a/plugins/notification-resources/src/components/inbox/InboxGroupedListView.svelte +++ b/plugins/notification-resources/src/components/inbox/InboxGroupedListView.svelte @@ -96,7 +96,14 @@
- + {@const contextId = displayData[itemIndex][0]} {@const contextNotifications = displayData[itemIndex][1]} diff --git a/plugins/notification-resources/src/utils.ts b/plugins/notification-resources/src/utils.ts index 904c6de0ae..a6fe3681e2 100644 --- a/plugins/notification-resources/src/utils.ts +++ b/plugins/notification-resources/src/utils.ts @@ -216,11 +216,12 @@ export async function hasHiddenDocNotifyContext (contexts: DocNotifyContext[]): export async function hideDocNotifyContext (notifyContext: DocNotifyContext): Promise { const client = getClient() await client.update(notifyContext, { hidden: true }) + await deleteContextNotifications(notifyContext) } export async function unHideDocNotifyContext (notifyContext: DocNotifyContext): Promise { const client = getClient() - await client.update(notifyContext, { hidden: false }) + await client.update(notifyContext, { hidden: false, lastViewedTimestamp: Date.now() }) } export async function isDocNotifyContextHidden (notifyContext: DocNotifyContext): Promise {