From 45b24722df35a127f6ebd4cb2a39b452f7193107 Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Fri, 14 Jun 2024 14:56:14 +0400 Subject: [PATCH] ezqms-966: notifications fixes (#5819) Signed-off-by: Alexey Zinoviev --- models/controlled-documents/src/index.ts | 18 ++++++++++--- models/controlled-documents/src/types.ts | 1 - models/document/src/index.ts | 1 - models/request/src/index.ts | 9 +++++-- models/server-request/package.json | 4 ++- models/server-request/src/index.ts | 6 +++++ models/view/src/index.ts | 4 +++ models/view/src/plugin.ts | 1 + plugins/activity-resources/src/utils.ts | 3 ++- .../src/components/document/DocTeam.svelte | 2 +- .../CollaborativeDocActivityPresenter.svelte | 21 +++++++++++++++ plugins/view-resources/src/index.ts | 2 ++ server-plugins/request-resources/src/index.ts | 26 ++++++++++++++++++- server-plugins/request/package.json | 3 ++- server-plugins/request/src/index.ts | 4 +++ 15 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 plugins/view-resources/src/components/CollaborativeDocActivityPresenter.svelte diff --git a/models/controlled-documents/src/index.ts b/models/controlled-documents/src/index.ts index 78395b2a3d..3897bac4c0 100644 --- a/models/controlled-documents/src/index.ts +++ b/models/controlled-documents/src/index.ts @@ -926,6 +926,11 @@ export function defineNotifications (builder: Builder): void { [notification.providers.PlatformNotification]: true, [notification.providers.BrowserNotification]: false, [notification.providers.EmailNotification]: false + }, + templates: { + textTemplate: '{sender} changed {doc} status', + htmlTemplate: '

{sender} changed {doc} status

', + subjectTemplate: '{doc} status changed' } }, documents.notification.StateNotification @@ -941,12 +946,17 @@ export function defineNotifications (builder: Builder): void { label: documents.string.CoAuthors, group: documents.notification.DocumentsNotificationGroup, field: 'coAuthors', - txClasses: [core.class.TxUpdateDoc], + txClasses: [core.class.TxCreateDoc, core.class.TxUpdateDoc], objectClass: documents.class.ControlledDocument, providers: { [notification.providers.PlatformNotification]: true, - [notification.providers.BrowserNotification]: false, - [notification.providers.EmailNotification]: false + [notification.providers.BrowserNotification]: true, + [notification.providers.EmailNotification]: true + }, + templates: { + textTemplate: '{sender} assigned you as a co-author of {doc}', + htmlTemplate: '

{sender} assigned you as a co-author of {doc}

', + subjectTemplate: 'Co-authoring assignment for {doc}' } }, documents.notification.CoAuthorsNotification @@ -978,7 +988,7 @@ export function defineNotifications (builder: Builder): void { 'changeControl', 'coAuthors' ], - ['owner'] + ['owner', 'comments', 'reviewers', 'approvers'] ) } diff --git a/models/controlled-documents/src/types.ts b/models/controlled-documents/src/types.ts index f6faafadb5..a40f13b757 100644 --- a/models/controlled-documents/src/types.ts +++ b/models/controlled-documents/src/types.ts @@ -270,7 +270,6 @@ export class TDocument extends TDoc implements Document { state!: DocumentState @Prop(TypeCollaborativeDoc(), documents.string.CollaborativeDocument) - @Hidden() content!: CollaborativeDoc @Prop(Collection(tags.class.TagReference), documents.string.Labels) diff --git a/models/document/src/index.ts b/models/document/src/index.ts index f731f14beb..ce4dd7eddf 100644 --- a/models/document/src/index.ts +++ b/models/document/src/index.ts @@ -93,7 +93,6 @@ export class TDocument extends TAttachedDoc implements Document { name!: string @Prop(TypeCollaborativeDoc(), document.string.Document) - @Hidden() content!: CollaborativeDoc @Prop(TypeRef(core.class.Account), document.string.LockedBy) diff --git a/models/request/src/index.ts b/models/request/src/index.ts index 2634bb6b64..a6d0bf2ef4 100644 --- a/models/request/src/index.ts +++ b/models/request/src/index.ts @@ -135,9 +135,14 @@ export function createModel (builder: Builder): void { label: request.string.Request, allowedForAuthor: true, providers: { - [notification.providers.BrowserNotification]: false, + [notification.providers.BrowserNotification]: true, [notification.providers.PlatformNotification]: true, - [notification.providers.EmailNotification]: false + [notification.providers.EmailNotification]: true + }, + templates: { + textTemplate: '{sender} sent you a {doc}', + htmlTemplate: '

{sender} sent you a {doc}

', + subjectTemplate: '{doc}' } }, request.ids.CreateRequestNotification diff --git a/models/server-request/package.json b/models/server-request/package.json index acda396189..2c2f390b8b 100644 --- a/models/server-request/package.json +++ b/models/server-request/package.json @@ -33,6 +33,8 @@ "@hcengineering/model-core": "^0.6.0", "@hcengineering/platform": "^0.6.11", "@hcengineering/server-request": "^0.6.0", - "@hcengineering/server-core": "^0.6.1" + "@hcengineering/server-core": "^0.6.1", + "@hcengineering/model-request": "^0.6.0", + "@hcengineering/server-notification": "^0.6.1" } } diff --git a/models/server-request/src/index.ts b/models/server-request/src/index.ts index 177b3df120..007cceb17d 100644 --- a/models/server-request/src/index.ts +++ b/models/server-request/src/index.ts @@ -18,6 +18,8 @@ import { type Builder } from '@hcengineering/model' import core from '@hcengineering/core' import serverCore from '@hcengineering/server-core' import serverRequest from '@hcengineering/server-request' +import serverNotification from '@hcengineering/server-notification' +import request from '@hcengineering/model-request' export { serverRequestId } from '@hcengineering/server-request' @@ -25,4 +27,8 @@ export function createModel (builder: Builder): void { builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverRequest.trigger.OnRequest }) + + builder.mixin(request.class.Request, core.class.Class, serverNotification.mixin.TextPresenter, { + presenter: serverRequest.function.RequestTextPresenter + }) } diff --git a/models/view/src/index.ts b/models/view/src/index.ts index c939c22683..8b378b6a8b 100644 --- a/models/view/src/index.ts +++ b/models/view/src/index.ts @@ -500,6 +500,10 @@ export function createModel (builder: Builder): void { editor: view.component.CollaborativeDocEditor }) + builder.mixin(core.class.TypeCollaborativeDoc, core.class.Class, view.mixin.ActivityAttributePresenter, { + presenter: view.component.CollaborativeDocActivityPresenter + }) + builder.mixin(core.class.TypeCollaborativeDocVersion, core.class.Class, view.mixin.InlineAttributEditor, { editor: view.component.CollaborativeDocEditor }) diff --git a/models/view/src/plugin.ts b/models/view/src/plugin.ts index a26003dda8..a53ffd21ed 100644 --- a/models/view/src/plugin.ts +++ b/models/view/src/plugin.ts @@ -74,6 +74,7 @@ export default mergeIds(viewId, view, { HTMLEditor: '' as AnyComponent, CollaborativeHTMLEditor: '' as AnyComponent, CollaborativeDocEditor: '' as AnyComponent, + CollaborativeDocActivityPresenter: '' as AnyComponent, MarkupEditor: '' as AnyComponent, MarkupEditorPopup: '' as AnyComponent, ListView: '' as AnyComponent, diff --git a/plugins/activity-resources/src/utils.ts b/plugins/activity-resources/src/utils.ts index 2e0a262325..4bd458ed2a 100644 --- a/plugins/activity-resources/src/utils.ts +++ b/plugins/activity-resources/src/utils.ts @@ -138,7 +138,8 @@ export function getIsTextType (attributeModel?: AttributeModel): boolean { return ( attributeModel.attribute?.type?._class === core.class.TypeMarkup || - attributeModel.attribute?.type?._class === core.class.TypeCollaborativeMarkup + attributeModel.attribute?.type?._class === core.class.TypeCollaborativeMarkup || + attributeModel.attribute?.type?._class === core.class.TypeCollaborativeDoc ) } diff --git a/plugins/controlled-documents-resources/src/components/document/DocTeam.svelte b/plugins/controlled-documents-resources/src/components/document/DocTeam.svelte index 4a04aefd41..1420b0f9b1 100644 --- a/plugins/controlled-documents-resources/src/components/document/DocTeam.svelte +++ b/plugins/controlled-documents-resources/src/components/document/DocTeam.svelte @@ -118,7 +118,7 @@
- {reviewers?.length} + {coAuthors?.length}
+ + +{value} diff --git a/plugins/view-resources/src/index.ts b/plugins/view-resources/src/index.ts index ab00f2bd00..3fdd4e5b96 100644 --- a/plugins/view-resources/src/index.ts +++ b/plugins/view-resources/src/index.ts @@ -28,6 +28,7 @@ import ClassPresenter from './components/ClassPresenter.svelte' import ClassRefPresenter from './components/ClassRefPresenter.svelte' import CollaborativeDocEditor from './components/CollaborativeDocEditor.svelte' import CollaborativeHTMLEditor from './components/CollaborativeHTMLEditor.svelte' +import CollaborativeDocActivityPresenter from './components/CollaborativeDocActivityPresenter.svelte' import ColorsPopup from './components/ColorsPopup.svelte' import DateEditor from './components/DateEditor.svelte' import DatePresenter from './components/DatePresenter.svelte' @@ -275,6 +276,7 @@ export default async (): Promise => ({ HTMLEditor, CollaborativeDocEditor, CollaborativeHTMLEditor, + CollaborativeDocActivityPresenter, ListView, GrowPresenter, DividerPresenter, diff --git a/server-plugins/request-resources/src/index.ts b/server-plugins/request-resources/src/index.ts index 92a72b3e1d..1a793eb37b 100644 --- a/server-plugins/request-resources/src/index.ts +++ b/server-plugins/request-resources/src/index.ts @@ -15,11 +15,12 @@ import core, { Doc, Tx, TxCUD, TxCollectionCUD, TxCreateDoc, TxUpdateDoc, TxProcessor } from '@hcengineering/core' import request, { Request, RequestStatus } from '@hcengineering/request' +import { getResource, translate } from '@hcengineering/platform' import type { TriggerControl } from '@hcengineering/server-core' import { pushDocUpdateMessages } from '@hcengineering/server-activity-resources' import { DocUpdateMessage } from '@hcengineering/activity' import notification from '@hcengineering/notification' -import { getNotificationTxes, getCollaborators } from '@hcengineering/server-notification-resources' +import { getNotificationTxes, getCollaborators, getTextPresenter } from '@hcengineering/server-notification-resources' /** * @public @@ -158,8 +159,31 @@ async function getRequestNotificationTx (tx: TxCollectionCUD, cont return res } +/** + * @public + */ +export async function requestTextPresenter (doc: Doc, control: TriggerControl): Promise { + const request = doc as Request + let title = await translate(control.hierarchy.getClass(request._class).label, {}) + + const attachedDocTextPresenter = getTextPresenter(request.attachedToClass, control.hierarchy) + if (attachedDocTextPresenter !== undefined) { + const getTitle = await getResource(attachedDocTextPresenter.presenter) + const attachedDoc = (await control.findAll(request.attachedToClass, { _id: request.attachedTo }, { limit: 1 }))[0] + + if (attachedDoc !== undefined) { + title = `${title} — ${await getTitle(attachedDoc, control)}` + } + } + + return title +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ + function: { + RequestTextPresenter: requestTextPresenter + }, trigger: { OnRequest } diff --git a/server-plugins/request/package.json b/server-plugins/request/package.json index 531502e71b..956ed15322 100644 --- a/server-plugins/request/package.json +++ b/server-plugins/request/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "@hcengineering/platform": "^0.6.11", - "@hcengineering/server-core": "^0.6.1" + "@hcengineering/server-core": "^0.6.1", + "@hcengineering/server-notification": "^0.6.1" } } diff --git a/server-plugins/request/src/index.ts b/server-plugins/request/src/index.ts index 702feab7f9..c575c5b2cc 100644 --- a/server-plugins/request/src/index.ts +++ b/server-plugins/request/src/index.ts @@ -15,6 +15,7 @@ import { Plugin, plugin, Resource } from '@hcengineering/platform' import type { TriggerFunc } from '@hcengineering/server-core' +import { Presenter } from '@hcengineering/server-notification' /** * @public @@ -25,6 +26,9 @@ export const serverRequestId = 'server-request' as Plugin * @public */ export default plugin(serverRequestId, { + function: { + RequestTextPresenter: '' as Resource + }, trigger: { OnRequest: '' as Resource }