From 401ca9960486ccf8a4c73991f6cd0a63cadc8b59 Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 21 May 2024 10:59:32 +0400 Subject: [PATCH] Fix document link in email notifications (#5627) Signed-off-by: Kristina Fefelova --- common/config/rush/pnpm-lock.yaml | 5 +- models/server-chunter/src/index.ts | 11 --- server-plugins/chunter-resources/src/index.ts | 89 +------------------ server-plugins/chunter/src/index.ts | 1 - .../document-resources/package.json | 3 +- .../document-resources/src/index.ts | 8 +- 6 files changed, 13 insertions(+), 104 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 15c8809e54..0f05f67513 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -21028,7 +21028,7 @@ packages: dev: false file:projects/model-recruit.tgz: - resolution: {integrity: sha512-okf7MWpkXXa77uzcoITAQPfa3Vrk2VSI9a4aYr0s0RrokB+nZnbQ53X1vFZ4WmoOkGuLJwM6Y3mF1JMixQYU7g==, tarball: file:projects/model-recruit.tgz} + resolution: {integrity: sha512-xylfMWvlyhc9HaC19AKbkMYCL3nCp40c/9npYgIEUPYOVa57it9ZpRG7xTfTkDSPv+XSy8ghXXorjDbS59yzQg==, tarball: file:projects/model-recruit.tgz} name: '@rush-temp/model-recruit' version: 0.0.0 dependencies: @@ -23290,7 +23290,7 @@ packages: dev: false file:projects/server-document-resources.tgz(esbuild@0.20.1)(ts-node@10.9.2): - resolution: {integrity: sha512-amHAX4TQhC6S+4d1hKL8Ha8q1CYgNQoqG/Hs0nAmzpLTYESNgY2pcfR01AR2MTQwzhOrPETjCJIefGXpZyOIVA==, tarball: file:projects/server-document-resources.tgz} + resolution: {integrity: sha512-HLCIVutccPS7ue3cRx8E6yPO7hdyYflE7S1RDxejexTf+ddxcMn74xPTUqQWYGwDhNf8ZEuAwN1eyJQluKZSsw==, tarball: file:projects/server-document-resources.tgz} id: file:projects/server-document-resources.tgz name: '@rush-temp/server-document-resources' version: 0.0.0 @@ -23308,6 +23308,7 @@ packages: jest: 29.7.0(@types/node@20.11.19)(ts-node@10.9.2) prettier: 3.2.5 prettier-plugin-svelte: 3.2.1(prettier@3.2.5)(svelte@4.2.11) + slugify: 1.6.6 ts-jest: 29.1.2(esbuild@0.20.1)(jest@29.7.0)(typescript@5.3.3) typescript: 5.3.3 transitivePeerDependencies: diff --git a/models/server-chunter/src/index.ts b/models/server-chunter/src/index.ts index b9687e59e1..aa77305549 100644 --- a/models/server-chunter/src/index.ts +++ b/models/server-chunter/src/index.ts @@ -57,17 +57,6 @@ export function createModel (builder: Builder): void { } }) - builder.createDoc(serverCore.class.Trigger, core.space.Model, { - trigger: serverChunter.trigger.OnDirectMessageSent, - txMatch: { - _class: core.class.TxCollectionCUD, - objectClass: chunter.class.DirectMessage, - collection: 'messages', - 'tx._class': core.class.TxCreateDoc, - 'tx.objectClass': chunter.class.ChatMessage - } - }) - builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverChunter.trigger.OnChatMessageRemoved, txMatch: { diff --git a/server-plugins/chunter-resources/src/index.ts b/server-plugins/chunter-resources/src/index.ts index 552a747006..631e311bc3 100644 --- a/server-plugins/chunter-resources/src/index.ts +++ b/server-plugins/chunter-resources/src/index.ts @@ -13,14 +13,7 @@ // limitations under the License. // -import chunter, { - Channel, - ChatMessage, - chunterId, - ChunterSpace, - DirectMessage, - ThreadMessage -} from '@hcengineering/chunter' +import chunter, { Channel, ChatMessage, chunterId, ChunterSpace, ThreadMessage } from '@hcengineering/chunter' import core, { Account, AttachedDoc, @@ -47,7 +40,6 @@ import serverCore, { TriggerControl } from '@hcengineering/server-core' import { getDocCollaborators, getMixinTx, - pushActivityInboxNotifications, createCollaboratorNotifications } from '@hcengineering/server-notification-resources' import { workbenchId } from '@hcengineering/workbench' @@ -272,84 +264,6 @@ export async function ChunterTrigger (tx: TxCUD, control: TriggerControl): return res.flat() } -/** - * @public - * Sends notification to the message sender in case when DM - * notifications are deleted or hidden. This is required for - * the DM to re-appear in the sender's inbox. - */ -export async function OnDirectMessageSent (originTx: Tx, control: TriggerControl): Promise { - const tx = TxProcessor.extractTx(originTx) as TxCreateDoc - - if (tx._class !== core.class.TxCreateDoc) { - return [] - } - - const message = TxProcessor.createDoc2Doc(tx) - - if ( - message.createdBy === undefined || - !control.hierarchy.isDerived(message.attachedToClass, chunter.class.DirectMessage) - ) { - return [] - } - - const directChannel = ( - await control.findAll(chunter.class.DirectMessage, { _id: message.attachedTo as Ref }) - ).shift() - - if (directChannel === undefined || directChannel.members.length !== 2 || !directChannel.private) { - return [] - } - - const notifyContexts = await control.findAll(notification.class.DocNotifyContext, { attachedTo: directChannel._id }) - - // binding notification to the DM creation tx to properly display it in inbox - const dmCreationTx = ( - await control.findAll(core.class.TxCreateDoc, { objectClass: directChannel._class, objectId: directChannel._id }) - ).shift() - - if (dmCreationTx === undefined) { - return [] - } - - const sender = message.createdBy - const notifyContext = notifyContexts.find(({ user }) => user === sender) - const res: Tx[] = [] - - if (notifyContext === undefined) { - let anotherPerson: Ref | undefined - for (const person of directChannel.members) { - if (person !== sender) { - anotherPerson = person - break - } - } - - if (anotherPerson == null) return [] - - await pushActivityInboxNotifications( - dmCreationTx, - control, - res, - anotherPerson, - directChannel, - notifyContexts, - [message], - true, - true - ) - } else if (notifyContext.hidden) { - res.push( - control.txFactory.createTxUpdateDoc(notifyContext._class, notifyContext.space, notifyContext._id, { - hidden: false - }) - ) - } - - return res -} - /** * @public */ @@ -520,7 +434,6 @@ async function OnCollaboratorsChanged (tx: TxMixin, control: export default async () => ({ trigger: { ChunterTrigger, - OnDirectMessageSent, OnChatMessageRemoved, OnChannelMembersChanged, ChatNotificationsHandler diff --git a/server-plugins/chunter/src/index.ts b/server-plugins/chunter/src/index.ts index 9dc11a94c4..193df6d277 100644 --- a/server-plugins/chunter/src/index.ts +++ b/server-plugins/chunter/src/index.ts @@ -29,7 +29,6 @@ export const serverChunterId = 'server-chunter' as Plugin export default plugin(serverChunterId, { trigger: { ChunterTrigger: '' as Resource, - OnDirectMessageSent: '' as Resource, OnChatMessageRemoved: '' as Resource, OnChannelMembersChanged: '' as Resource, ChatNotificationsHandler: '' as Resource diff --git a/server-plugins/document-resources/package.json b/server-plugins/document-resources/package.json index f298716147..791b4dcd01 100644 --- a/server-plugins/document-resources/package.json +++ b/server-plugins/document-resources/package.json @@ -37,6 +37,7 @@ "@hcengineering/platform": "^0.6.9", "@hcengineering/workbench": "^0.6.9", "@hcengineering/server-core": "^0.6.1", - "@hcengineering/document": "^0.6.0" + "@hcengineering/document": "^0.6.0", + "slugify": "^1.6.6" } } diff --git a/server-plugins/document-resources/src/index.ts b/server-plugins/document-resources/src/index.ts index 1336d1ed02..cb3dfafd13 100644 --- a/server-plugins/document-resources/src/index.ts +++ b/server-plugins/document-resources/src/index.ts @@ -8,6 +8,12 @@ import { Document, documentId } from '@hcengineering/document' import { getMetadata } from '@hcengineering/platform' import { workbenchId } from '@hcengineering/workbench' import serverCore, { TriggerControl } from '@hcengineering/server-core' +import slugify from 'slugify' + +function getDocumentId (doc: Document): string { + const slug = slugify(doc.name, { lower: true }) + return `${slug}-${doc._id}` +} /** * @public @@ -15,7 +21,7 @@ import serverCore, { TriggerControl } from '@hcengineering/server-core' export async function documentHTMLPresenter (doc: Doc, control: TriggerControl): Promise { const document = doc as Document const front = getMetadata(serverCore.metadata.FrontUrl) ?? '' - const path = `${workbenchId}/${control.workspace.workspaceUrl}/${documentId}/${doc._id}` + const path = `${workbenchId}/${control.workspace.workspaceUrl}/${documentId}/${getDocumentId(document)}` const link = concatLink(front, path) return `${document.name}` }