2024-04-18 17:11:24 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { PersonAccount } from '@hcengineering/contact'
|
|
|
|
import { Avatar, personAccountByIdStore, personByIdStore } from '@hcengineering/contact-resources'
|
2024-09-24 12:31:34 +00:00
|
|
|
import { Class, Doc, Ref } from '@hcengineering/core'
|
2024-04-18 17:11:24 +00:00
|
|
|
import { BrowserNotification } from '@hcengineering/notification'
|
2024-09-18 02:27:13 +00:00
|
|
|
import { Button, navigate, Notification as PlatformNotification, NotificationToast } from '@hcengineering/ui'
|
2024-09-24 12:31:34 +00:00
|
|
|
import view from '@hcengineering/view'
|
|
|
|
import chunter, { ThreadMessage } from '@hcengineering/chunter'
|
2024-09-18 02:27:13 +00:00
|
|
|
import { getResource } from '@hcengineering/platform'
|
2024-09-24 12:31:34 +00:00
|
|
|
import activity, { ActivityMessage } from '@hcengineering/activity'
|
|
|
|
import { getClient } from '@hcengineering/presentation'
|
2024-09-18 02:27:13 +00:00
|
|
|
|
2024-04-18 17:11:24 +00:00
|
|
|
import { pushAvailable, subscribePush } from '../utils'
|
|
|
|
import plugin from '../plugin'
|
|
|
|
|
|
|
|
export let notification: PlatformNotification
|
|
|
|
export let onRemove: () => void
|
|
|
|
|
2024-09-24 12:31:34 +00:00
|
|
|
const client = getClient()
|
|
|
|
const hierarchy = client.getHierarchy()
|
|
|
|
|
2024-04-18 17:11:24 +00:00
|
|
|
$: value = notification.params?.value as BrowserNotification
|
|
|
|
|
|
|
|
$: senderAccount =
|
|
|
|
value.senderId !== undefined ? $personAccountByIdStore.get(value.senderId as Ref<PersonAccount>) : undefined
|
|
|
|
$: sender = senderAccount !== undefined ? $personByIdStore.get(senderAccount.person) : undefined
|
2024-09-18 02:27:13 +00:00
|
|
|
|
|
|
|
async function openChannelInSidebar (): Promise<void> {
|
|
|
|
if (!value.onClickLocation) return
|
|
|
|
const { onClickLocation } = value
|
2024-09-24 12:31:34 +00:00
|
|
|
let _id: Ref<Doc> | undefined = value.objectId
|
|
|
|
let _class: Ref<Class<Doc>> | undefined = value.objectClass
|
|
|
|
let thread = onClickLocation.path[4] as Ref<ActivityMessage> | undefined
|
|
|
|
const selectedMessageId: Ref<ActivityMessage> | undefined = value.messageId
|
|
|
|
|
|
|
|
if (_class && _id && hierarchy.isDerived(_class, activity.class.ActivityMessage)) {
|
|
|
|
const message = await client.findOne<ActivityMessage>(_class, { _id: _id as Ref<ActivityMessage> })
|
|
|
|
|
|
|
|
if (hierarchy.isDerived(_class, chunter.class.ThreadMessage)) {
|
|
|
|
const threadMessage = message as ThreadMessage
|
|
|
|
_id = threadMessage?.objectId
|
|
|
|
_class = threadMessage?.objectClass
|
|
|
|
thread = threadMessage?.attachedTo
|
|
|
|
} else {
|
|
|
|
_id = message?.attachedTo
|
|
|
|
_class = message?.attachedToClass
|
|
|
|
thread = (message?.replies ?? 0) > 0 ? message?._id : undefined
|
|
|
|
}
|
|
|
|
}
|
2024-09-18 02:27:13 +00:00
|
|
|
|
|
|
|
onRemove()
|
|
|
|
|
2024-09-24 12:31:34 +00:00
|
|
|
if (!_id || !_class || _id === '' || _class === '' || selectedMessageId === undefined) {
|
2024-09-18 02:27:13 +00:00
|
|
|
navigate(onClickLocation)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn = await getResource(chunter.function.OpenChannelInSidebar)
|
2024-09-24 12:31:34 +00:00
|
|
|
await fn(_id, _class, undefined, thread, true, selectedMessageId)
|
2024-09-18 02:27:13 +00:00
|
|
|
}
|
2024-04-18 17:11:24 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<NotificationToast title={notification.title} severity={notification.severity} onClose={onRemove}>
|
|
|
|
<svelte:fragment slot="content">
|
|
|
|
<div class="flex-row-center flex-wrap gap-2">
|
|
|
|
{#if sender}
|
2024-05-27 07:25:57 +00:00
|
|
|
<Avatar person={sender} name={sender.name} size={'small'} />
|
2024-04-18 17:11:24 +00:00
|
|
|
{/if}
|
|
|
|
<span class="overflow-label">
|
|
|
|
{value.body}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</svelte:fragment>
|
|
|
|
|
|
|
|
<svelte:fragment slot="buttons">
|
|
|
|
{#if value.onClickLocation}
|
|
|
|
<Button
|
|
|
|
label={view.string.Open}
|
|
|
|
on:click={() => {
|
2024-09-24 12:31:34 +00:00
|
|
|
void openChannelInSidebar()
|
2024-04-18 17:11:24 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
<Button
|
|
|
|
label={plugin.string.EnablePush}
|
|
|
|
disabled={!pushAvailable()}
|
|
|
|
showTooltip={!pushAvailable() ? { label: plugin.string.NotificationBlockedInBrowser } : undefined}
|
|
|
|
on:click={subscribePush}
|
|
|
|
/>
|
|
|
|
</svelte:fragment>
|
|
|
|
</NotificationToast>
|