Fix LastView tx space (#1029)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-02-21 15:12:25 +06:00 committed by GitHub
parent 6748b60eca
commit 90b8edf5ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@
// limitations under the License.
//
import { Class, Doc, getCurrentAccount, Ref, Timestamp } from '@anticrm/core'
import core, { Class, Doc, getCurrentAccount, Ref, Timestamp } from '@anticrm/core'
import notification, { LastView } from '@anticrm/notification'
import { createQuery, getClient } from '@anticrm/presentation'
import { writable, Writable } from 'svelte/store'
@ -63,18 +63,22 @@ export class NotificationClient {
const current = this.lastViews.get(_id)
if (current !== undefined) {
if (current.lastView < lastView || force) {
await client.updateDoc(current._class, current.space, current._id, {
const u = client.txFactory.createTxUpdateDoc(current._class, current.space, current._id, {
lastView: lastView
})
u.space = core.space.DerivedTx
await client.tx(u)
}
} else if (force) {
await client.createDoc(notification.class.LastView, notification.space.Notifications, {
const u = client.txFactory.createTxCreateDoc(notification.class.LastView, notification.space.Notifications, {
user,
lastView,
attachedTo: _id,
attachedToClass: _class,
collection: 'lastViews'
})
u.space = core.space.DerivedTx
await client.tx(u)
}
}