From f4d3518c3c834300e827144b257f9243192b9461 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 5 Jun 2024 18:13:16 +0500 Subject: [PATCH] Delay before remove participant info (#5735) Signed-off-by: Denis Bykhov --- server-plugins/love-resources/src/index.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/server-plugins/love-resources/src/index.ts b/server-plugins/love-resources/src/index.ts index 753625d909..9917a80f36 100644 --- a/server-plugins/love-resources/src/index.ts +++ b/server-plugins/love-resources/src/index.ts @@ -73,6 +73,11 @@ async function createUserInfo (acc: Ref, control: TriggerControl): Prom const account = control.modelDb.findAllSync(contact.class.PersonAccount, { _id: acc as Ref })[0] if (account === undefined) return [] const personId = account.person + + // we already have participantInfo for this person + const infos = await control.findAll(love.class.ParticipantInfo, { person: personId }) + if (infos.length > 0) return [] + const person = (await control.findAll(contact.class.Person, { _id: personId }))[0] const room = (await control.findAll(love.class.Office, { person: personId }))[0] const tx = control.txFactory.createTxCreateDoc(love.class.ParticipantInfo, love.space.Rooms, { @@ -98,15 +103,19 @@ async function createUserInfo (acc: Ref, control: TriggerControl): Prom return [] } -async function removeUserInfo (acc: Ref, control: TriggerControl): Promise { +async function removeUserInfo (acc: Ref, control: TriggerControl): Promise { const account = control.modelDb.findAllSync(contact.class.PersonAccount, { _id: acc as Ref })[0] - if (account === undefined) return [] + if (account === undefined) return + + // recheck that user is still offline + const status = (await control.findAll(core.class.UserStatus, { user: acc }))[0] + if (status !== undefined && status.online) return + const person = account.person const infos = await control.findAll(love.class.ParticipantInfo, { person }) for (const info of infos) { await control.apply([control.txFactory.createTxRemoveDoc(info._class, info.space, info._id)], true) } - return [] } export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise { @@ -125,7 +134,10 @@ export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise { + void removeUserInfo(status.user, control) + }, 5000) + return [] } } }