From 906f741d4bf6663ea5e2935dc1214e9851e3ab13 Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Fri, 4 Mar 2022 15:09:01 +0600 Subject: [PATCH] Gmail attachments (#1095) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- models/gmail/package.json | 1 + models/gmail/src/index.ts | 44 ++++- models/gmail/src/plugin.ts | 1 + .../src/components/AttachmentRefInput.svelte | 2 +- plugins/attachment-resources/src/index.ts | 2 +- plugins/gmail-assets/lang/en.json | 1 + plugins/gmail-assets/lang/ru.json | 1 + plugins/gmail-resources/package.json | 2 + .../src/components/FullMessage.svelte | 40 ++++- .../src/components/Message.svelte | 6 +- .../src/components/NewMessage.svelte | 165 ++++++++++++++---- plugins/gmail/src/index.ts | 14 +- 12 files changed, 232 insertions(+), 47 deletions(-) diff --git a/models/gmail/package.json b/models/gmail/package.json index 89cc376a85..2662d7219f 100644 --- a/models/gmail/package.json +++ b/models/gmail/package.json @@ -33,6 +33,7 @@ "@anticrm/model-contact": "~0.6.1", "@anticrm/gmail": "~0.6.0", "@anticrm/gmail-resources": "~0.6.0", + "@anticrm/model-attachment": "~0.6.0", "@anticrm/setting": "~0.6.0", "@anticrm/ui": "~0.6.0" } diff --git a/models/gmail/src/index.ts b/models/gmail/src/index.ts index 5c8e6393b1..9b88c0c3f8 100644 --- a/models/gmail/src/index.ts +++ b/models/gmail/src/index.ts @@ -16,10 +16,11 @@ import activity from '@anticrm/activity' import { Domain, IndexKind, Type } from '@anticrm/core' -import type { Message, SharedMessage, SharedMessages } from '@anticrm/gmail' -import { ArrOf, Builder, Index, Model, Prop, TypeBoolean, TypeString } from '@anticrm/model' +import type { Message, NewMessage, SharedMessage, SharedMessages } from '@anticrm/gmail' +import { ArrOf, Builder, Collection, Index, Model, Prop, TypeBoolean, TypeString } from '@anticrm/model' import contact from '@anticrm/model-contact' -import core, { TAttachedDoc } from '@anticrm/model-core' +import core, { TDoc, TAttachedDoc } from '@anticrm/model-core' +import attachment from '@anticrm/model-attachment' import setting from '@anticrm/setting' import gmail from './plugin' @@ -46,10 +47,6 @@ export class TMessage extends TAttachedDoc implements Message { @Index(IndexKind.FullText) to!: string - @Prop(TypeString(), contact.string.Contact) - @Index(IndexKind.FullText) - contact!: string - @Prop(TypeString(), gmail.string.Subject) @Index(IndexKind.FullText) subject!: string @@ -67,6 +64,37 @@ export class TMessage extends TAttachedDoc implements Message { @Prop(TypeBoolean(), gmail.string.Incoming) incoming!: boolean + + @Prop(Collection(attachment.class.Attachment), attachment.string.Attachments) + attachments?: number +} + +@Model(gmail.class.NewMessage, core.class.Doc, DOMAIN_GMAIL) +export class TNewMessage extends TDoc implements NewMessage { + @Prop(TypeString(), gmail.string.ReplyTo) + @Index(IndexKind.FullText) + replyTo?: string + + @Prop(TypeString(), gmail.string.To) + @Index(IndexKind.FullText) + to!: string + + @Prop(TypeString(), gmail.string.Subject) + @Index(IndexKind.FullText) + subject!: string + + @Prop(TypeString(), gmail.string.Message) + @Index(IndexKind.FullText) + content!: string + + @Prop(TypeString(), gmail.string.Status) + status!: 'new' | 'sent' + + @Prop(ArrOf(TypeString()), gmail.string.Copy) + copy?: string[] + + @Prop(Collection(attachment.class.Attachment), attachment.string.Attachments) + attachments?: number } @Model(gmail.class.SharedMessages, core.class.AttachedDoc, DOMAIN_GMAIL) @@ -76,7 +104,7 @@ export class TSharedMessages extends TAttachedDoc implements SharedMessages { } export function createModel (builder: Builder): void { - builder.createModel(TMessage, TSharedMessages) + builder.createModel(TMessage, TSharedMessages, TNewMessage) builder.createDoc( contact.class.ChannelProvider, diff --git a/models/gmail/src/plugin.ts b/models/gmail/src/plugin.ts index b0f3969a0c..64ee7be07d 100644 --- a/models/gmail/src/plugin.ts +++ b/models/gmail/src/plugin.ts @@ -33,6 +33,7 @@ export default mergeIds(gmailId, gmail, { Messages: '' as IntlString, Incoming: '' as IntlString, Email: '' as IntlString, + Status: '' as IntlString, EmailPlaceholder: '' as IntlString }, ids: { diff --git a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte index d1397507b1..dc5f14af14 100644 --- a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte +++ b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte @@ -24,7 +24,7 @@ import { Attachment } from '@anticrm/attachment' import AttachmentPresenter from './AttachmentPresenter.svelte' import { IconClose } from '@anticrm/ui' -import ActionIcon from '@anticrm/ui/src/components/ActionIcon.svelte'; + import { ActionIcon } from '@anticrm/ui' export let objectId: Ref export let space: Ref diff --git a/plugins/attachment-resources/src/index.ts b/plugins/attachment-resources/src/index.ts index eee6da65e9..82554a6bb3 100644 --- a/plugins/attachment-resources/src/index.ts +++ b/plugins/attachment-resources/src/index.ts @@ -24,7 +24,7 @@ import Photos from './components/Photos.svelte' import { Resources } from '@anticrm/platform' import { uploadFile, deleteFile } from './utils' -export { Attachments, AttachmentsPresenter, AttachmentRefInput, AttachmentList, AttachmentDocList } +export { Attachments, AttachmentsPresenter, AttachmentPresenter, AttachmentRefInput, AttachmentList, AttachmentDocList } export default async (): Promise => ({ component: { diff --git a/plugins/gmail-assets/lang/en.json b/plugins/gmail-assets/lang/en.json index 013ea7594c..bf9804dc0d 100644 --- a/plugins/gmail-assets/lang/en.json +++ b/plugins/gmail-assets/lang/en.json @@ -27,6 +27,7 @@ "Messages": "Messages", "Incoming": "Incoming", "Email": "Email", + "Status": "Status", "EmailPlaceholder": "john.appleseed@apple.com" } } \ No newline at end of file diff --git a/plugins/gmail-assets/lang/ru.json b/plugins/gmail-assets/lang/ru.json index 71fc1f954e..71759e8572 100644 --- a/plugins/gmail-assets/lang/ru.json +++ b/plugins/gmail-assets/lang/ru.json @@ -27,6 +27,7 @@ "Messages": "Сообщения", "Incoming": "Входящие", "Email": "Email", + "Status": "Статус", "EmailPlaceholder": "john.appleseed@apple.com" } } \ No newline at end of file diff --git a/plugins/gmail-resources/package.json b/plugins/gmail-resources/package.json index df5fddc4f0..fad00863b2 100644 --- a/plugins/gmail-resources/package.json +++ b/plugins/gmail-resources/package.json @@ -42,6 +42,8 @@ "@anticrm/chunter": "~0.6.0", "@anticrm/chunter-resources": "~0.6.0", "@anticrm/notification-resources": "~0.6.0", + "@anticrm/attachment": "~0.6.0", + "@anticrm/attachment-resources": "~0.6.0", "@anticrm/login": "~0.6.1", "@anticrm/core": "~0.6.11" } diff --git a/plugins/gmail-resources/src/components/FullMessage.svelte b/plugins/gmail-resources/src/components/FullMessage.svelte index 58b0ef6e49..cb222d0153 100644 --- a/plugins/gmail-resources/src/components/FullMessage.svelte +++ b/plugins/gmail-resources/src/components/FullMessage.svelte @@ -20,6 +20,9 @@ import { IconArrowLeft, Label } from '@anticrm/ui' import gmail from '../plugin' import FullMessageContent from './FullMessageContent.svelte' + import { createQuery } from '@anticrm/presentation' + import attachment, { Attachment } from '@anticrm/attachment' + import { AttachmentPresenter } from '@anticrm/attachment-resources' export let currentMessage: SharedMessage export let newMessage: boolean @@ -29,6 +32,13 @@ const dispatch = createEventDispatcher() + const query = createQuery() + let attachments: Attachment[] = [] + + $: currentMessage._id && query.query(attachment.class.Attachment, { + attachedTo: currentMessage._id + }, (res) => attachments = res) + $: title = currentMessage.incoming ? currentMessage.sender : currentMessage.receiver $: user = currentMessage.incoming ? currentMessage.receiver : currentMessage.sender @@ -60,13 +70,22 @@ /> -
+