Fix document link in email notifications (#5627)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-05-21 10:59:32 +04:00 committed by GitHub
parent 69e683e060
commit 401ca99604
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 13 additions and 104 deletions

View File

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

View File

@ -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: {

View File

@ -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<Doc>, 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<Tx[]> {
const tx = TxProcessor.extractTx(originTx) as TxCreateDoc<ChatMessage>
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<DirectMessage> })
).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<Account> | 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<Doc, Collaborators>, control:
export default async () => ({
trigger: {
ChunterTrigger,
OnDirectMessageSent,
OnChatMessageRemoved,
OnChannelMembersChanged,
ChatNotificationsHandler

View File

@ -29,7 +29,6 @@ export const serverChunterId = 'server-chunter' as Plugin
export default plugin(serverChunterId, {
trigger: {
ChunterTrigger: '' as Resource<TriggerFunc>,
OnDirectMessageSent: '' as Resource<TriggerFunc>,
OnChatMessageRemoved: '' as Resource<TriggerFunc>,
OnChannelMembersChanged: '' as Resource<TriggerFunc>,
ChatNotificationsHandler: '' as Resource<TriggerFunc>

View File

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

View File

@ -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<string> {
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 `<a href="${link}">${document.name}</a>`
}