Add logs for not translated push notifications (#5986)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-07-03 12:13:16 +04:00 committed by GitHub
parent 73afaddc65
commit 9d3ce44ce7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 18 deletions

View File

@ -557,7 +557,7 @@
const { offsetHeight, scrollHeight, scrollTop } = scrollElement const { offsetHeight, scrollHeight, scrollTop } = scrollElement
prevScrollHeight = scrollHeight prevScrollHeight = scrollHeight
isScrollAtBottom = scrollHeight === scrollTop + offsetHeight isScrollAtBottom = scrollHeight <= Math.ceil(scrollTop + offsetHeight)
} }
beforeUpdate(() => { beforeUpdate(() => {

View File

@ -461,6 +461,12 @@ async function activityInboxNotificationToText (doc: Data<ActivityInboxNotificat
if (doc.body != null) { if (doc.body != null) {
body = await translate(doc.body, params) body = await translate(doc.body, params)
} }
// TODO: temporary log to understand problem. Remove it later.
if (doc.body === 'chunter:string:MessageNotificationBody') {
console.error('Cannot translate chunter notification: ', { doc, params })
}
return [title, body] return [title, body]
} }

View File

@ -41,7 +41,7 @@ import serverNotification, {
NotificationPresenter, NotificationPresenter,
TextPresenter TextPresenter
} from '@hcengineering/server-notification' } from '@hcengineering/server-notification'
import { getResource, IntlString } 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 { NotifyResult } from './types' import { NotifyResult } from './types'
@ -98,14 +98,6 @@ function escapeRegExp (str: string): string {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
} }
async function findPersonForAccount (control: TriggerControl, personId: Ref<Person>): Promise<Person | undefined> {
const persons = await control.findAll(contact.class.Person, { _id: personId })
if (persons !== undefined && persons.length > 0) {
return persons[0]
}
return undefined
}
export async function shouldNotifyCommon ( export async function shouldNotifyCommon (
control: TriggerControl, control: TriggerControl,
user: Ref<Account>, user: Ref<Account>,
@ -323,18 +315,27 @@ async function getFallbackNotificationFullfillment (
intlParams.title = await textPresenterFunc(object, control) intlParams.title = await textPresenterFunc(object, control)
} }
const account = control.modelDb.getObject(originTx.modifiedBy) as PersonAccount const tx = TxProcessor.extractTx(originTx)
const account = control.modelDb.getObject(tx.modifiedBy) as PersonAccount
if (account !== undefined) { if (account !== undefined) {
const senderPerson = (cache.get(account.person) as Person) ?? (await findPersonForAccount(control, account.person)) const person =
if (senderPerson !== undefined) { (cache.get(account.person) as Person) ?? (await control.findAll(contact.class.Person, { _id: account.person }))[0]
intlParams.senderName = formatName(senderPerson.name, control.branding?.lastNameFirst) if (person !== undefined) {
cache.set(senderPerson._id, senderPerson) 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)
} }
const actualTx = TxProcessor.extractTx(originTx) intlParams.senderName = intlParams.senderName ?? ''
if (actualTx._class === core.class.TxUpdateDoc) {
const updateTx = actualTx as TxUpdateDoc<Doc> if (tx._class === core.class.TxUpdateDoc) {
const updateTx = tx as TxUpdateDoc<Doc>
const attributes = control.hierarchy.getAllAttributes(object._class) const attributes = control.hierarchy.getAllAttributes(object._class)
for (const attrName in updateTx.operations) { for (const attrName in updateTx.operations) {
if (!Object.prototype.hasOwnProperty.call(updateTx.operations, attrName)) { if (!Object.prototype.hasOwnProperty.call(updateTx.operations, attrName)) {