Notification fix (#2330)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2022-10-27 20:26:15 +06:00 committed by GitHub
parent e2db2c7a81
commit 2c681a88a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 22 deletions

View File

@ -32,6 +32,7 @@ import core, {
TxCollectionCUD,
TxCreateDoc,
TxCUD,
TxFactory,
TxProcessor
} from '@hcengineering/core'
import notification, {
@ -50,7 +51,8 @@ import serverNotification, {
createLastViewTx,
getEmployeeAccount,
getEmployeeAccountById,
getUpdateLastViewTx
getUpdateLastViewTx,
getEmployee
} from '@hcengineering/server-notification'
import { replaceAll } from './utils'
import { Content } from './types'
@ -209,9 +211,19 @@ export async function createNotificationTxes (
const content = await getContent(doc, senderName, type, control, data)
if (await isAllowed(control, receiver, notification.ids.PlatformNotification)) {
const createNotificationTx = await getPlatformNotificationTx(ptx, type, content?.text, action)
const target = await getEmployee(receiver.employee, control)
if (target !== undefined) {
const createNotificationTx = await getPlatformNotificationTx(
ptx,
type,
control.txFactory,
target,
content?.text,
action
)
res.push(createNotificationTx)
res.push(createNotificationTx)
}
}
if (content !== undefined && (await isAllowed(control, receiver, notification.ids.EmailNotification))) {
@ -227,6 +239,8 @@ export async function createNotificationTxes (
async function getPlatformNotificationTx (
ptx: TxCollectionCUD<Doc, AttachedDoc>,
type: Ref<NotificationType>,
txFactory: TxFactory,
target: Employee,
text?: string,
action?: NotificationAction
): Promise<TxCollectionCUD<Doc, Notification>> {
@ -254,14 +268,7 @@ async function getPlatformNotificationTx (
createTx.attributes.action = action
}
const createNotificationTx: TxCollectionCUD<Doc, Notification> = {
...ptx,
_id: generateId(),
collection: 'notifications',
tx: createTx
}
return createNotificationTx
return txFactory.createTxCollectionCUD(target._class, target._id, target.space, 'notifications', createTx)
}
async function getEmailNotificationTx (

View File

@ -19,12 +19,7 @@ import login from '@hcengineering/login'
import { NotificationAction } from '@hcengineering/notification'
import { getMetadata, Resource } from '@hcengineering/platform'
import { TriggerControl } from '@hcengineering/server-core'
import {
getEmployee,
getEmployeeAccount,
getEmployeeAccountById,
getUpdateLastViewTx
} from '@hcengineering/server-notification'
import { getEmployeeAccount, getEmployeeAccountById, getUpdateLastViewTx } from '@hcengineering/server-notification'
import { createNotificationTxes } from '@hcengineering/server-notification-resources'
import task, { Issue, Task, taskId } from '@hcengineering/task'
import view from '@hcengineering/view'
@ -63,11 +58,6 @@ export async function addAssigneeNotification (
return
}
const target = await getEmployee(assignee, control)
if (target === undefined) {
return
}
const receiver = await getEmployeeAccount(assignee, control)
if (receiver === undefined) {
return