mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-07 07:56:34 +00:00
Fix notifications (#7955)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
b97b858728
commit
529230ff68
@ -13,10 +13,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import aiBot from '@hcengineering/ai-bot'
|
||||
import analyticsCollector from '@hcengineering/analytics-collector'
|
||||
import chunter, { ChatMessage, ThreadMessage } from '@hcengineering/chunter'
|
||||
import core, { AttachedDoc, Tx, TxCreateDoc, TxCUD, TxProcessor } from '@hcengineering/core'
|
||||
import { ChatMessage } from '@hcengineering/chunter'
|
||||
import { AttachedDoc, Tx, TxCreateDoc, TxCUD } from '@hcengineering/core'
|
||||
import { ActivityInboxNotification, MentionInboxNotification } from '@hcengineering/notification'
|
||||
import { TriggerControl } from '@hcengineering/server-core'
|
||||
|
||||
@ -133,78 +131,61 @@ import { TriggerControl } from '@hcengineering/server-core'
|
||||
// }
|
||||
// }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async function onBotDirectMessageSend (control: TriggerControl, message: ChatMessage): Promise<void> {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// const account = control.modelDb.findAllSync(contact.class.PersonAccount, {
|
||||
// _id: (message.createdBy ?? message.modifiedBy) as PersonId
|
||||
// })[0]
|
||||
|
||||
// if (account === undefined) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// const direct = (await getMessageDoc(message, control)) as DirectMessage
|
||||
|
||||
// if (direct === undefined) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// const isAvailable = await isDirectAvailable(direct, control)
|
||||
|
||||
// if (!isAvailable) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// let messageEvent: AIMessageEventRequest
|
||||
|
||||
// if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) {
|
||||
// messageEvent = getThreadMessageData(message as ThreadMessage, account.email)
|
||||
// } else {
|
||||
// messageEvent = getMessageData(direct, message, account.email)
|
||||
// }
|
||||
|
||||
// const transferEvent = await createTransferEvent(control, message, account, messageEvent)
|
||||
// const events = transferEvent !== undefined ? [messageEvent, transferEvent] : [messageEvent]
|
||||
|
||||
// await sendAIEvents(events, control.workspace.uuid, control.ctx)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async function onSupportWorkspaceMessage (control: TriggerControl, message: ChatMessage): Promise<void> {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// const supportWorkspaceId = getSupportWorkspaceId()
|
||||
|
||||
// if (supportWorkspaceId === undefined) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// if (control.workspace.uuid !== supportWorkspaceId) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// if (!control.hierarchy.isDerived(message.attachedToClass, analyticsCollector.class.OnboardingChannel)) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// const channel = (await getMessageDoc(message, control)) as OnboardingChannel
|
||||
|
||||
// if (channel === undefined) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// const { workspaceId, email } = channel
|
||||
// const account = control.modelDb.findAllSync(contact.class.PersonAccount, {
|
||||
// _id: (message.createdBy ?? message.modifiedBy) as PersonId
|
||||
// })[0]
|
||||
|
||||
// let data: AIMessageEventRequest
|
||||
// if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) {
|
||||
// data = getThreadMessageData(message as ThreadMessage, account.email)
|
||||
// } else {
|
||||
// data = getMessageData(channel, message, account.email)
|
||||
// }
|
||||
|
||||
// const transferEvent: AITransferEventRequest = {
|
||||
// type: AIEventType.Transfer,
|
||||
// createdOn: data.createdOn,
|
||||
@ -219,39 +200,39 @@ async function onSupportWorkspaceMessage (control: TriggerControl, message: Chat
|
||||
// messageId: message._id,
|
||||
// parentMessageId: await getThreadParent(control, message)
|
||||
// }
|
||||
|
||||
// await sendAIEvents([transferEvent], control.workspace.uuid, control.ctx)
|
||||
}
|
||||
|
||||
export async function OnMessageSend (originTxs: TxCUD<AttachedDoc>[], control: TriggerControl): Promise<Tx[]> {
|
||||
const { hierarchy } = control
|
||||
const txes = originTxs.filter(
|
||||
(it) =>
|
||||
it._class === core.class.TxCreateDoc &&
|
||||
hierarchy.isDerived(it.objectClass, chunter.class.ChatMessage) &&
|
||||
!(it.modifiedBy === aiBot.account.AIBot || it.modifiedBy === core.account.System)
|
||||
)
|
||||
if (txes.length === 0) {
|
||||
return []
|
||||
}
|
||||
for (const tx of txes) {
|
||||
const isThread = hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage)
|
||||
const message = TxProcessor.createDoc2Doc(tx as TxCreateDoc<ChatMessage>)
|
||||
|
||||
const docClass = isThread ? (message as ThreadMessage).objectClass : message.attachedToClass
|
||||
|
||||
if (!hierarchy.isDerived(docClass, chunter.class.ChunterSpace)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (docClass === chunter.class.DirectMessage) {
|
||||
await onBotDirectMessageSend(control, message)
|
||||
}
|
||||
|
||||
if (docClass === analyticsCollector.class.OnboardingChannel) {
|
||||
await onSupportWorkspaceMessage(control, message)
|
||||
}
|
||||
}
|
||||
// TODO: FIXME
|
||||
// const { hierarchy } = control
|
||||
// const txes = originTxs.filter(
|
||||
// (it) =>
|
||||
// it._class === core.class.TxCreateDoc &&
|
||||
// hierarchy.isDerived(it.objectClass, chunter.class.ChatMessage) &&
|
||||
// !(it.modifiedBy === aiBot.account.AIBot || it.modifiedBy === core.account.System)
|
||||
// )
|
||||
// if (txes.length === 0) {
|
||||
// return []
|
||||
// }
|
||||
// for (const tx of txes) {
|
||||
// const isThread = hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage)
|
||||
// const message = TxProcessor.createDoc2Doc(tx as TxCreateDoc<ChatMessage>)
|
||||
//
|
||||
// const docClass = isThread ? (message as ThreadMessage).objectClass : message.attachedToClass
|
||||
//
|
||||
// if (!hierarchy.isDerived(docClass, chunter.class.ChunterSpace)) {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// if (docClass === chunter.class.DirectMessage) {
|
||||
// await onBotDirectMessageSend(control, message)
|
||||
// }
|
||||
//
|
||||
// if (docClass === analyticsCollector.class.OnboardingChannel) {
|
||||
// await onSupportWorkspaceMessage(control, message)
|
||||
// }
|
||||
// }
|
||||
|
||||
return []
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import { TriggerControl } from '@hcengineering/server-core'
|
||||
import contact, { Employee, type Person } from '@hcengineering/contact'
|
||||
import { PersonId, toIdMap, parseSocialIdString, type Ref } from '@hcengineering/core'
|
||||
import { parseSocialIdString, PersonId, type Ref, toIdMap } from '@hcengineering/core'
|
||||
|
||||
export async function getTriggerCurrentPerson (control: TriggerControl): Promise<Person | undefined> {
|
||||
const { type, value } = parseSocialIdString(control.txFactory.account)
|
||||
@ -79,9 +79,13 @@ export async function getAllSocialStringsByPersonId (
|
||||
|
||||
export async function getPerson (control: TriggerControl, personId: PersonId): Promise<Person | undefined> {
|
||||
const socialId = (await control.findAll(control.ctx, contact.class.SocialIdentity, { key: personId }))[0]
|
||||
const person = (await control.findAll(control.ctx, contact.class.Person, { _id: socialId.attachedTo }))[0]
|
||||
|
||||
return person
|
||||
if (socialId === undefined) {
|
||||
control.ctx.error('Cannot find social id', { key: personId })
|
||||
return undefined
|
||||
}
|
||||
|
||||
return (await control.findAll(control.ctx, contact.class.Person, { _id: socialId.attachedTo }))[0]
|
||||
}
|
||||
|
||||
export async function getPersons (control: TriggerControl, personIds: PersonId[]): Promise<Person[]> {
|
||||
|
@ -147,16 +147,12 @@ async function notifyByEmail (
|
||||
message?: ActivityMessage
|
||||
): Promise<void> {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// const account = receiver.account
|
||||
|
||||
// if (account === undefined) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// const senderPerson = sender.person
|
||||
// const senderName = senderPerson !== undefined ? formatName(senderPerson.name, control.branding?.lastNameFirst) : ''
|
||||
|
||||
// const content = await getContentByTemplate(doc, senderName, type, control, '', data, message)
|
||||
// if (content !== undefined) {
|
||||
// await sendEmailNotification(control.ctx, content.text, content.html, content.subject, account.email)
|
||||
@ -173,7 +169,6 @@ const SendEmailNotifications: NotificationProviderFunc = async (
|
||||
message?: ActivityMessage
|
||||
): Promise<Tx[]> => {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// if (types.length === 0) {
|
||||
// return []
|
||||
// }
|
||||
@ -190,7 +185,7 @@ const SendEmailNotifications: NotificationProviderFunc = async (
|
||||
// await notifyByEmail(control, type._id, object, sender, receiver, data, message)
|
||||
// }
|
||||
|
||||
// return []
|
||||
return []
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
|
@ -45,7 +45,6 @@ export async function getValue (control: TriggerControl, context: Record<string,
|
||||
async function getEmployee (control: TriggerControl, _id: PersonId): Promise<Person | undefined> {
|
||||
// TODO: FIXME
|
||||
// Related to integrations
|
||||
throw new Error('Not implemented')
|
||||
// const employeeAccount = control.modelDb.findAllSync(contact.class.PersonAccount, {
|
||||
// _id: _id as PersonId
|
||||
// })[0]
|
||||
@ -57,6 +56,7 @@ async function getEmployee (control: TriggerControl, _id: PersonId): Promise<Per
|
||||
// )[0]
|
||||
// return employee
|
||||
// }
|
||||
return undefined
|
||||
}
|
||||
|
||||
export async function getOwnerFirstName (
|
||||
|
@ -114,7 +114,6 @@ export async function GetCurrentEmployeeTG (
|
||||
context: Record<string, Doc>
|
||||
): Promise<string | undefined> {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// const account = await control.modelDb.findOne(contact.class.PersonAccount, {
|
||||
// _id: control.txFactory.account as PersonId
|
||||
// })
|
||||
@ -125,6 +124,8 @@ export async function GetCurrentEmployeeTG (
|
||||
// if (employee !== undefined) {
|
||||
// return await getContactChannel(control, employee, contact.channelProvider.Telegram)
|
||||
// }
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
export async function GetIntegrationOwnerTG (
|
||||
@ -132,7 +133,6 @@ export async function GetIntegrationOwnerTG (
|
||||
context: Record<string, Doc>
|
||||
): Promise<string | undefined> {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// const value = context[setting.class.Integration] as Integration
|
||||
// if (value === undefined) return
|
||||
// const account = await control.modelDb.findOne(contact.class.PersonAccount, {
|
||||
@ -145,6 +145,8 @@ export async function GetIntegrationOwnerTG (
|
||||
// if (employee !== undefined) {
|
||||
// return await getContactChannel(control, employee, contact.channelProvider.Telegram)
|
||||
// }
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
async function getContactChannel (
|
||||
@ -261,7 +263,6 @@ const SendTelegramNotifications: NotificationProviderFunc = async (
|
||||
message?: ActivityMessage
|
||||
): Promise<Tx[]> => {
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// if (types.length === 0) {
|
||||
// return []
|
||||
// }
|
||||
@ -312,7 +313,7 @@ const SendTelegramNotifications: NotificationProviderFunc = async (
|
||||
// })
|
||||
// }
|
||||
|
||||
// return []
|
||||
return []
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
|
Loading…
Reference in New Issue
Block a user