mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-08 21:27:45 +03:00
Fix office statuses (#6053)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
0031ede489
commit
6ad119c66a
@ -104,19 +104,21 @@ async function createUserInfo (acc: Ref<Account>, control: TriggerControl): Prom
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeUserInfo (acc: Ref<Account>, control: TriggerControl): Promise<void> {
|
async function removeUserInfo (acc: Ref<Account>, control: TriggerControl): Promise<Tx[]> {
|
||||||
const account = control.modelDb.findAllSync(contact.class.PersonAccount, { _id: acc as Ref<PersonAccount> })[0]
|
const account = control.modelDb.findAllSync(contact.class.PersonAccount, { _id: acc as Ref<PersonAccount> })[0]
|
||||||
if (account === undefined) return
|
if (account === undefined) return []
|
||||||
|
|
||||||
// recheck that user is still offline
|
// recheck that user is still offline
|
||||||
const status = (await control.findAll(core.class.UserStatus, { user: acc }))[0]
|
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 person = account.person
|
||||||
const infos = await control.findAll(love.class.ParticipantInfo, { person })
|
const infos = await control.findAll(love.class.ParticipantInfo, { person })
|
||||||
|
const res: Tx[] = []
|
||||||
for (const info of infos) {
|
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<Tx[]> {
|
export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||||
@ -135,10 +137,13 @@ export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise<Tx
|
|||||||
if (val) {
|
if (val) {
|
||||||
return await createUserInfo(status.user, control)
|
return await createUserInfo(status.user, control)
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
return await new Promise((resolve) => {
|
||||||
void removeUserInfo(status.user, control)
|
setTimeout(() => {
|
||||||
}, 20000)
|
void removeUserInfo(status.user, control).then((res) => {
|
||||||
return []
|
resolve(res)
|
||||||
|
})
|
||||||
|
}, 20000)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user