Fix multiple adding user to replied persons (#6130)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-07-25 10:41:22 +04:00 committed by GitHub
parent 3b9318e34a
commit 14487823a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 24 deletions

View File

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

View File

@ -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[]> {