Adjust archiveAll/readAll (#4972)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-03-15 08:08:07 +04:00 committed by GitHub
parent ecf2a5193a
commit 76cf81381b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 })