From ee4bbb055dad3c4ef1ea456b05b2d3aba345090c Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 28 Aug 2024 19:44:14 +0400 Subject: [PATCH] Fix email notification (#6425) Signed-off-by: Kristina Fefelova --- models/gmail/src/index.ts | 61 +------------- models/gmail/src/notification.ts | 82 +++++++++++++++++++ models/gmail/src/plugin.ts | 5 +- .../DocUpdateMessageObjectValue.svelte | 26 +++++- .../src/components/ChannelPanel.svelte | 5 +- plugins/gmail-resources/src/index.ts | 5 +- plugins/gmail-resources/src/utils.ts | 8 +- .../src/components/AttachedDocPanel.svelte | 2 +- 8 files changed, 125 insertions(+), 69 deletions(-) create mode 100644 models/gmail/src/notification.ts diff --git a/models/gmail/src/index.ts b/models/gmail/src/index.ts index 4801861cb4..6e02c0d38c 100644 --- a/models/gmail/src/index.ts +++ b/models/gmail/src/index.ts @@ -32,12 +32,11 @@ import { import attachment from '@hcengineering/model-attachment' import contact from '@hcengineering/model-contact' import core, { TAttachedDoc, TDoc } from '@hcengineering/model-core' -import notification from '@hcengineering/model-notification' import view, { createAction } from '@hcengineering/model-view' import setting from '@hcengineering/setting' -import love from '@hcengineering/model-love' import gmail from './plugin' +import { defineNotifications } from './notification' export { gmailId } from '@hcengineering/gmail' export { gmailOperation } from './migration' @@ -215,32 +214,6 @@ export function createModel (builder: Builder): void { gmail.action.WriteEmail ) - builder.createDoc( - notification.class.NotificationGroup, - core.space.Model, - { - label: gmail.string.Email, - icon: contact.icon.Email - }, - gmail.ids.EmailNotificationGroup - ) - - builder.createDoc( - notification.class.NotificationType, - core.space.Model, - { - label: gmail.string.NewMessage, - generated: false, - hidden: false, - txClasses: [core.class.TxCreateDoc], - objectClass: gmail.class.Message, - group: gmail.ids.EmailNotificationGroup, - allowedForAuthor: true, - defaultEnabled: false - }, - gmail.ids.EmailNotification - ) - builder.mixin(gmail.class.Message, core.class.Class, core.mixin.FullTextSearchContext, { parentPropagate: false }) @@ -259,35 +232,9 @@ export function createModel (builder: Builder): void { ] }) - builder.createDoc( - notification.class.NotificationProvider, - core.space.Model, - { - icon: contact.icon.Email, - label: gmail.string.Email, - description: gmail.string.EmailNotificationsDescription, - defaultEnabled: true, - canDisable: true, - depends: notification.providers.InboxNotificationProvider, - order: 300 - }, - gmail.providers.EmailNotificationProvider - ) - - builder.createDoc(notification.class.NotificationProviderDefaults, core.space.Model, { - provider: notification.providers.InboxNotificationProvider, - ignoredTypes: [], - enabledTypes: [gmail.ids.EmailNotification] + builder.mixin(gmail.class.Message, core.class.Class, view.mixin.ObjectTitle, { + titleProvider: gmail.function.MessageTitleProvider }) - builder.createDoc(notification.class.NotificationProviderDefaults, core.space.Model, { - provider: gmail.providers.EmailNotificationProvider, - ignoredTypes: [ - gmail.ids.EmailNotification, - notification.ids.CollaboratoAddNotification, - love.ids.InviteNotification, - love.ids.KnockNotification - ], - enabledTypes: [] - }) + defineNotifications(builder) } diff --git a/models/gmail/src/notification.ts b/models/gmail/src/notification.ts new file mode 100644 index 0000000000..584f1346c0 --- /dev/null +++ b/models/gmail/src/notification.ts @@ -0,0 +1,82 @@ +// +// Copyright © 2024 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import notification from '@hcengineering/model-notification' +import core from '@hcengineering/model-core' +import contact from '@hcengineering/model-contact' +import love from '@hcengineering/model-love' +import { type Builder } from '@hcengineering/model' + +import gmail from './plugin' + +export function defineNotifications (builder: Builder): void { + builder.createDoc( + notification.class.NotificationGroup, + core.space.Model, + { + label: gmail.string.Email, + icon: contact.icon.Email + }, + gmail.ids.EmailNotificationGroup + ) + + builder.createDoc( + notification.class.NotificationType, + core.space.Model, + { + label: gmail.string.NewMessage, + generated: false, + hidden: false, + txClasses: [core.class.TxCreateDoc], + objectClass: gmail.class.Message, + group: gmail.ids.EmailNotificationGroup, + allowedForAuthor: true, + defaultEnabled: false + }, + gmail.ids.EmailNotification + ) + + builder.createDoc( + notification.class.NotificationProvider, + core.space.Model, + { + icon: contact.icon.Email, + label: gmail.string.Email, + description: gmail.string.EmailNotificationsDescription, + defaultEnabled: true, + canDisable: true, + depends: notification.providers.InboxNotificationProvider, + order: 300 + }, + gmail.providers.EmailNotificationProvider + ) + + builder.createDoc(notification.class.NotificationProviderDefaults, core.space.Model, { + provider: notification.providers.InboxNotificationProvider, + ignoredTypes: [], + enabledTypes: [gmail.ids.EmailNotification] + }) + + builder.createDoc(notification.class.NotificationProviderDefaults, core.space.Model, { + provider: gmail.providers.EmailNotificationProvider, + ignoredTypes: [ + gmail.ids.EmailNotification, + notification.ids.CollaboratoAddNotification, + love.ids.InviteNotification, + love.ids.KnockNotification + ], + enabledTypes: [] + }) +} diff --git a/models/gmail/src/plugin.ts b/models/gmail/src/plugin.ts index 6db94b7ae3..f4b7b7ddf5 100644 --- a/models/gmail/src/plugin.ts +++ b/models/gmail/src/plugin.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import { type Doc, type Ref } from '@hcengineering/core' +import { type Client, type Doc, type Ref } from '@hcengineering/core' import { type IntlString, mergeIds, type Resource } from '@hcengineering/platform' import { gmailId } from '@hcengineering/gmail' import gmail from '@hcengineering/gmail-resources/src/plugin' @@ -52,6 +52,7 @@ export default mergeIds(gmailId, gmail, { GmailWriteMessage: '' as AnyComponent }, function: { - HasEmail: '' as Resource<(doc?: Doc | Doc[] | undefined) => Promise> + HasEmail: '' as Resource<(doc?: Doc | Doc[] | undefined) => Promise>, + MessageTitleProvider: '' as Resource<(client: Client, ref: Ref, doc?: Doc) => Promise> } }) diff --git a/plugins/activity-resources/src/components/doc-update-message/DocUpdateMessageObjectValue.svelte b/plugins/activity-resources/src/components/doc-update-message/DocUpdateMessageObjectValue.svelte index d2ce1ee29a..f01337e682 100644 --- a/plugins/activity-resources/src/components/doc-update-message/DocUpdateMessageObjectValue.svelte +++ b/plugins/activity-resources/src/components/doc-update-message/DocUpdateMessageObjectValue.svelte @@ -16,9 +16,15 @@ import { DisplayDocUpdateMessage, DocUpdateMessageViewlet } from '@hcengineering/activity' import { Class, Doc, Ref } from '@hcengineering/core' import { createQuery, getClient } from '@hcengineering/presentation' - import { Component, Icon, IconAdd, IconDelete } from '@hcengineering/ui' - import view from '@hcengineering/view' - import { buildRemovedDoc, checkIsObjectRemoved, DocNavLink, getDocLinkTitle } from '@hcengineering/view-resources' + import { AnyComponent, Component, Icon, IconAdd, IconDelete } from '@hcengineering/ui' + import view, { ObjectPanel } from '@hcengineering/view' + import { + buildRemovedDoc, + checkIsObjectRemoved, + DocNavLink, + getDocLinkTitle, + isAttachedDoc + } from '@hcengineering/view-resources' export let objectClass: DisplayDocUpdateMessage['objectClass'] export let objectId: DisplayDocUpdateMessage['objectId'] @@ -59,6 +65,18 @@ } $: void loadObject(objectId, objectClass) + + function getPanelComponent (object: Doc, objectPanel?: ObjectPanel): AnyComponent { + if (objectPanel !== undefined) { + return objectPanel.component + } + + if (isAttachedDoc(object)) { + return view.component.AttachedDocPanel + } + + return view.component.EditDoc + } {#if object} @@ -84,7 +102,7 @@ {object} colorInherit disabled={action === 'remove'} - component={objectPanel?.component ?? view.component.EditDoc} + component={getPanelComponent(object, objectPanel)} shrink={0} > {value} diff --git a/plugins/contact-resources/src/components/ChannelPanel.svelte b/plugins/contact-resources/src/components/ChannelPanel.svelte index 708283bf24..646ceec4ab 100644 --- a/plugins/contact-resources/src/components/ChannelPanel.svelte +++ b/plugins/contact-resources/src/components/ChannelPanel.svelte @@ -14,7 +14,7 @@ -->