mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-28 22:13:29 +03:00
Allow users to create direct with themselves (#5534)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
db16524e1f
commit
5584f2702b
@ -114,7 +114,7 @@
|
|||||||
SelectUsersPopup,
|
SelectUsersPopup,
|
||||||
{
|
{
|
||||||
okLabel: presentation.string.Next,
|
okLabel: presentation.string.Next,
|
||||||
skipCurrentAccount: true,
|
skipCurrentAccount: false,
|
||||||
selected: employeeIds,
|
selected: employeeIds,
|
||||||
showStatus: true
|
showStatus: true
|
||||||
},
|
},
|
||||||
|
@ -13,19 +13,19 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
import { type Channel, type ChatMessage, type DirectMessage, type ThreadMessage } from '@hcengineering/chunter'
|
import { type Channel, type ChatMessage, type DirectMessage, type ThreadMessage } from '@hcengineering/chunter'
|
||||||
import contact, { type Employee, type PersonAccount, getName, type Person } from '@hcengineering/contact'
|
import contact, { type Employee, getName, type Person, type PersonAccount } from '@hcengineering/contact'
|
||||||
import { employeeByIdStore, PersonIcon } from '@hcengineering/contact-resources'
|
import { employeeByIdStore, PersonIcon } from '@hcengineering/contact-resources'
|
||||||
import {
|
import {
|
||||||
|
type Account,
|
||||||
|
type Class,
|
||||||
type Client,
|
type Client,
|
||||||
type Doc,
|
type Doc,
|
||||||
|
generateId,
|
||||||
getCurrentAccount,
|
getCurrentAccount,
|
||||||
type IdMap,
|
type IdMap,
|
||||||
type Ref,
|
type Ref,
|
||||||
type Space,
|
type Space,
|
||||||
type Class,
|
type Timestamp
|
||||||
type Timestamp,
|
|
||||||
type Account,
|
|
||||||
generateId
|
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import { getClient } from '@hcengineering/presentation'
|
import { getClient } from '@hcengineering/presentation'
|
||||||
import { type AnySvelteComponent } from '@hcengineering/ui'
|
import { type AnySvelteComponent } from '@hcengineering/ui'
|
||||||
@ -82,6 +82,8 @@ export async function buildDmName (client: Client, employeeAccounts: PersonAccou
|
|||||||
const names: string[] = []
|
const names: string[] = []
|
||||||
const processedPersons: Array<Ref<Person>> = []
|
const processedPersons: Array<Ref<Person>> = []
|
||||||
|
|
||||||
|
let myName = ''
|
||||||
|
|
||||||
for (const acc of employeeAccounts) {
|
for (const acc of employeeAccounts) {
|
||||||
if (processedPersons.includes(acc.person)) {
|
if (processedPersons.includes(acc.person)) {
|
||||||
continue
|
continue
|
||||||
@ -89,12 +91,20 @@ export async function buildDmName (client: Client, employeeAccounts: PersonAccou
|
|||||||
|
|
||||||
const employee = map.get(acc.person as unknown as Ref<Employee>)
|
const employee = map.get(acc.person as unknown as Ref<Employee>)
|
||||||
|
|
||||||
if (employee !== undefined && me.person !== employee._id) {
|
if (employee === undefined) {
|
||||||
names.push(getName(client.getHierarchy(), employee))
|
continue
|
||||||
processedPersons.push(acc.person)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (me.person === employee._id) {
|
||||||
|
myName = getName(client.getHierarchy(), employee)
|
||||||
|
processedPersons.push(acc.person)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
names.push(getName(client.getHierarchy(), employee))
|
||||||
|
processedPersons.push(acc.person)
|
||||||
}
|
}
|
||||||
return names.join(', ')
|
return names.length > 0 ? names.join(', ') : myName
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dmIdentifierProvider (): Promise<string> {
|
export async function dmIdentifierProvider (): Promise<string> {
|
||||||
@ -146,13 +156,9 @@ async function getDmAccounts (client: Client, space?: Space): Promise<PersonAcco
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const myAccId = getCurrentAccount()._id
|
return await client.findAll(contact.class.PersonAccount, {
|
||||||
|
|
||||||
const employeeAccounts: PersonAccount[] = await client.findAll(contact.class.PersonAccount, {
|
|
||||||
_id: { $in: (space.members ?? []) as Array<Ref<PersonAccount>> }
|
_id: { $in: (space.members ?? []) as Array<Ref<PersonAccount>> }
|
||||||
})
|
})
|
||||||
|
|
||||||
return employeeAccounts.filter((p) => p._id !== myAccId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDmPersons (client: Client, space: Space): Promise<Person[]> {
|
export async function getDmPersons (client: Client, space: Space): Promise<Person[]> {
|
||||||
@ -161,15 +167,27 @@ export async function getDmPersons (client: Client, space: Space): Promise<Perso
|
|||||||
const persons: Person[] = []
|
const persons: Person[] = []
|
||||||
|
|
||||||
const personRefs = new Set(personAccounts.map(({ person }) => person))
|
const personRefs = new Set(personAccounts.map(({ person }) => person))
|
||||||
|
let myPerson: Person | undefined
|
||||||
|
|
||||||
for (const personRef of personRefs) {
|
for (const personRef of personRefs) {
|
||||||
const person = await client.findOne(contact.class.Person, { _id: personRef })
|
const person = await client.findOne(contact.class.Person, { _id: personRef })
|
||||||
if (person !== undefined && me.person !== person._id) {
|
if (person === undefined) {
|
||||||
persons.push(person)
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (me.person === person._id) {
|
||||||
|
myPerson = person
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
persons.push(person)
|
||||||
}
|
}
|
||||||
|
|
||||||
return persons
|
if (persons.length > 0) {
|
||||||
|
return persons
|
||||||
|
}
|
||||||
|
|
||||||
|
return myPerson !== undefined ? [myPerson] : []
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function DirectTitleProvider (client: Client, id: Ref<DirectMessage>): Promise<string> {
|
export async function DirectTitleProvider (client: Client, id: Ref<DirectMessage>): Promise<string> {
|
||||||
|
Loading…
Reference in New Issue
Block a user