Fix mentions and threads (#8309)

This commit is contained in:
Kristina 2025-03-21 16:48:54 +04:00 committed by GitHub
parent a343075411
commit e70c86f86f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 22 deletions

View File

@ -296,13 +296,15 @@ export function includesAny (members: PersonId[], ids: PersonId[]): boolean {
export async function getPersonBySocialKey (client: Client, socialKey: string): Promise<Person | undefined> { export async function getPersonBySocialKey (client: Client, socialKey: string): Promise<Person | undefined> {
const socialId = await client.findOne(contact.class.SocialIdentity, { key: socialKey }) const socialId = await client.findOne(contact.class.SocialIdentity, { key: socialKey })
if (socialId === undefined) return undefined
return await client.findOne(contact.class.Person, { _id: socialId?.attachedTo, _class: socialId?.attachedToClass }) return await client.findOne(contact.class.Person, { _id: socialId?.attachedTo, _class: socialId?.attachedToClass })
} }
export async function getPersonBySocialId (client: Client, socialIdString: PersonId): Promise<Person | undefined> { export async function getPersonBySocialId (client: Client, socialIdString: PersonId): Promise<Person | undefined> {
const socialId = await client.findOne(contact.class.SocialIdentity, { _id: socialIdString as SocialIdentityRef }) const socialId = await client.findOne(contact.class.SocialIdentity, { _id: socialIdString as SocialIdentityRef })
if (socialId === undefined) return undefined
return await client.findOne(contact.class.Person, { _id: socialId?.attachedTo, _class: socialId?.attachedToClass }) return await client.findOne(contact.class.Person, { _id: socialId?.attachedTo, _class: socialId?.attachedToClass })
} }

View File

@ -22,7 +22,6 @@ import core, {
Data, Data,
Doc, Doc,
generateId, generateId,
parseSocialIdString,
Hierarchy, Hierarchy,
Markup, Markup,
Ref, Ref,
@ -40,6 +39,7 @@ import core, {
AccountUuid AccountUuid
} from '@hcengineering/core' } from '@hcengineering/core'
import notification, { CommonInboxNotification, MentionInboxNotification } from '@hcengineering/notification' import notification, { CommonInboxNotification, MentionInboxNotification } from '@hcengineering/notification'
import { getPerson } from '@hcengineering/server-contact'
import { StorageAdapter, TriggerControl } from '@hcengineering/server-core' import { StorageAdapter, TriggerControl } from '@hcengineering/server-core'
import { import {
applyNotificationProviders, applyNotificationProviders,
@ -155,15 +155,11 @@ export async function getPersonNotificationTxes (
archived: false archived: false
} }
const { type, value } = parseSocialIdString(senderId) const senderPerson = await getPerson(control, senderId)
const senderSocialIds =
const senderSocialIds = await control.findAll(ctx, contact.class.SocialIdentity, { type, value }) senderPerson !== undefined
const senderSocialId = senderSocialIds[0] ? await control.findAll(ctx, contact.class.SocialIdentity, { attachedTo: senderPerson._id })
: []
const senderPerson =
senderId !== undefined
? (await control.findAll(ctx, contact.class.Person, { _id: senderSocialId.attachedTo }, { limit: 1 }))[0]
: undefined
const receiverSocialString = pickPrimarySocialId(receiverSocialStrings) const receiverSocialString = pickPrimarySocialId(receiverSocialStrings)
const receiverInfo = toReceiverInfo(control.hierarchy, { const receiverInfo = toReceiverInfo(control.hierarchy, {

View File

@ -137,7 +137,7 @@ async function OnThreadMessageCreated (originTx: TxCUD<Doc>, control: TriggerCon
const person = await getPerson(control, originTx.modifiedBy) const person = await getPerson(control, originTx.modifiedBy)
if (person === undefined) { if (person === undefined) {
return [] return [lastReplyTx]
} }
if ((message.repliedPersons ?? []).includes(person._id)) { if ((message.repliedPersons ?? []).includes(person._id)) {

View File

@ -14,7 +14,7 @@
// //
import { TriggerControl } from '@hcengineering/server-core' import { TriggerControl } from '@hcengineering/server-core'
import contact, { Employee, pickPrimarySocialId, SocialIdentityRef, type Person } from '@hcengineering/contact' import contact, { Employee, type Person, pickPrimarySocialId, SocialIdentityRef } from '@hcengineering/contact'
import { AccountUuid, parseSocialIdString, PersonId, type Ref, toIdMap } from '@hcengineering/core' import { AccountUuid, parseSocialIdString, PersonId, type Ref, toIdMap } from '@hcengineering/core'
export async function getCurrentPerson (control: TriggerControl): Promise<Person | undefined> { export async function getCurrentPerson (control: TriggerControl): Promise<Person | undefined> {
@ -25,14 +25,12 @@ export async function getCurrentPerson (control: TriggerControl): Promise<Person
return undefined return undefined
} }
const person = ( return (
await control.findAll(control.ctx, contact.class.Person, { await control.findAll(control.ctx, contact.class.Person, {
_id: socialIdentity.attachedTo, _id: socialIdentity.attachedTo,
_class: socialIdentity.attachedToClass _class: socialIdentity.attachedToClass
}) })
)[0] )[0]
return person
} }
export async function getSocialStrings (control: TriggerControl, person: Ref<Person>): Promise<PersonId[]> { export async function getSocialStrings (control: TriggerControl, person: Ref<Person>): Promise<PersonId[]> {
@ -119,7 +117,13 @@ export async function getEmployee (control: TriggerControl, personId: PersonId):
const socialId = ( const socialId = (
await control.findAll(control.ctx, contact.class.SocialIdentity, { _id: personId as SocialIdentityRef }) await control.findAll(control.ctx, contact.class.SocialIdentity, { _id: personId as SocialIdentityRef })
)[0] )[0]
const employee = (
if (socialId === undefined) {
control.ctx.error('Cannot find social id', { _id: personId })
return undefined
}
return (
await control.findAll( await control.findAll(
control.ctx, control.ctx,
contact.mixin.Employee, contact.mixin.Employee,
@ -127,8 +131,6 @@ export async function getEmployee (control: TriggerControl, personId: PersonId):
{ limit: 1 } { limit: 1 }
) )
)[0] )[0]
return employee
} }
export async function getEmployeeByAcc (control: TriggerControl, account: AccountUuid): Promise<Employee | undefined> { export async function getEmployeeByAcc (control: TriggerControl, account: AccountUuid): Promise<Employee | undefined> {
@ -136,11 +138,9 @@ export async function getEmployeeByAcc (control: TriggerControl, account: Accoun
} }
export async function getEmployees (control: TriggerControl, accounts: AccountUuid[]): Promise<Employee[]> { export async function getEmployees (control: TriggerControl, accounts: AccountUuid[]): Promise<Employee[]> {
const employees = await control.findAll(control.ctx, contact.mixin.Employee, { return await control.findAll(control.ctx, contact.mixin.Employee, {
personUuid: { $in: accounts } personUuid: { $in: accounts }
}) })
return employees
} }
export async function getEmployeesBySocialIds ( export async function getEmployeesBySocialIds (