@@ -3,6 +3,10 @@ import { Actor } from "@opencode-ai/console-core/actor.js"
33import { action , query } from "@solidjs/router"
44import { withActor } from "~/context/auth.withActor"
55import { Billing } from "@opencode-ai/console-core/billing.js"
6+ import { User } from "@opencode-ai/console-core/user.js"
7+ import { and , Database , desc , eq , isNull } from "@opencode-ai/console-core/drizzle/index.js"
8+ import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
9+ import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
610
711export function formatDateForTable ( date : Date ) {
812 const options : Intl . DateTimeFormatOptions = {
@@ -30,17 +34,28 @@ export function formatDateUTC(date: Date) {
3034 return date . toLocaleDateString ( "en-US" , options )
3135}
3236
33- export const queryIsLoggedIn = query ( async ( ) => {
37+ export async function getLastSeenWorkspaceID ( ) {
3438 "use server"
35- return withActor ( ( ) => {
36- try {
37- Actor . assert ( "account" )
38- return true
39- } catch {
40- return false
41- }
39+ return withActor ( async ( ) => {
40+ const actor = Actor . assert ( "account" )
41+ return Database . use ( async ( tx ) =>
42+ tx
43+ . select ( { id : WorkspaceTable . id } )
44+ . from ( UserTable )
45+ . innerJoin ( WorkspaceTable , eq ( UserTable . workspaceID , WorkspaceTable . id ) )
46+ . where (
47+ and (
48+ eq ( UserTable . accountID , actor . properties . accountID ) ,
49+ isNull ( UserTable . timeDeleted ) ,
50+ isNull ( WorkspaceTable . timeDeleted ) ,
51+ ) ,
52+ )
53+ . orderBy ( desc ( UserTable . timeSeen ) )
54+ . limit ( 1 )
55+ . then ( ( x ) => x [ 0 ] ?. id ) ,
56+ )
4257 } )
43- } , "isLoggedIn.get" )
58+ }
4459
4560export const querySessionInfo = query ( async ( workspaceID : string ) => {
4661 "use server"
0 commit comments