From 5584f2702b089793305347936fd50ed46d70cccc Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 7 May 2024 19:03:23 +0400 Subject: [PATCH] Allow users to create direct with themselves (#5534) Signed-off-by: Kristina Fefelova --- .../chat/create/CreateDirectChat.svelte | 2 +- plugins/chunter-resources/src/utils.ts | 52 +++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/plugins/chunter-resources/src/components/chat/create/CreateDirectChat.svelte b/plugins/chunter-resources/src/components/chat/create/CreateDirectChat.svelte index fdfa5cda42..809adbd1df 100644 --- a/plugins/chunter-resources/src/components/chat/create/CreateDirectChat.svelte +++ b/plugins/chunter-resources/src/components/chat/create/CreateDirectChat.svelte @@ -114,7 +114,7 @@ SelectUsersPopup, { okLabel: presentation.string.Next, - skipCurrentAccount: true, + skipCurrentAccount: false, selected: employeeIds, showStatus: true }, diff --git a/plugins/chunter-resources/src/utils.ts b/plugins/chunter-resources/src/utils.ts index 96f267b4e0..15debdbe4d 100644 --- a/plugins/chunter-resources/src/utils.ts +++ b/plugins/chunter-resources/src/utils.ts @@ -13,19 +13,19 @@ // limitations under the License. // 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 { + type Account, + type Class, type Client, type Doc, + generateId, getCurrentAccount, type IdMap, type Ref, type Space, - type Class, - type Timestamp, - type Account, - generateId + type Timestamp } from '@hcengineering/core' import { getClient } from '@hcengineering/presentation' import { type AnySvelteComponent } from '@hcengineering/ui' @@ -82,6 +82,8 @@ export async function buildDmName (client: Client, employeeAccounts: PersonAccou const names: string[] = [] const processedPersons: Array> = [] + let myName = '' + for (const acc of employeeAccounts) { if (processedPersons.includes(acc.person)) { continue @@ -89,12 +91,20 @@ export async function buildDmName (client: Client, employeeAccounts: PersonAccou const employee = map.get(acc.person as unknown as Ref) - if (employee !== undefined && me.person !== employee._id) { - names.push(getName(client.getHierarchy(), employee)) - processedPersons.push(acc.person) + if (employee === undefined) { + continue } + + 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 { @@ -146,13 +156,9 @@ async function getDmAccounts (client: Client, space?: Space): Promise> } }) - - return employeeAccounts.filter((p) => p._id !== myAccId) } export async function getDmPersons (client: Client, space: Space): Promise { @@ -161,15 +167,27 @@ export async function getDmPersons (client: Client, space: Space): Promise person)) + let myPerson: Person | undefined for (const personRef of personRefs) { const person = await client.findOne(contact.class.Person, { _id: personRef }) - if (person !== undefined && me.person !== person._id) { - persons.push(person) + if (person === undefined) { + 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): Promise {