From 14487823a9abaaa2f3e7f200ec374ca84c1ecee3 Mon Sep 17 00:00:00 2001 From: Kristina Date: Thu, 25 Jul 2024 10:41:22 +0400 Subject: [PATCH] Fix multiple adding user to replied persons (#6130) Signed-off-by: Kristina Fefelova --- .../chat-message/ChatMessageInput.svelte | 8 ----- server-plugins/chunter-resources/src/index.ts | 32 +++++++++---------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte b/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte index f4e8e428f1..1c89326ff2 100644 --- a/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte +++ b/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte @@ -157,14 +157,6 @@ }, _id as Ref ) - - 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 { await operations.addCollection( _class, diff --git a/server-plugins/chunter-resources/src/index.ts b/server-plugins/chunter-resources/src/index.ts index 0bab977747..881d49a86d 100644 --- a/server-plugins/chunter-resources/src/index.ts +++ b/server-plugins/chunter-resources/src/index.ts @@ -104,23 +104,18 @@ export async function CommentRemove ( }) } -async function OnThreadMessageCreated (tx: Tx, control: TriggerControl): Promise { +async function OnThreadMessageCreated (originTx: TxCUD, control: TriggerControl): Promise { const hierarchy = control.hierarchy - const actualTx = TxProcessor.extractTx(tx) + const tx = TxProcessor.extractTx(originTx) as TxCreateDoc - if (actualTx._class !== core.class.TxCreateDoc) { + if (tx._class !== core.class.TxCreateDoc || !hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage)) { return [] } - const doc = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc) + 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)) { - return [] - } - - const threadMessage = doc as ThreadMessage - - if (!hierarchy.isDerived(threadMessage.attachedToClass, activity.class.ActivityMessage)) { + if (message === undefined) { return [] } @@ -129,21 +124,26 @@ async function OnThreadMessageCreated (tx: Tx, control: TriggerControl): Promise threadMessage.space, threadMessage.attachedTo, { - lastReply: tx.modifiedOn + lastReply: originTx.modifiedOn } ) - const employee = control.modelDb.getObject(tx.modifiedBy) as PersonAccount - const employeeTx = control.txFactory.createTxUpdateDoc( + const personAccount = control.modelDb.getObject(originTx.modifiedBy) as PersonAccount + + if ((message.repliedPersons ?? []).includes(personAccount.person)) { + return [lastReplyTx] + } + + const repliedPersonTx = control.txFactory.createTxUpdateDoc( threadMessage.attachedToClass, threadMessage.space, threadMessage.attachedTo, { - $push: { repliedPersons: employee.person } + $push: { repliedPersons: personAccount.person } } ) - return [lastReplyTx, employeeTx] + return [lastReplyTx, repliedPersonTx] } async function OnChatMessageCreated (tx: TxCUD, control: TriggerControl): Promise {