QFIX: User status (#7601)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2025-01-08 16:10:52 +07:00 committed by GitHub
parent bc4c94ae2a
commit bfe2960787
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 4 deletions

View File

@ -553,6 +553,13 @@ export interface Session {
query: DocumentQuery<T>,
options?: FindOptions<T>
) => Promise<void>
findAllRaw: <T extends Doc>(
ctx: MeasureContext,
pipeline: Pipeline,
_class: Ref<Class<T>>,
query: DocumentQuery<T>,
options?: FindOptions<T>
) => Promise<FindResult<T>>
searchFulltext: (ctx: ClientSessionCtx, query: SearchQuery, options: SearchOptions) => Promise<void>
tx: (ctx: ClientSessionCtx, tx: Tx) => Promise<void>
loadChunk: (ctx: ClientSessionCtx, domain: Domain, idx?: number) => Promise<void>

View File

@ -716,21 +716,38 @@ class TSessionManager implements SessionManager {
const user = pipeline.context.modelDb.getAccountByEmail(session.getUser())
if (user === undefined) return
const status = (await pipeline.findAll(ctx, core.class.UserStatus, { user: user._id }, { limit: 1 }))[0]
const clientCtx: ClientSessionCtx = {
requestId: undefined,
pipeline,
sendResponse: async (msg) => {
// No response
},
ctx,
sendError: async (msg, error: Status) => {
// Assume no error send
},
sendPong: () => {}
}
const status = (
await session.findAllRaw(ctx, pipeline, core.class.UserStatus, { user: user._id }, { limit: 1 })
)[0]
const txFactory = new TxFactory(user._id, true)
if (status === undefined) {
const tx = txFactory.createTxCreateDoc(core.class.UserStatus, core.space.Space, {
online,
user: user._id
})
await pipeline.tx(ctx, [tx])
await session.tx(clientCtx, tx)
} else if (status.online !== online) {
const tx = txFactory.createTxUpdateDoc(status._class, status.space, status._id, {
online
})
await pipeline.tx(ctx, [tx])
await session.tx(clientCtx, tx)
}
} catch {}
} catch (err: any) {
ctx.error('failed to set status', { err })
Analytics.handleError(err)
}
}
async close (ctx: MeasureContext, ws: ConnectionSocket, wsid: string): Promise<void> {