TSK-1341 Remove last view (#3115)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2023-04-29 22:46:13 +07:00
committed by GitHub
parent 9b04d366e3
commit ae8fcf8d62
41 changed files with 204 additions and 645 deletions
+2 -73
View File
@@ -15,8 +15,8 @@
//
import contact, { Employee, EmployeeAccount } from '@hcengineering/contact'
import { Account, Class, Doc, Mixin, Ref, Tx, TxCreateDoc, TxFactory, TxUpdateDoc } from '@hcengineering/core'
import notification, { LastView, NotificationType } from '@hcengineering/notification'
import { Account, Class, Doc, Mixin, Ref, Tx } from '@hcengineering/core'
import { NotificationType } from '@hcengineering/notification'
import { Plugin, Resource, plugin } from '@hcengineering/platform'
import type { TriggerControl, TriggerFunc } from '@hcengineering/server-core'
@@ -25,42 +25,6 @@ import type { TriggerControl, TriggerFunc } from '@hcengineering/server-core'
*/
export const serverNotificationId = 'server-notification' as Plugin
/**
* @public
*/
export async function getUpdateLastViewTx (
findAll: TriggerControl['findAll'],
attachedTo: Ref<Doc>,
lastView: number,
user: Ref<Account>
): Promise<TxUpdateDoc<LastView> | TxCreateDoc<LastView> | undefined> {
const current = (
await findAll(
notification.class.LastView,
{
user
},
{ limit: 1 }
)
)[0]
const factory = new TxFactory(user, true)
if (current !== undefined) {
if (current[attachedTo] === -1 || current[attachedTo] >= lastView) {
return
}
const u = factory.createTxUpdateDoc(current._class, current.space, current._id, {
[attachedTo]: lastView
})
return u
} else {
const u = factory.createTxCreateDoc(notification.class.LastView, notification.space.Notifications, {
user,
[attachedTo]: lastView
})
return u
}
}
/**
* @public
*/
@@ -115,38 +79,6 @@ export async function getEmployee (employee: Ref<Employee>, control: TriggerCont
return account
}
/**
* @public
*/
export async function createLastViewTx (
findAll: TriggerControl['findAll'],
attachedTo: Ref<Doc>,
user: Ref<Account>
): Promise<TxCreateDoc<LastView> | TxUpdateDoc<LastView> | undefined> {
const current = (
await findAll(
notification.class.LastView,
{
user
},
{ limit: 1 }
)
)[0]
const factory = new TxFactory(user, true)
if (current === undefined) {
const u = factory.createTxCreateDoc(notification.class.LastView, notification.space.Notifications, {
user,
[attachedTo]: 1
})
return u
} else if (current[attachedTo] === undefined) {
const u = factory.createTxUpdateDoc(current._class, current.space, current._id, {
[attachedTo]: 1
})
return u
}
}
/**
* @public
*/
@@ -191,10 +123,7 @@ export default plugin(serverNotificationId, {
},
trigger: {
OnBacklinkCreate: '' as Resource<TriggerFunc>,
UpdateLastView: '' as Resource<TriggerFunc>,
OnUpdateLastView: '' as Resource<TriggerFunc>,
CollaboratorDocHandler: '' as Resource<TriggerFunc>,
OnAddCollborator: '' as Resource<TriggerFunc>,
OnAttributeCreate: '' as Resource<TriggerFunc>,
OnAttributeUpdate: '' as Resource<TriggerFunc>
},