Skip to content

Commit

Permalink
Fix document link in email notifications (#5627)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristina Fefelova <[email protected]>
  • Loading branch information
kristina-fefelova authored May 21, 2024
1 parent 69e683e commit 401ca99
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 104 deletions.
5 changes: 3 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions models/server-chunter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
89 changes: 1 addition & 88 deletions server-plugins/chunter-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -520,7 +434,6 @@ async function OnCollaboratorsChanged (tx: TxMixin<Doc, Collaborators>, control:
export default async () => ({
trigger: {
ChunterTrigger,
OnDirectMessageSent,
OnChatMessageRemoved,
OnChannelMembersChanged,
ChatNotificationsHandler
Expand Down
1 change: 0 additions & 1 deletion server-plugins/chunter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion server-plugins/document-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
8 changes: 7 additions & 1 deletion server-plugins/document-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ 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
*/
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>`
}
Expand Down

0 comments on commit 401ca99

Please sign in to comment.