From 0480eeb424f67410ef2b051219655b7124722433 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 10:01:47 +0000 Subject: [PATCH] Refresh workspaces from Codex threads --- internal/telegram/bot.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/telegram/bot.go b/internal/telegram/bot.go index 9374071..c408d57 100644 --- a/internal/telegram/bot.go +++ b/internal/telegram/bot.go @@ -191,7 +191,7 @@ func (b *Bot) handleCommand(ctx context.Context, message *Message, session store case "cancel": return true, b.cancelTurn(ctx, userID, chatID, session) case "workspaces": - return true, b.sendWorkspaces(ctx, chatID) + return true, b.sendWorkspaces(ctx, userID, chatID) case "workspace": return true, b.handleWorkspaceCommand(ctx, userID, chatID, session, args) case "model": @@ -486,7 +486,11 @@ func (b *Bot) cancelTurn(ctx context.Context, userID, chatID int64, session stor 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) if err != nil { 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 { if len(args) == 0 { - return b.sendWorkspaces(ctx, chatID) + return b.sendWorkspaces(ctx, userID, chatID) } id, err := strconv.ParseInt(args[0], 10, 64) if err != nil { @@ -809,6 +813,15 @@ func (b *Bot) syncThreadStates(ctx context.Context, threads []store.Thread) []st 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) { workspace, err := b.resolveWorkspace(ctx, userID, session) if err != nil {