mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-22 16:27:22 +00:00
Use Analytics to catch errors (#5992)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
1359838df4
commit
15d9661f29
@ -39,6 +39,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hcengineering/activity": "^0.6.0",
|
"@hcengineering/activity": "^0.6.0",
|
||||||
|
"@hcengineering/analytics": "^0.6.0",
|
||||||
"@hcengineering/core": "^0.6.32",
|
"@hcengineering/core": "^0.6.32",
|
||||||
"@hcengineering/platform": "^0.6.11",
|
"@hcengineering/platform": "^0.6.11",
|
||||||
"@hcengineering/server-core": "^0.6.1",
|
"@hcengineering/server-core": "^0.6.1",
|
||||||
|
@ -81,6 +81,7 @@ import { workbenchId } from '@hcengineering/workbench'
|
|||||||
import webpush, { WebPushError } from 'web-push'
|
import webpush, { WebPushError } from 'web-push'
|
||||||
import { encodeObjectURI } from '@hcengineering/view'
|
import { encodeObjectURI } from '@hcengineering/view'
|
||||||
import serverView from '@hcengineering/server-view'
|
import serverView from '@hcengineering/server-view'
|
||||||
|
import { Analytics } from '@hcengineering/analytics'
|
||||||
|
|
||||||
import { Content, NotifyResult, NotifyParams } from './types'
|
import { Content, NotifyResult, NotifyParams } from './types'
|
||||||
import {
|
import {
|
||||||
@ -463,8 +464,9 @@ async function activityInboxNotificationToText (doc: Data<ActivityInboxNotificat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: temporary log to understand problem. Remove it later.
|
// TODO: temporary log to understand problem. Remove it later.
|
||||||
if (doc.body === 'chunter:string:MessageNotificationBody') {
|
if (body === 'chunter:string:MessageNotificationBody') {
|
||||||
console.error('Cannot translate chunter notification: ', { doc, params })
|
console.error('Cannot translate chunter notification: ', { doc, params })
|
||||||
|
Analytics.handleError(new Error('Cannot translate chunter notification'))
|
||||||
}
|
}
|
||||||
|
|
||||||
return [title, body]
|
return [title, body]
|
||||||
|
@ -44,6 +44,8 @@ import serverNotification, {
|
|||||||
import { getResource, IntlString, translate } from '@hcengineering/platform'
|
import { getResource, IntlString, translate } from '@hcengineering/platform'
|
||||||
import contact, { formatName, Person, PersonAccount } from '@hcengineering/contact'
|
import contact, { formatName, Person, PersonAccount } from '@hcengineering/contact'
|
||||||
import { DocUpdateMessage } from '@hcengineering/activity'
|
import { DocUpdateMessage } from '@hcengineering/activity'
|
||||||
|
import { Analytics } from '@hcengineering/analytics'
|
||||||
|
|
||||||
import { NotifyResult } from './types'
|
import { NotifyResult } from './types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -298,6 +300,36 @@ export function getTextPresenter (_class: Ref<Class<Doc>>, hierarchy: Hierarchy)
|
|||||||
return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.TextPresenter)
|
return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.TextPresenter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getSenderName (
|
||||||
|
accountId: Ref<PersonAccount>,
|
||||||
|
control: TriggerControl,
|
||||||
|
cache: Map<Ref<Doc>, Doc>
|
||||||
|
): Promise<string> {
|
||||||
|
if (accountId === core.account.System) {
|
||||||
|
return await translate(core.string.System, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
const account = await getPersonAccountById(accountId, control)
|
||||||
|
|
||||||
|
if (account === undefined) {
|
||||||
|
console.error('Cannot find person account: ', accountId)
|
||||||
|
Analytics.handleError(new Error(`Cannot find person account ${accountId}`))
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const person =
|
||||||
|
(cache.get(accountId) as Person) ?? (await control.findAll(contact.class.Person, { _id: account.person }))[0]
|
||||||
|
|
||||||
|
if (person === undefined) {
|
||||||
|
console.error('Cannot find person', { accountId: account._id, person: account.person })
|
||||||
|
Analytics.handleError(new Error(`Cannot find person ${account.person}`))
|
||||||
|
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatName(person.name, control.branding?.lastNameFirst)
|
||||||
|
}
|
||||||
|
|
||||||
async function getFallbackNotificationFullfillment (
|
async function getFallbackNotificationFullfillment (
|
||||||
object: Doc,
|
object: Doc,
|
||||||
originTx: TxCUD<Doc>,
|
originTx: TxCUD<Doc>,
|
||||||
@ -316,23 +348,8 @@ async function getFallbackNotificationFullfillment (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tx = TxProcessor.extractTx(originTx)
|
const tx = TxProcessor.extractTx(originTx)
|
||||||
const account = control.modelDb.getObject(tx.modifiedBy) as PersonAccount
|
|
||||||
if (account !== undefined) {
|
|
||||||
const person =
|
|
||||||
(cache.get(account.person) as Person) ?? (await control.findAll(contact.class.Person, { _id: account.person }))[0]
|
|
||||||
if (person !== undefined) {
|
|
||||||
intlParams.senderName = formatName(person.name, control.branding?.lastNameFirst)
|
|
||||||
cache.set(person._id, person)
|
|
||||||
} else {
|
|
||||||
console.error('Cannot find person: ', { accountId: account._id, person: account.person })
|
|
||||||
}
|
|
||||||
} else if (tx.modifiedBy === core.account.System) {
|
|
||||||
intlParams.senderName = await translate(core.string.System, {})
|
|
||||||
} else {
|
|
||||||
console.error('Cannot find person account by _id: ', tx.modifiedBy)
|
|
||||||
}
|
|
||||||
|
|
||||||
intlParams.senderName = intlParams.senderName ?? ''
|
intlParams.senderName = await getSenderName(tx.modifiedBy as Ref<PersonAccount>, control, cache)
|
||||||
|
|
||||||
if (tx._class === core.class.TxUpdateDoc) {
|
if (tx._class === core.class.TxUpdateDoc) {
|
||||||
const updateTx = tx as TxUpdateDoc<Doc>
|
const updateTx = tx as TxUpdateDoc<Doc>
|
||||||
|
Loading…
Reference in New Issue
Block a user