Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions packages/presentation/src/pulse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
34 changes: 18 additions & 16 deletions packages/ui/src/components/internal/RootBarExtension.svelte
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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}
28 changes: 14 additions & 14 deletions plugins/chunter-resources/src/components/ChannelTypingInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -26,7 +26,6 @@

const maxTypingPersons = 3
const acc = getCurrentAccount()
const client = getClient()
const hierarchy = getClient().getHierarchy()

interface TypingGroup {
Expand Down Expand Up @@ -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)

groups.push({
status,
names: displayNames,
count: names.length,
moreCount
})
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.sort((a, b) => a.status.localeCompare(b.status))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -28,7 +28,6 @@

const maxTypingPersons = 3
const acc = getCurrentAccount()
const client = getClient()
const hierarchy = getClient().getHierarchy()

interface TypingGroup {
Expand Down Expand Up @@ -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)

groups.push({
status,
names: displayNames,
count: names.length,
moreCount
})
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.sort((a, b) => a.status.localeCompare(b.status))
Expand Down
Loading