diff --git a/plugins/contact-resources/src/components/ChannelsEditor.svelte b/plugins/contact-resources/src/components/ChannelsEditor.svelte index 1bb113d8a1..8cc9f2a6be 100644 --- a/plugins/contact-resources/src/components/ChannelsEditor.svelte +++ b/plugins/contact-resources/src/components/ChannelsEditor.svelte @@ -77,7 +77,7 @@ if (ev.detail.presenter !== undefined) { if (allowOpen) { closeTooltip() - showPopup(ev.detail.presenter, { _id: attachedTo, _class: attachedClass }, 'float') + showPopup(ev.detail.presenter, { channel: ev.detail.channel }, 'float') } } } diff --git a/plugins/contact-resources/src/components/ChannelsPresenter.svelte b/plugins/contact-resources/src/components/ChannelsPresenter.svelte index ccaad5f1fa..2835552b1d 100644 --- a/plugins/contact-resources/src/components/ChannelsPresenter.svelte +++ b/plugins/contact-resources/src/components/ChannelsPresenter.svelte @@ -31,11 +31,7 @@ async function _open (ev: CustomEvent): Promise<void> { if (ev.detail.presenter !== undefined && Array.isArray(value)) { - showPopup( - ev.detail.presenter, - { _id: ev.detail.channel.attachedTo, _class: ev.detail.channel.attachedToClass }, - 'float' - ) + showPopup(ev.detail.presenter, { channel: ev.detail.channel }, 'float') } if (ev.detail.action !== undefined && Array.isArray(value)) { const action = await getResource(ev.detail.action as ViewAction) diff --git a/plugins/gmail-resources/src/components/Main.svelte b/plugins/gmail-resources/src/components/Main.svelte index 76f9ff181c..a4055cb381 100644 --- a/plugins/gmail-resources/src/components/Main.svelte +++ b/plugins/gmail-resources/src/components/Main.svelte @@ -15,26 +15,25 @@ --> <script lang="ts"> import contact, { Channel, Contact, getName } from '@hcengineering/contact' - import { Class, getCurrentAccount, Ref } from '@hcengineering/core' + import { employeeByIdStore } from '@hcengineering/contact-resources' + import { getCurrentAccount } from '@hcengineering/core' import { Message, SharedMessage } from '@hcengineering/gmail' import { NotificationClientImpl } from '@hcengineering/notification-resources' import { getResource } from '@hcengineering/platform' import { createQuery } from '@hcengineering/presentation' import setting, { Integration } from '@hcengineering/setting' import templates, { TemplateDataProvider } from '@hcengineering/templates' - import { Button, eventToHTMLElement, Icon, Label, Panel, showPopup } from '@hcengineering/ui' + import { Button, Icon, Label, Panel, eventToHTMLElement, showPopup } from '@hcengineering/ui' import { createEventDispatcher, onDestroy } from 'svelte' import gmail from '../plugin' + import { convertMessage } from '../utils' import Chats from './Chats.svelte' import Connect from './Connect.svelte' import FullMessage from './FullMessage.svelte' import IntegrationSelector from './IntegrationSelector.svelte' import NewMessage from './NewMessage.svelte' - import { convertMessage } from '../utils' - import { employeeByIdStore } from '@hcengineering/contact-resources' - export let _id: Ref<Contact> - export let _class: Ref<Class<Contact>> + export let channel: Channel export let embedded = false export let message: Message | undefined = undefined @@ -42,34 +41,18 @@ let currentMessage: SharedMessage | undefined = undefined let newMessage: boolean = false - let channel: Channel | undefined = undefined const notificationClient = NotificationClientImpl.getClient() let integrations: Integration[] = [] let selectedIntegration: Integration | undefined = undefined - const channelQuery = createQuery() + notificationClient.forceRead(channel._id, channel._class) + const dispatch = createEventDispatcher() - $: channelQuery.query( - contact.class.Channel, - { - attachedTo: _id, - provider: contact.channelProvider.Email - }, - (res) => { - channel = res[0] - if (channel !== undefined) { - notificationClient.forceRead(channel._id, channel._class) - } - } - ) - const query = createQuery() - $: _id && - _class && - query.query(_class, { _id }, (result) => { - object = result[0] - }) + $: query.query(channel.attachedToClass, { _id: channel.attachedTo }, (result) => { + object = result[0] as Contact + }) function back () { if (newMessage) { diff --git a/plugins/telegram-resources/src/components/Chat.svelte b/plugins/telegram-resources/src/components/Chat.svelte index c03155471e..dc14bd9d72 100644 --- a/plugins/telegram-resources/src/components/Chat.svelte +++ b/plugins/telegram-resources/src/components/Chat.svelte @@ -24,7 +24,7 @@ getName as getContactName } from '@hcengineering/contact' import { Avatar, employeeAccountByIdStore, employeeByIdStore } from '@hcengineering/contact-resources' - import { Class, IdMap, Ref, SortingOrder, generateId, getCurrentAccount } from '@hcengineering/core' + import { IdMap, Ref, SortingOrder, generateId, getCurrentAccount } from '@hcengineering/core' import { NotificationClientImpl } from '@hcengineering/notification-resources' import { getEmbeddedLabel, getResource } from '@hcengineering/platform' import { createQuery, getClient } from '@hcengineering/presentation' @@ -49,30 +49,16 @@ import Reconnect from './Reconnect.svelte' import TelegramIcon from './icons/Telegram.svelte' - export let _id: Ref<Contact> - export let _class: Ref<Class<Contact>> + export let channel: Channel export let embedded = false let object: Contact - let channel: Channel | undefined = undefined let objectId: Ref<NewTelegramMessage> = generateId() const dispatch = createEventDispatcher() const client = getClient() const notificationClient = NotificationClientImpl.getClient() - const channelQuery = createQuery() - - $: channelQuery.query( - contact.class.Channel, - { - attachedTo: _id, - provider: contact.channelProvider.Telegram - }, - (res) => { - channel = res[0] - } - ) let templateProvider: TemplateDataProvider | undefined @@ -88,11 +74,9 @@ $: templateProvider && integration && templateProvider.set(setting.class.Integration, integration) const query = createQuery() - $: _id && - _class && - query.query(_class, { _id }, (result) => { - object = result[0] - }) + $: query.query(channel.attachedToClass, { _id: channel.attachedTo }, (result) => { + object = result[0] as Contact + }) let messages: TelegramMessage[] = [] let integration: Integration | undefined