mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-08 21:27:45 +03:00
Fix multiple adding user to replied persons (#6130)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
3b9318e34a
commit
14487823a9
@ -157,14 +157,6 @@
|
|||||||
},
|
},
|
||||||
_id as Ref<ThreadMessage>
|
_id as Ref<ThreadMessage>
|
||||||
)
|
)
|
||||||
|
|
||||||
await operations.update(parentMessage, { lastReply: Date.now() })
|
|
||||||
|
|
||||||
const hasPerson = !!parentMessage.repliedPersons?.includes(account.person)
|
|
||||||
|
|
||||||
if (!hasPerson) {
|
|
||||||
await operations.update(parentMessage, { $push: { repliedPersons: account.person } })
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
await operations.addCollection<Doc, ChatMessage>(
|
await operations.addCollection<Doc, ChatMessage>(
|
||||||
_class,
|
_class,
|
||||||
|
@ -104,23 +104,18 @@ export async function CommentRemove (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function OnThreadMessageCreated (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
async function OnThreadMessageCreated (originTx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
|
||||||
const hierarchy = control.hierarchy
|
const hierarchy = control.hierarchy
|
||||||
const actualTx = TxProcessor.extractTx(tx)
|
const tx = TxProcessor.extractTx(originTx) as TxCreateDoc<ThreadMessage>
|
||||||
|
|
||||||
if (actualTx._class !== core.class.TxCreateDoc) {
|
if (tx._class !== core.class.TxCreateDoc || !hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc<Doc>)
|
const threadMessage = TxProcessor.createDoc2Doc(tx)
|
||||||
|
const message = (await control.findAll(activity.class.ActivityMessage, { _id: threadMessage.attachedTo }))[0]
|
||||||
|
|
||||||
if (!hierarchy.isDerived(doc._class, chunter.class.ThreadMessage)) {
|
if (message === undefined) {
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
const threadMessage = doc as ThreadMessage
|
|
||||||
|
|
||||||
if (!hierarchy.isDerived(threadMessage.attachedToClass, activity.class.ActivityMessage)) {
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,21 +124,26 @@ async function OnThreadMessageCreated (tx: Tx, control: TriggerControl): Promise
|
|||||||
threadMessage.space,
|
threadMessage.space,
|
||||||
threadMessage.attachedTo,
|
threadMessage.attachedTo,
|
||||||
{
|
{
|
||||||
lastReply: tx.modifiedOn
|
lastReply: originTx.modifiedOn
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const employee = control.modelDb.getObject(tx.modifiedBy) as PersonAccount
|
const personAccount = control.modelDb.getObject(originTx.modifiedBy) as PersonAccount
|
||||||
const employeeTx = control.txFactory.createTxUpdateDoc<ActivityMessage>(
|
|
||||||
|
if ((message.repliedPersons ?? []).includes(personAccount.person)) {
|
||||||
|
return [lastReplyTx]
|
||||||
|
}
|
||||||
|
|
||||||
|
const repliedPersonTx = control.txFactory.createTxUpdateDoc<ActivityMessage>(
|
||||||
threadMessage.attachedToClass,
|
threadMessage.attachedToClass,
|
||||||
threadMessage.space,
|
threadMessage.space,
|
||||||
threadMessage.attachedTo,
|
threadMessage.attachedTo,
|
||||||
{
|
{
|
||||||
$push: { repliedPersons: employee.person }
|
$push: { repliedPersons: personAccount.person }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return [lastReplyTx, employeeTx]
|
return [lastReplyTx, repliedPersonTx]
|
||||||
}
|
}
|
||||||
|
|
||||||
async function OnChatMessageCreated (tx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
|
async function OnChatMessageCreated (tx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
|
||||||
|
Loading…
Reference in New Issue
Block a user