Refresh workspaces from Codex threads
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user