maybeFinalizeTurnStatusLabelAndPush updates the cached turn status label for parent chats and optionally sends a web push notification.
( ctx context.Context, chat database.Chat, status database.ChatStatus, lastError string, runResult runChatResult, logger slog.Logger, )
| 9605 | // maybeFinalizeTurnStatusLabelAndPush updates the cached turn status label |
| 9606 | // for parent chats and optionally sends a web push notification. |
| 9607 | func (p *Server) maybeFinalizeTurnStatusLabelAndPush( |
| 9608 | ctx context.Context, |
| 9609 | chat database.Chat, |
| 9610 | status database.ChatStatus, |
| 9611 | lastError string, |
| 9612 | runResult runChatResult, |
| 9613 | logger slog.Logger, |
| 9614 | ) { |
| 9615 | if chat.ParentChatID.Valid { |
| 9616 | return |
| 9617 | } |
| 9618 | |
| 9619 | switch status { |
| 9620 | case database.ChatStatusWaiting: |
| 9621 | p.finalizeSuccessfulTurnStatusLabelAndPush(ctx, chat, status, runResult, logger) |
| 9622 | |
| 9623 | case database.ChatStatusPending: |
| 9624 | p.setLastTurnSummaryAsync(ctx, chat, fallbackTurnStatusLabel(status), logger) |
| 9625 | |
| 9626 | case database.ChatStatusError: |
| 9627 | p.clearLastTurnSummaryAsync(ctx, chat, logger) |
| 9628 | if p.webpushConfigured() { |
| 9629 | pushBody := fallbackTurnStatusLabel(status) |
| 9630 | if lastError != "" { |
| 9631 | pushBody = lastError |
| 9632 | } |
| 9633 | p.dispatchPush(ctx, chat, pushBody, status, logger) |
| 9634 | } |
| 9635 | |
| 9636 | case database.ChatStatusRequiresAction: |
| 9637 | p.setLastTurnSummaryAsync(ctx, chat, fallbackTurnStatusLabel(status), logger) |
| 9638 | |
| 9639 | default: |
| 9640 | // New statuses must be classified before they can safely |
| 9641 | // preserve or finalize a cached turn status label. |
| 9642 | p.clearLastTurnSummaryAsync(ctx, chat, logger) |
| 9643 | } |
| 9644 | } |
| 9645 | |
| 9646 | func (p *Server) finalizeSuccessfulTurnStatusLabelAndPush( |
| 9647 | ctx context.Context, |