Attached gmail (depends from #883) (#892)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-02-01 15:01:59 +06:00 committed by GitHub
parent 51b0cdb5f4
commit 7cbbb0a919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 30 deletions

View File

@ -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)

View File

@ -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">

View File

@ -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}

View File

@ -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">

View File

@ -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
}
/**