Skip to content

Commit

Permalink
Fix multiple adding user to replied persons (#6130)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristina Fefelova <[email protected]>
  • Loading branch information
kristina-fefelova authored Jul 25, 2024
1 parent 3b9318e commit 1448782
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@
},
_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 {
await operations.addCollection<Doc, ChatMessage>(
_class,
Expand Down
32 changes: 16 additions & 16 deletions server-plugins/chunter-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 actualTx = TxProcessor.extractTx(tx)
const tx = TxProcessor.extractTx(originTx) as TxCreateDoc<ThreadMessage>

if (actualTx._class !== core.class.TxCreateDoc) {
return []
}

const doc = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc<Doc>)

if (!hierarchy.isDerived(doc._class, chunter.class.ThreadMessage)) {
if (tx._class !== core.class.TxCreateDoc || !hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage)) {
return []
}

const threadMessage = doc as ThreadMessage
const threadMessage = TxProcessor.createDoc2Doc(tx)
const message = (await control.findAll(activity.class.ActivityMessage, { _id: threadMessage.attachedTo }))[0]

if (!hierarchy.isDerived(threadMessage.attachedToClass, activity.class.ActivityMessage)) {
if (message === undefined) {
return []
}

Expand All @@ -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<ActivityMessage>(
const personAccount = control.modelDb.getObject(originTx.modifiedBy) as PersonAccount

if ((message.repliedPersons ?? []).includes(personAccount.person)) {
return [lastReplyTx]
}

const repliedPersonTx = control.txFactory.createTxUpdateDoc<ActivityMessage>(
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<Doc>, control: TriggerControl): Promise<Tx[]> {
Expand Down

0 comments on commit 1448782

Please sign in to comment.