mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-02 14:29:03 +02:00
fix pulse issues (#10144)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -15,24 +15,50 @@ import { HulypulseClient } from '@hcengineering/hulypulse-client'
|
||||
import { getMetadata } from '@hcengineering/platform'
|
||||
import presentation from './plugin'
|
||||
|
||||
let pulseClient: HulypulseClient | undefined
|
||||
let currentWorkspaceUuid: string | undefined
|
||||
let currentToken: string | undefined
|
||||
let promise: Promise<HulypulseClient | undefined> | undefined
|
||||
|
||||
export async function createPulseClient (): Promise<HulypulseClient | undefined> {
|
||||
const token = getMetadata(presentation.metadata.Token)
|
||||
if (token !== currentToken) {
|
||||
const pulseUrl = getMetadata(presentation.metadata.PulseUrl) ?? ''
|
||||
const token = getMetadata(presentation.metadata.Token) ?? ''
|
||||
const workspaceUuid = getMetadata(presentation.metadata.WorkspaceUuid) ?? ''
|
||||
|
||||
if (pulseUrl === '' || token === '' || workspaceUuid === '') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// Token or workspace changed, need to reconnect
|
||||
if (token !== currentToken || workspaceUuid !== currentWorkspaceUuid) {
|
||||
closePulseClient()
|
||||
}
|
||||
if (pulseClient === undefined) {
|
||||
const wsPulseUrl = getMetadata(presentation.metadata.PulseUrl)
|
||||
if (wsPulseUrl == null || wsPulseUrl.trim().length === 0) return undefined
|
||||
pulseClient = await HulypulseClient.connect(`${wsPulseUrl}?token=${token}`)
|
||||
currentToken = token
|
||||
|
||||
if (promise !== undefined) {
|
||||
// eslint-disable-next-line @typescript-eslint/return-await
|
||||
return promise
|
||||
}
|
||||
return pulseClient
|
||||
|
||||
promise = new Promise((resolve) => {
|
||||
HulypulseClient.connect(`${pulseUrl}?token=${token}`)
|
||||
.then(resolve)
|
||||
.catch(() => {
|
||||
resolve(undefined)
|
||||
})
|
||||
})
|
||||
currentToken = token
|
||||
currentWorkspaceUuid = workspaceUuid
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/return-await
|
||||
return promise
|
||||
}
|
||||
|
||||
export function closePulseClient (): void {
|
||||
pulseClient?.close()
|
||||
pulseClient = undefined
|
||||
if (promise !== undefined) {
|
||||
void promise.then((client) => {
|
||||
client?.close()
|
||||
})
|
||||
}
|
||||
promise = undefined
|
||||
currentToken = undefined
|
||||
currentWorkspaceUuid = undefined
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { location as locationStore } from '../../location'
|
||||
import { location as locationStore, workspaceId } from '../../location'
|
||||
import { rootBarExtensions } from '../../utils'
|
||||
import Component from '../Component.svelte'
|
||||
|
||||
@@ -15,18 +15,20 @@
|
||||
$: sorted = $rootBarExtensions.sort((a, b) => a[1].order - b[1].order)
|
||||
</script>
|
||||
|
||||
{#each sorted as ext (ext[1].id)}
|
||||
{#if ext[0] === position}
|
||||
<div id={ext[1].id} class="clear-mins">
|
||||
<Component
|
||||
is={ext[1].component}
|
||||
props={ext[1].props}
|
||||
on:close={() => {
|
||||
rootBarExtensions.update((cur) => {
|
||||
return cur.filter((it) => it[1].id !== ext[1].id)
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
{#key $workspaceId}
|
||||
{#each sorted as ext (ext[1].id)}
|
||||
{#if ext[0] === position}
|
||||
<div id={ext[1].id} class="clear-mins">
|
||||
<Component
|
||||
is={ext[1].component}
|
||||
props={ext[1].props}
|
||||
on:close={() => {
|
||||
rootBarExtensions.update((cur) => {
|
||||
return cur.filter((it) => it[1].id !== ext[1].id)
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
{/key}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
<script lang="ts">
|
||||
import chunter from '@hcengineering/chunter'
|
||||
import { type Doc, type PersonId, getCurrentAccount } from '@hcengineering/core'
|
||||
import { getName, getPersonRefsBySocialIds } from '@hcengineering/contact'
|
||||
import { getPersonsByPersonRefs } from '@hcengineering/contact-resources'
|
||||
import { getName } from '@hcengineering/contact'
|
||||
import { getPersonsByPersonIds } from '@hcengineering/contact-resources'
|
||||
import { IntlString } from '@hcengineering/platform'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { Label } from '@hcengineering/ui'
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
const maxTypingPersons = 3
|
||||
const acc = getCurrentAccount()
|
||||
const client = getClient()
|
||||
const hierarchy = getClient().getHierarchy()
|
||||
|
||||
interface TypingGroup {
|
||||
@@ -58,21 +57,22 @@
|
||||
const groups: TypingGroup[] = []
|
||||
|
||||
for (const [status, personIds] of groupedByStatus.entries()) {
|
||||
const personRefs = await getPersonRefsBySocialIds(client, personIds)
|
||||
const persons = await getPersonsByPersonRefs(Object.values(personRefs))
|
||||
const persons = await getPersonsByPersonIds(personIds)
|
||||
const names = Array.from(persons.values())
|
||||
.map((person) => getName(hierarchy, person))
|
||||
.sort((name1, name2) => name1.localeCompare(name2))
|
||||
|
||||
const displayNames = names.slice(0, maxTypingPersons).join(', ')
|
||||
const moreCount = Math.max(names.length - maxTypingPersons, 0)
|
||||
if (names.length > 0) {
|
||||
const displayNames = names.slice(0, maxTypingPersons).join(', ')
|
||||
const moreCount = Math.max(names.length - maxTypingPersons, 0)
|
||||
|
||||
groups.push({
|
||||
status,
|
||||
names: displayNames,
|
||||
count: names.length,
|
||||
moreCount
|
||||
})
|
||||
groups.push({
|
||||
status,
|
||||
names: displayNames,
|
||||
count: names.length,
|
||||
moreCount
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
groups.sort((a, b) => a.status.localeCompare(b.status))
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { type PersonId, getCurrentAccount } from '@hcengineering/core'
|
||||
import { getName, getPersonRefsBySocialIds } from '@hcengineering/contact'
|
||||
import { getPersonsByPersonRefs } from '@hcengineering/contact-resources'
|
||||
import { getName } from '@hcengineering/contact'
|
||||
import { getPersonsByPersonIds } from '@hcengineering/contact-resources'
|
||||
import { IntlString } from '@hcengineering/platform'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { Label } from '@hcengineering/ui'
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
const maxTypingPersons = 3
|
||||
const acc = getCurrentAccount()
|
||||
const client = getClient()
|
||||
const hierarchy = getClient().getHierarchy()
|
||||
|
||||
interface TypingGroup {
|
||||
@@ -60,21 +59,22 @@
|
||||
const groups: TypingGroup[] = []
|
||||
|
||||
for (const [status, personIds] of groupedByStatus.entries()) {
|
||||
const personRefs = await getPersonRefsBySocialIds(client, personIds)
|
||||
const persons = await getPersonsByPersonRefs(Object.values(personRefs))
|
||||
const persons = await getPersonsByPersonIds(personIds)
|
||||
const names = Array.from(persons.values())
|
||||
.map((person) => getName(hierarchy, person))
|
||||
.sort((name1, name2) => name1.localeCompare(name2))
|
||||
|
||||
const displayNames = names.slice(0, maxTypingPersons).join(', ')
|
||||
const moreCount = Math.max(names.length - maxTypingPersons, 0)
|
||||
if (names.length > 0) {
|
||||
const displayNames = names.slice(0, maxTypingPersons).join(', ')
|
||||
const moreCount = Math.max(names.length - maxTypingPersons, 0)
|
||||
|
||||
groups.push({
|
||||
status,
|
||||
names: displayNames,
|
||||
count: names.length,
|
||||
moreCount
|
||||
})
|
||||
groups.push({
|
||||
status,
|
||||
names: displayNames,
|
||||
count: names.length,
|
||||
moreCount
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
groups.sort((a, b) => a.status.localeCompare(b.status))
|
||||
|
||||
Reference in New Issue
Block a user