diff --git a/models/gmail/src/index.ts b/models/gmail/src/index.ts index f32bdb851a..e5de37889d 100644 --- a/models/gmail/src/index.ts +++ b/models/gmail/src/index.ts @@ -15,8 +15,8 @@ // import type { IntlString } from '@anticrm/platform' -import { Builder, Model, TypeString, Prop, ArrOf } from '@anticrm/model' -import core, { TAttachedDoc, TDoc } from '@anticrm/model-core' +import { Builder, Model, TypeString, Prop, ArrOf, TypeBoolean } from '@anticrm/model' +import core, { TAttachedDoc } from '@anticrm/model-core' import contact from '@anticrm/model-contact' import gmail from './plugin' import type { Message, SharedMessage, SharedMessages } from '@anticrm/gmail' @@ -30,8 +30,8 @@ function TypeSharedMessage (): Type<SharedMessage> { return { _class: gmail.class.SharedMessage, label: 'Shared message' as IntlString } } -@Model(gmail.class.Message, core.class.Doc, DOMAIN_GMAIL) -export class TMessage extends TDoc implements Message { +@Model(gmail.class.Message, core.class.AttachedDoc, DOMAIN_GMAIL) +export class TMessage extends TAttachedDoc implements Message { @Prop(TypeString(), gmail.string.MessageID) messageId!: string @@ -58,6 +58,9 @@ export class TMessage extends TDoc implements Message { @Prop(ArrOf(TypeString()), 'Copy' as IntlString) copy?: string[] + + @Prop(TypeBoolean(), 'Incoming' as IntlString) + incoming!: boolean } @Model(gmail.class.SharedMessages, core.class.AttachedDoc, DOMAIN_GMAIL) diff --git a/plugins/gmail-resources/src/components/Chats.svelte b/plugins/gmail-resources/src/components/Chats.svelte index 1b5b6d36ce..aed4160a47 100644 --- a/plugins/gmail-resources/src/components/Chats.svelte +++ b/plugins/gmail-resources/src/components/Chats.svelte @@ -18,7 +18,7 @@ import { createQuery, getClient } from '@anticrm/presentation' import { Message, SharedMessage } from '@anticrm/gmail' import gmail from '../plugin' - import { Contact, EmployeeAccount, formatName } from '@anticrm/contact' + import { Channel, Contact, EmployeeAccount, formatName } from '@anticrm/contact' import contact from '@anticrm/contact' import { ActionIcon, IconShare, Button, ScrollBox, showPopup, Icon, Label } from '@anticrm/ui' import { getCurrentAccount, Ref, SortingOrder, Space } from '@anticrm/core' @@ -27,7 +27,7 @@ import Messages from './Messages.svelte' export let object: Contact - export let contactString: string + export let channel: Channel export let newMessage: boolean let messages: Message[] = [] @@ -44,9 +44,9 @@ $: messagesQuery.query( gmail.class.Message, - { modifiedBy: accountId, contact: { $like: '%' + contactString + '%' } }, + { modifiedBy: accountId, attachedTo: channel._id }, (res) => { - // messages = res + messages = res }, { sort: { modifiedOn: SortingOrder.Descending } } ) @@ -59,15 +59,15 @@ setting.class.Integration, { type: gmail.integrationType.Gmail, space: accountId as string as Ref<Space> }, (res) => { - // enabled = res.length > 0 - // me = res[0].value + enabled = res.length > 0 + me = res[0].value } ) const client = getClient() async function share (): Promise<void> { const selectedMessages = messages.filter((m) => selected.has(m._id as string as Ref<SharedMessage>)) - await client.addCollection(gmail.class.SharedMessages, object.space, object._id, object._class, 'gmailMessages', { + await client.addCollection(gmail.class.SharedMessages, object.space, object._id, object._class, 'gmailSharedMessages', { messages: convertMessages(selectedMessages) }) clear() @@ -85,21 +85,16 @@ ...m, _id: m._id as string as Ref<SharedMessage>, sender: account ? getName(m, account, true) : '', - receiver: account ? getName(m, account, false) : '', - incoming: !amISender(m) + receiver: account ? getName(m, account, false) : '' } }) } function getName (message: Message, account: EmployeeAccount, sender: boolean): string { - return amISender(message) !== sender - ? `${formatName(object.name)} (${contactString})` + return message.incoming === sender + ? `${formatName(object.name)} (${channel.value})` : `${formatName(account.name)} (${me})` } - - function amISender (message: Message): boolean { - return !message.from.includes(contactString) - } </script> <div class="flex-between header"> diff --git a/plugins/gmail-resources/src/components/Main.svelte b/plugins/gmail-resources/src/components/Main.svelte index 2e6444fe88..dfcd308cb3 100644 --- a/plugins/gmail-resources/src/components/Main.svelte +++ b/plugins/gmail-resources/src/components/Main.svelte @@ -24,14 +24,14 @@ export let object: Contact let newMessage: boolean = false let currentMessage: SharedMessage | undefined = undefined - let channelValue: string | undefined = undefined + let channel: Channel | undefined = undefined const client = getClient() client.findOne(contact.class.Channel, { attachedTo: object._id, provider: contact.channelProvider.Email - }).then((res) => channelValue = res?.value) + }).then((res) => channel = res) function back () { if (newMessage) { @@ -45,12 +45,12 @@ } </script> -{#if channelValue} +{#if channel} {#if newMessage} - <NewMessage {object} contact={channelValue} {currentMessage} on:close={back} /> + <NewMessage {object} {channel} {currentMessage} on:close={back} /> {:else if currentMessage} <FullMessage {currentMessage} bind:newMessage on:close={back} /> {:else} - <Chats {object} contactString={channelValue} bind:newMessage on:select={selectHandler} /> + <Chats {object} {channel} bind:newMessage on:select={selectHandler} /> {/if} {/if} diff --git a/plugins/gmail-resources/src/components/NewMessage.svelte b/plugins/gmail-resources/src/components/NewMessage.svelte index 1e716da224..8858a3c9b2 100644 --- a/plugins/gmail-resources/src/components/NewMessage.svelte +++ b/plugins/gmail-resources/src/components/NewMessage.svelte @@ -21,12 +21,12 @@ import Button from '@anticrm/ui/src/components/Button.svelte' import { createEventDispatcher } from 'svelte' import { IconArrowLeft, Label } from '@anticrm/ui' - import { Contact, formatName } from '@anticrm/contact' + import { Channel, Contact, formatName } from '@anticrm/contact' import { TextEditor } from '@anticrm/text-editor' import plugin from '../plugin' export let object: Contact - export let contact: string + export let channel: Channel export let currentMessage: SharedMessage | undefined let editor: TextEditor @@ -35,7 +35,7 @@ const obj: NewMessage = { subject: currentMessage ? 'RE: ' + currentMessage.subject : '', content: '', - to: contact, + to: channel.value, replyTo: currentMessage?.messageId } @@ -72,7 +72,7 @@ <div class="fs-title">Gmail</div> <div class="small-text content-dark-color overflow-label"> <Label label={plugin.string.NewMessageTo} /> - <span class="content-accent-color">{formatName(object.name)} ({contact})</span> + <span class="content-accent-color">{formatName(object.name)} ({channel.value})</span> </div> </div> <div class="mr-3"> diff --git a/plugins/gmail/src/index.ts b/plugins/gmail/src/index.ts index f1e2498636..515b2f6e15 100644 --- a/plugins/gmail/src/index.ts +++ b/plugins/gmail/src/index.ts @@ -22,11 +22,11 @@ import type { IntegrationType, Handler } from '@anticrm/setting' /** * @public */ -export interface Message extends NewMessage, Doc { +export interface Message extends NewMessage, AttachedDoc { messageId: string from: string textContent: string - contact: string + incoming: boolean } /**