Refresh workspaces from Codex threads

This commit is contained in:
Codex
2026-05-21 10:01:47 +00:00
parent a73f88fe5e
commit 0480eeb424

View File

@@ -191,7 +191,7 @@ func (b *Bot) handleCommand(ctx context.Context, message *Message, session store
case "cancel": case "cancel":
return true, b.cancelTurn(ctx, userID, chatID, session) return true, b.cancelTurn(ctx, userID, chatID, session)
case "workspaces": case "workspaces":
return true, b.sendWorkspaces(ctx, chatID) return true, b.sendWorkspaces(ctx, userID, chatID)
case "workspace": case "workspace":
return true, b.handleWorkspaceCommand(ctx, userID, chatID, session, args) return true, b.handleWorkspaceCommand(ctx, userID, chatID, session, args)
case "model": case "model":
@@ -486,7 +486,11 @@ func (b *Bot) cancelTurn(ctx context.Context, userID, chatID int64, session stor
return err return err
} }
func (b *Bot) sendWorkspaces(ctx context.Context, chatID int64) error { func (b *Bot) sendWorkspaces(ctx context.Context, userID, chatID int64) error {
if err := b.syncUserThreadStates(ctx, userID); err != nil {
b.logger.Printf("sync workspaces for user %d: %v", userID, err)
}
workspaces, err := b.store.ListWorkspaces(ctx) workspaces, err := b.store.ListWorkspaces(ctx)
if err != nil { if err != nil {
return err return err
@@ -513,7 +517,7 @@ func (b *Bot) sendWorkspaces(ctx context.Context, chatID int64) error {
func (b *Bot) handleWorkspaceCommand(ctx context.Context, userID, chatID int64, session store.Session, args []string) error { func (b *Bot) handleWorkspaceCommand(ctx context.Context, userID, chatID int64, session store.Session, args []string) error {
if len(args) == 0 { if len(args) == 0 {
return b.sendWorkspaces(ctx, chatID) return b.sendWorkspaces(ctx, userID, chatID)
} }
id, err := strconv.ParseInt(args[0], 10, 64) id, err := strconv.ParseInt(args[0], 10, 64)
if err != nil { if err != nil {
@@ -809,6 +813,15 @@ func (b *Bot) syncThreadStates(ctx context.Context, threads []store.Thread) []st
return threads return threads
} }
func (b *Bot) syncUserThreadStates(ctx context.Context, userID int64) error {
threads, err := b.store.ListThreadsPage(ctx, userID, false, 200, 0)
if err != nil {
return err
}
b.syncThreadStates(ctx, threads)
return nil
}
func (b *Bot) createNewThread(ctx context.Context, userID, chatID int64, session store.Session) (store.Thread, store.Workspace, error) { func (b *Bot) createNewThread(ctx context.Context, userID, chatID int64, session store.Session) (store.Thread, store.Workspace, error) {
workspace, err := b.resolveWorkspace(ctx, userID, session) workspace, err := b.resolveWorkspace(ctx, userID, session)
if err != nil { if err != nil {