UBERF-8547: Inbox cleanup and other (#7058)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-10-29 20:06:16 +07:00
committed by GitHub
parent 400772b792
commit f258c6755a
53 changed files with 397 additions and 1120 deletions
@@ -148,13 +148,15 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
return InboxNotificationsClientImpl._instance
}
async readDoc (client: TxOperations, _id: Ref<Doc>): Promise<void> {
async readDoc (_id: Ref<Doc>): Promise<void> {
const docNotifyContext = this._contextByDoc.get(_id)
if (docNotifyContext === undefined) {
return
}
const client = getClient()
const op = client.apply(undefined, 'readDoc', true)
const inboxNotifications = await client.findAll(
notification.class.InboxNotification,
{ docNotifyContext: docNotifyContext._id, isViewed: false },
@@ -162,19 +164,20 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
)
for (const notification of inboxNotifications) {
await client.updateDoc(notification._class, notification.space, notification._id, { isViewed: true })
await op.updateDoc(notification._class, notification.space, notification._id, { isViewed: true })
}
await client.update(docNotifyContext, { lastViewedTimestamp: Date.now() })
await op.update(docNotifyContext, { lastViewedTimestamp: Date.now() })
}
async forceReadDoc (client: TxOperations, _id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<void> {
async forceReadDoc (_id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<void> {
const context = this._contextByDoc.get(_id)
if (context !== undefined) {
await this.readDoc(client, _id)
await this.readDoc(_id)
return
}
const client = getClient()
const doc = await client.findOne(_class, { _id })
if (doc === undefined) {
@@ -230,7 +233,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
async archiveNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
const inboxNotifications = (get(this.inboxNotifications) ?? []).filter(({ _id }) => ids.includes(_id))
for (const notification of inboxNotifications) {
await client.update(notification, { archived: true })
await client.update(notification, { archived: true, isViewed: true })
}
}
@@ -248,7 +251,10 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
)
const contexts = get(this.contexts) ?? []
for (const notification of inboxNotifications) {
await ops.updateDoc(notification._class, notification.space, notification._id, { archived: true })
await ops.updateDoc(notification._class, notification.space, notification._id, {
archived: true,
isViewed: true
})
}
for (const context of contexts) {