2023-12-13 18:59:11 +03:00
|
|
|
//
|
|
|
|
// Copyright © 2023 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.
|
|
|
|
//
|
|
|
|
|
2024-02-19 16:07:30 +03:00
|
|
|
import activity, { ActivityMessage, ActivityMessageControl, DocUpdateMessage, Reaction } from '@hcengineering/activity'
|
2024-01-11 17:46:11 +03:00
|
|
|
import core, {
|
2023-12-13 18:59:11 +03:00
|
|
|
Account,
|
|
|
|
AttachedDoc,
|
2024-02-27 11:30:36 +03:00
|
|
|
Class,
|
2023-12-13 18:59:11 +03:00
|
|
|
Data,
|
|
|
|
Doc,
|
2024-01-30 14:07:34 +03:00
|
|
|
MeasureContext,
|
2023-12-13 18:59:11 +03:00
|
|
|
Ref,
|
|
|
|
Tx,
|
2024-01-30 14:07:34 +03:00
|
|
|
TxCUD,
|
2023-12-13 18:59:11 +03:00
|
|
|
TxCollectionCUD,
|
|
|
|
TxCreateDoc,
|
2024-01-30 14:07:34 +03:00
|
|
|
TxProcessor,
|
2024-02-27 11:30:36 +03:00
|
|
|
matchQuery,
|
2024-05-14 09:40:02 +03:00
|
|
|
Hierarchy,
|
|
|
|
Space
|
2023-12-13 18:59:11 +03:00
|
|
|
} from '@hcengineering/core'
|
|
|
|
import { ActivityControl, DocObjectCache } from '@hcengineering/server-activity'
|
2023-12-21 21:13:02 +03:00
|
|
|
import type { TriggerControl } from '@hcengineering/server-core'
|
2024-01-25 19:44:12 +03:00
|
|
|
import {
|
|
|
|
createCollabDocInfo,
|
|
|
|
createCollaboratorNotifications,
|
2024-07-12 15:07:11 +03:00
|
|
|
getTextPresenter,
|
2024-01-25 19:44:12 +03:00
|
|
|
removeDocInboxNotifications
|
|
|
|
} from '@hcengineering/server-notification-resources'
|
2024-07-05 11:36:02 +03:00
|
|
|
import { PersonAccount } from '@hcengineering/contact'
|
2024-07-12 15:07:11 +03:00
|
|
|
import { NotificationContent } from '@hcengineering/notification'
|
|
|
|
import { getResource, translate } from '@hcengineering/platform'
|
2024-01-11 17:46:11 +03:00
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
import { getDocUpdateAction, getTxAttributesUpdates } from './utils'
|
2024-03-07 09:53:07 +03:00
|
|
|
import { ReferenceTrigger } from './references'
|
2023-12-13 18:59:11 +03:00
|
|
|
|
2024-01-11 17:46:11 +03:00
|
|
|
export async function OnReactionChanged (originTx: Tx, control: TriggerControl): Promise<Tx[]> {
|
|
|
|
const tx = originTx as TxCollectionCUD<ActivityMessage, Reaction>
|
|
|
|
const innerTx = TxProcessor.extractTx(tx) as TxCUD<Reaction>
|
|
|
|
|
|
|
|
if (innerTx._class === core.class.TxCreateDoc) {
|
2024-07-12 15:07:11 +03:00
|
|
|
const txes = await createReactionNotifications(tx, control)
|
|
|
|
|
|
|
|
await control.apply(txes, true)
|
|
|
|
return txes
|
2024-01-11 17:46:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (innerTx._class === core.class.TxRemoveDoc) {
|
2024-07-12 15:07:11 +03:00
|
|
|
const txes = await removeReactionNotifications(tx, control)
|
|
|
|
await control.apply(txes, true)
|
|
|
|
return txes
|
2024-01-11 17:46:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeReactionNotifications (
|
|
|
|
tx: TxCollectionCUD<ActivityMessage, Reaction>,
|
|
|
|
control: TriggerControl
|
|
|
|
): Promise<Tx[]> {
|
|
|
|
const message = (
|
2024-03-07 09:53:07 +03:00
|
|
|
await control.findAll(
|
|
|
|
activity.class.ActivityMessage,
|
|
|
|
{ objectId: tx.tx.objectId },
|
|
|
|
{ projection: { _id: 1, _class: 1, space: 1 } }
|
|
|
|
)
|
2024-01-11 17:46:11 +03:00
|
|
|
)[0]
|
|
|
|
|
|
|
|
if (message === undefined) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2024-03-07 09:53:07 +03:00
|
|
|
const res: Tx[] = []
|
|
|
|
const txes = await removeDocInboxNotifications(message._id, control)
|
|
|
|
|
|
|
|
const removeTx = control.txFactory.createTxRemoveDoc(message._class, message.space, message._id)
|
|
|
|
|
|
|
|
res.push(removeTx)
|
|
|
|
res.push(...txes)
|
|
|
|
|
|
|
|
return res
|
2024-01-11 17:46:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createReactionNotifications (
|
|
|
|
tx: TxCollectionCUD<ActivityMessage, Reaction>,
|
|
|
|
control: TriggerControl
|
|
|
|
): Promise<Tx[]> {
|
2024-02-02 12:43:50 +03:00
|
|
|
const createTx = TxProcessor.extractTx(tx) as TxCreateDoc<Reaction>
|
|
|
|
|
2024-01-11 17:46:11 +03:00
|
|
|
const parentMessage = (await control.findAll(activity.class.ActivityMessage, { _id: tx.objectId }))[0]
|
|
|
|
|
|
|
|
if (parentMessage === undefined) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = parentMessage.createdBy
|
|
|
|
|
|
|
|
if (user === undefined || user === core.account.System || user === tx.modifiedBy) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
let res: Tx[] = []
|
|
|
|
|
2024-02-02 12:43:50 +03:00
|
|
|
const rawMessage: Data<DocUpdateMessage> = {
|
|
|
|
txId: tx._id,
|
|
|
|
attachedTo: parentMessage._id,
|
|
|
|
attachedToClass: parentMessage._class,
|
|
|
|
objectId: createTx.objectId,
|
|
|
|
objectClass: createTx.objectClass,
|
|
|
|
action: 'create',
|
|
|
|
collection: 'docUpdateMessages',
|
|
|
|
updateCollection: tx.collection
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageTx = getDocUpdateMessageTx(control, tx, parentMessage, rawMessage, tx.modifiedBy)
|
2024-01-11 17:46:11 +03:00
|
|
|
|
|
|
|
if (messageTx === undefined) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:43:50 +03:00
|
|
|
res.push(messageTx)
|
|
|
|
|
2024-01-11 17:46:11 +03:00
|
|
|
const docUpdateMessage = TxProcessor.createDoc2Doc(messageTx.tx as TxCreateDoc<DocUpdateMessage>)
|
|
|
|
|
|
|
|
res = res.concat(
|
2024-05-07 09:49:36 +03:00
|
|
|
await createCollabDocInfo(
|
2024-07-05 11:36:02 +03:00
|
|
|
[user] as Ref<PersonAccount>[],
|
2024-05-07 09:49:36 +03:00
|
|
|
control,
|
|
|
|
tx.tx,
|
|
|
|
tx,
|
|
|
|
parentMessage,
|
|
|
|
[docUpdateMessage],
|
|
|
|
{ isOwn: true, isSpace: false, shouldUpdateTimestamp: false },
|
|
|
|
new Map()
|
|
|
|
)
|
2024-01-11 17:46:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
2023-12-13 18:59:11 +03:00
|
|
|
|
2024-02-27 11:30:36 +03:00
|
|
|
function isActivityDoc (_class: Ref<Class<Doc>>, hierarchy: Hierarchy): boolean {
|
|
|
|
const mixin = hierarchy.classHierarchyMixin(_class, activity.mixin.ActivityDoc)
|
|
|
|
|
|
|
|
return mixin !== undefined
|
|
|
|
}
|
|
|
|
|
2024-05-14 09:40:02 +03:00
|
|
|
function isSpace (space: Doc, hierarchy: Hierarchy): space is Space {
|
|
|
|
return hierarchy.isDerived(space._class, core.class.Space)
|
|
|
|
}
|
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
function getDocUpdateMessageTx (
|
|
|
|
control: ActivityControl,
|
|
|
|
originTx: TxCUD<Doc>,
|
|
|
|
object: Doc,
|
|
|
|
rawMessage: Data<DocUpdateMessage>,
|
|
|
|
modifiedBy?: Ref<Account>
|
|
|
|
): TxCollectionCUD<Doc, DocUpdateMessage> {
|
2024-05-14 09:40:02 +03:00
|
|
|
const { hierarchy } = control
|
|
|
|
const space = isSpace(object, hierarchy) ? object._id : object.space
|
2023-12-13 18:59:11 +03:00
|
|
|
const innerTx = control.txFactory.createTxCreateDoc(
|
|
|
|
activity.class.DocUpdateMessage,
|
2024-05-14 09:40:02 +03:00
|
|
|
space,
|
2023-12-13 18:59:11 +03:00
|
|
|
rawMessage,
|
|
|
|
undefined,
|
|
|
|
originTx.modifiedOn,
|
|
|
|
modifiedBy ?? originTx.modifiedBy
|
|
|
|
)
|
|
|
|
|
|
|
|
return control.txFactory.createTxCollectionCUD(
|
|
|
|
rawMessage.attachedToClass,
|
|
|
|
rawMessage.attachedTo,
|
2024-05-14 09:40:02 +03:00
|
|
|
space,
|
2023-12-13 18:59:11 +03:00
|
|
|
rawMessage.collection,
|
|
|
|
innerTx,
|
|
|
|
originTx.modifiedOn,
|
|
|
|
modifiedBy ?? originTx.modifiedBy
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-02-29 09:32:17 +03:00
|
|
|
export async function pushDocUpdateMessages (
|
|
|
|
ctx: MeasureContext | undefined,
|
2023-12-13 18:59:11 +03:00
|
|
|
control: ActivityControl,
|
|
|
|
res: TxCollectionCUD<Doc, DocUpdateMessage>[],
|
|
|
|
object: Doc | undefined,
|
|
|
|
originTx: TxCUD<Doc>,
|
|
|
|
modifiedBy?: Ref<Account>,
|
2024-02-19 16:07:30 +03:00
|
|
|
objectCache?: DocObjectCache,
|
|
|
|
controlRules?: ActivityMessageControl[]
|
2023-12-13 18:59:11 +03:00
|
|
|
): Promise<TxCollectionCUD<Doc, DocUpdateMessage>[]> {
|
|
|
|
if (object === undefined) {
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2024-02-27 11:30:36 +03:00
|
|
|
if (!isActivityDoc(object._class, control.hierarchy)) {
|
2023-12-13 18:59:11 +03:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
const tx =
|
|
|
|
originTx._class === core.class.TxCollectionCUD ? (originTx as TxCollectionCUD<Doc, AttachedDoc>).tx : originTx
|
|
|
|
|
|
|
|
const rawMessage: Data<DocUpdateMessage> = {
|
|
|
|
txId: originTx._id,
|
|
|
|
attachedTo: object._id,
|
|
|
|
attachedToClass: object._class,
|
|
|
|
objectId: tx.objectId,
|
|
|
|
objectClass: tx.objectClass,
|
|
|
|
action: getDocUpdateAction(control, tx),
|
|
|
|
collection: 'docUpdateMessages',
|
|
|
|
updateCollection:
|
|
|
|
originTx._class === core.class.TxCollectionCUD
|
|
|
|
? (originTx as TxCollectionCUD<Doc, AttachedDoc>).collection
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:07:30 +03:00
|
|
|
const attributesUpdates = await getTxAttributesUpdates(control, originTx, tx, object, objectCache, controlRules)
|
2023-12-13 18:59:11 +03:00
|
|
|
|
|
|
|
for (const attributeUpdates of attributesUpdates) {
|
|
|
|
res.push(
|
|
|
|
getDocUpdateMessageTx(
|
|
|
|
control,
|
|
|
|
originTx,
|
|
|
|
object,
|
|
|
|
{
|
|
|
|
...rawMessage,
|
|
|
|
attributeUpdates
|
|
|
|
},
|
|
|
|
modifiedBy
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-01-29 14:54:21 +03:00
|
|
|
if (attributesUpdates.length === 0 && rawMessage.action !== 'update') {
|
2023-12-13 18:59:11 +03:00
|
|
|
res.push(getDocUpdateMessageTx(control, originTx, object, rawMessage, modifiedBy))
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function generateDocUpdateMessages (
|
2024-01-30 14:07:34 +03:00
|
|
|
ctx: MeasureContext,
|
2023-12-13 18:59:11 +03:00
|
|
|
tx: TxCUD<Doc>,
|
|
|
|
control: ActivityControl,
|
|
|
|
res: TxCollectionCUD<Doc, DocUpdateMessage>[] = [],
|
|
|
|
originTx?: TxCUD<Doc>,
|
|
|
|
objectCache?: DocObjectCache
|
|
|
|
): Promise<TxCollectionCUD<Doc, DocUpdateMessage>[]> {
|
2023-12-28 18:21:40 +03:00
|
|
|
const { hierarchy } = control
|
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
if (tx.space === core.space.DerivedTx) {
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2023-12-28 18:21:40 +03:00
|
|
|
const etx = TxProcessor.extractTx(tx) as TxCUD<Doc>
|
|
|
|
|
|
|
|
if (
|
|
|
|
hierarchy.isDerived(tx.objectClass, activity.class.ActivityMessage) ||
|
|
|
|
hierarchy.isDerived(etx.objectClass, activity.class.ActivityMessage)
|
|
|
|
) {
|
2023-12-13 18:59:11 +03:00
|
|
|
return res
|
|
|
|
}
|
2023-12-28 18:21:40 +03:00
|
|
|
|
2023-12-21 21:13:02 +03:00
|
|
|
if (
|
2023-12-28 18:21:40 +03:00
|
|
|
hierarchy.classHierarchyMixin(tx.objectClass, activity.mixin.IgnoreActivity) !== undefined ||
|
|
|
|
hierarchy.classHierarchyMixin(etx.objectClass, activity.mixin.IgnoreActivity) !== undefined
|
2023-12-21 21:13:02 +03:00
|
|
|
) {
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we have override control over transaction => activity mappings
|
2024-02-19 16:07:30 +03:00
|
|
|
const controlRules = control.modelDb.findAllSync<ActivityMessageControl>(activity.class.ActivityMessageControl, {
|
2023-12-28 18:21:40 +03:00
|
|
|
objectClass: { $in: hierarchy.getAncestors(tx.objectClass) }
|
2023-12-21 21:13:02 +03:00
|
|
|
})
|
|
|
|
if (controlRules.length > 0) {
|
|
|
|
for (const r of controlRules) {
|
|
|
|
for (const s of r.skip) {
|
2023-12-28 18:21:40 +03:00
|
|
|
const otx = originTx ?? etx
|
|
|
|
if (matchQuery(otx !== undefined ? [tx, otx] : [tx], s, r.objectClass, hierarchy).length > 0) {
|
2023-12-21 21:13:02 +03:00
|
|
|
// Match found, we need to skip
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-13 18:59:11 +03:00
|
|
|
|
|
|
|
switch (tx._class) {
|
|
|
|
case core.class.TxCreateDoc: {
|
|
|
|
const doc = TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>)
|
2024-01-30 14:07:34 +03:00
|
|
|
return await ctx.with(
|
|
|
|
'pushDocUpdateMessages',
|
|
|
|
{},
|
2024-02-19 16:07:30 +03:00
|
|
|
async (ctx) =>
|
|
|
|
await pushDocUpdateMessages(ctx, control, res, doc, originTx ?? tx, undefined, objectCache, controlRules)
|
2024-01-30 14:07:34 +03:00
|
|
|
)
|
2023-12-13 18:59:11 +03:00
|
|
|
}
|
|
|
|
case core.class.TxMixin:
|
|
|
|
case core.class.TxUpdateDoc: {
|
2024-02-27 11:30:36 +03:00
|
|
|
if (!isActivityDoc(tx.objectClass, control.hierarchy)) {
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
let doc = objectCache?.docs?.get(tx.objectId)
|
|
|
|
if (doc === undefined) {
|
|
|
|
doc = (await control.findAll(tx.objectClass, { _id: tx.objectId }, { limit: 1 }))[0]
|
|
|
|
}
|
2024-01-30 14:07:34 +03:00
|
|
|
return await ctx.with(
|
|
|
|
'pushDocUpdateMessages',
|
|
|
|
{},
|
|
|
|
async (ctx) =>
|
2024-02-19 16:07:30 +03:00
|
|
|
await pushDocUpdateMessages(
|
|
|
|
ctx,
|
|
|
|
control,
|
|
|
|
res,
|
|
|
|
doc ?? undefined,
|
|
|
|
originTx ?? tx,
|
|
|
|
undefined,
|
|
|
|
objectCache,
|
|
|
|
controlRules
|
|
|
|
)
|
2024-01-30 14:07:34 +03:00
|
|
|
)
|
2023-12-13 18:59:11 +03:00
|
|
|
}
|
|
|
|
case core.class.TxCollectionCUD: {
|
|
|
|
const actualTx = TxProcessor.extractTx(tx) as TxCUD<Doc>
|
2024-01-30 14:07:34 +03:00
|
|
|
res = await generateDocUpdateMessages(ctx, actualTx, control, res, tx, objectCache)
|
2024-02-29 09:32:17 +03:00
|
|
|
if ([core.class.TxCreateDoc, core.class.TxRemoveDoc].includes(actualTx._class)) {
|
2024-02-27 11:30:36 +03:00
|
|
|
if (!isActivityDoc(tx.objectClass, control.hierarchy)) {
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
let doc = objectCache?.docs?.get(tx.objectId)
|
|
|
|
if (doc === undefined) {
|
|
|
|
doc = (await control.findAll(tx.objectClass, { _id: tx.objectId }, { limit: 1 }))[0]
|
|
|
|
}
|
2024-01-30 14:07:34 +03:00
|
|
|
if (doc !== undefined) {
|
|
|
|
return await ctx.with(
|
|
|
|
'pushDocUpdateMessages',
|
|
|
|
{},
|
|
|
|
async (ctx) =>
|
2024-02-19 16:07:30 +03:00
|
|
|
await pushDocUpdateMessages(
|
|
|
|
ctx,
|
|
|
|
control,
|
|
|
|
res,
|
|
|
|
doc ?? undefined,
|
|
|
|
originTx ?? tx,
|
|
|
|
undefined,
|
|
|
|
objectCache,
|
|
|
|
controlRules
|
|
|
|
)
|
2024-01-30 14:07:34 +03:00
|
|
|
)
|
|
|
|
}
|
2023-12-13 18:59:11 +03:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
async function ActivityMessagesHandler (tx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
|
2024-02-27 11:30:36 +03:00
|
|
|
if (tx.space === core.space.DerivedTx) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
if (control.hierarchy.isDerived(tx.objectClass, activity.class.ActivityMessage)) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2024-01-30 14:07:34 +03:00
|
|
|
const txes = await control.ctx.with(
|
|
|
|
'generateDocUpdateMessages',
|
|
|
|
{},
|
|
|
|
async (ctx) => await generateDocUpdateMessages(ctx, tx, control)
|
|
|
|
)
|
2024-02-27 11:30:36 +03:00
|
|
|
|
|
|
|
if (txes.length === 0) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2024-01-25 19:44:12 +03:00
|
|
|
const messages = txes.map((messageTx) => TxProcessor.createDoc2Doc(messageTx.tx as TxCreateDoc<DocUpdateMessage>))
|
|
|
|
|
2024-01-30 14:07:34 +03:00
|
|
|
const notificationTxes = await control.ctx.with(
|
|
|
|
'createNotificationTxes',
|
|
|
|
{},
|
|
|
|
async (ctx) => await createCollaboratorNotifications(ctx, tx, control, messages)
|
|
|
|
)
|
2024-01-25 19:44:12 +03:00
|
|
|
|
|
|
|
return [...txes, ...notificationTxes]
|
2023-12-13 18:59:11 +03:00
|
|
|
}
|
|
|
|
|
2023-12-20 18:05:52 +03:00
|
|
|
async function OnDocRemoved (originTx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
|
|
|
|
const tx = TxProcessor.extractTx(originTx) as TxCUD<Doc>
|
|
|
|
|
|
|
|
if (tx._class !== core.class.TxRemoveDoc) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
const activityDocMixin = control.hierarchy.classHierarchyMixin(tx.objectClass, activity.mixin.ActivityDoc)
|
|
|
|
|
|
|
|
if (activityDocMixin === undefined) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
const messages = await control.findAll(
|
|
|
|
activity.class.ActivityMessage,
|
|
|
|
{ attachedTo: tx.objectId },
|
|
|
|
{ projection: { _id: 1, _class: 1, space: 1 } }
|
|
|
|
)
|
|
|
|
|
|
|
|
return messages.map((message) => control.txFactory.createTxRemoveDoc(message._class, message.space, message._id))
|
|
|
|
}
|
|
|
|
|
2024-07-12 15:07:11 +03:00
|
|
|
async function ReactionNotificationContentProvider (
|
|
|
|
doc: ActivityMessage,
|
|
|
|
originTx: TxCUD<Doc>,
|
|
|
|
_: Ref<Account>,
|
|
|
|
control: TriggerControl
|
|
|
|
): Promise<NotificationContent> {
|
|
|
|
const tx = TxProcessor.extractTx(originTx) as TxCreateDoc<Reaction>
|
|
|
|
const presenter = getTextPresenter(doc._class, control.hierarchy)
|
|
|
|
const reaction = TxProcessor.createDoc2Doc(tx)
|
|
|
|
|
|
|
|
let text = ''
|
|
|
|
|
|
|
|
if (presenter !== undefined) {
|
|
|
|
const fn = await getResource(presenter.presenter)
|
|
|
|
|
|
|
|
text = await fn(doc, control)
|
|
|
|
} else {
|
|
|
|
text = await translate(activity.string.Message, {})
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: activity.string.ReactionNotificationTitle,
|
|
|
|
body: activity.string.ReactionNotificationBody,
|
|
|
|
intlParams: {
|
|
|
|
title: text,
|
|
|
|
reaction: reaction.emoji
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-25 20:31:13 +03:00
|
|
|
export * from './references'
|
|
|
|
|
2023-12-13 18:59:11 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
|
|
export default async () => ({
|
|
|
|
trigger: {
|
2024-03-07 09:53:07 +03:00
|
|
|
ReferenceTrigger,
|
2023-12-20 18:05:52 +03:00
|
|
|
ActivityMessagesHandler,
|
2024-01-11 17:46:11 +03:00
|
|
|
OnDocRemoved,
|
|
|
|
OnReactionChanged
|
2024-07-12 15:07:11 +03:00
|
|
|
},
|
|
|
|
function: {
|
|
|
|
ReactionNotificationContentProvider
|
2023-12-13 18:59:11 +03:00
|
|
|
}
|
|
|
|
})
|