From 6ad119c66a19a9b39f2806948fdeed604ca682af Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 11 Jul 2024 20:39:40 +0500 Subject: [PATCH] Fix office statuses (#6053) Signed-off-by: Denis Bykhov --- server-plugins/love-resources/src/index.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server-plugins/love-resources/src/index.ts b/server-plugins/love-resources/src/index.ts index b265e5dd61..924cb8eab8 100644 --- a/server-plugins/love-resources/src/index.ts +++ b/server-plugins/love-resources/src/index.ts @@ -104,19 +104,21 @@ 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 + if (status !== undefined && status.online) return [] const person = account.person const infos = await control.findAll(love.class.ParticipantInfo, { person }) + const res: Tx[] = [] for (const info of infos) { - await control.apply([control.txFactory.createTxRemoveDoc(info._class, info.space, info._id)]) + res.push(control.txFactory.createTxRemoveDoc(info._class, info.space, info._id)) } + return res } export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise { @@ -135,10 +137,13 @@ export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise { - void removeUserInfo(status.user, control) - }, 20000) - return [] + return await new Promise((resolve) => { + setTimeout(() => { + void removeUserInfo(status.user, control).then((res) => { + resolve(res) + }) + }, 20000) + }) } } }