MCPcopy Index your code
hub / github.com/coder/coder / DeleteQueued

Method DeleteQueued

coderd/x/chatd/chatd.go:2361–2419  ·  view source on GitHub ↗

DeleteQueued removes a queued user message and publishes the queue update.

(
	ctx context.Context,
	chatID uuid.UUID,
	queuedMessageID int64,
)

Source from the content-addressed store, hash-verified

2359
2360// DeleteQueued removes a queued user message and publishes the queue update.
2361func (p *Server) DeleteQueued(
2362 ctx context.Context,
2363 chatID uuid.UUID,
2364 queuedMessageID int64,
2365) error {
2366 if chatID == uuid.Nil {
2367 return xerrors.New("chat_id is required")
2368 }
2369
2370 var queuedMessages []database.ChatQueuedMessage
2371 var queueLoadedOK bool
2372
2373 txErr := p.db.InTx(func(tx database.Store) error {
2374 // Lock the chat row to prevent processChat from
2375 // auto-promoting a message the user intended to delete.
2376 if _, err := tx.GetChatByIDForUpdate(ctx, chatID); err != nil {
2377 return xerrors.Errorf("lock chat: %w", err)
2378 }
2379
2380 err := tx.DeleteChatQueuedMessage(ctx, database.DeleteChatQueuedMessageParams{
2381 ID: queuedMessageID,
2382 ChatID: chatID,
2383 })
2384 if err != nil {
2385 return xerrors.Errorf("delete queued message: %w", err)
2386 }
2387
2388 var err2 error
2389 queuedMessages, err2 = tx.GetChatQueuedMessages(ctx, chatID)
2390 if err2 != nil {
2391 p.logger.Warn(ctx, "failed to load queued messages after delete",
2392 slog.F("chat_id", chatID),
2393 slog.F("queued_message_id", queuedMessageID),
2394 slog.Error(err2),
2395 )
2396 // Non-fatal: the delete succeeded, so we still commit.
2397 return nil
2398 }
2399 queueLoadedOK = true
2400
2401 return nil
2402 }, nil)
2403 if txErr != nil {
2404 return txErr
2405 }
2406
2407 if queueLoadedOK {
2408 p.publishEvent(chatID, codersdk.ChatStreamEvent{
2409 Type: codersdk.ChatStreamEventTypeQueueUpdate,
2410 QueuedMessages: db2sdk.ChatQueuedMessages(queuedMessages),
2411 })
2412 }
2413 // Always notify subscribers so they can re-fetch, even if we
2414 // failed to load the updated queue payload above.
2415 p.publishChatStreamNotify(chatID, coderdpubsub.ChatStreamNotifyMessage{
2416 QueueUpdate: true,
2417 })
2418 return nil

Callers 1

Calls 10

publishEventMethod · 0.95
ChatQueuedMessagesFunction · 0.92
NewMethod · 0.65
InTxMethod · 0.65
GetChatByIDForUpdateMethod · 0.65
GetChatQueuedMessagesMethod · 0.65
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected