markChatAsRead updates the last read message ID for a chat to the latest message, so subsequent unread checks treat all current messages as seen. This is called on stream connect and disconnect to avoid per-message API calls during active streaming.
(ctx context.Context, chatID uuid.UUID)
| 3404 | // messages as seen. This is called on stream connect and disconnect |
| 3405 | // to avoid per-message API calls during active streaming. |
| 3406 | func (api *API) markChatAsRead(ctx context.Context, chatID uuid.UUID) { |
| 3407 | lastMsg, err := api.Database.GetLastChatMessageByRole(ctx, database.GetLastChatMessageByRoleParams{ |
| 3408 | ChatID: chatID, |
| 3409 | Role: database.ChatMessageRoleAssistant, |
| 3410 | }) |
| 3411 | if errors.Is(err, sql.ErrNoRows) { |
| 3412 | // No assistant messages yet, nothing to mark as read. |
| 3413 | return |
| 3414 | } |
| 3415 | if err != nil { |
| 3416 | api.Logger.Warn(ctx, "failed to get last assistant message for read marker", |
| 3417 | slog.F("chat_id", chatID), |
| 3418 | slog.Error(err), |
| 3419 | ) |
| 3420 | return |
| 3421 | } |
| 3422 | |
| 3423 | err = api.Database.UpdateChatLastReadMessageID(ctx, database.UpdateChatLastReadMessageIDParams{ |
| 3424 | ID: chatID, |
| 3425 | LastReadMessageID: lastMsg.ID, |
| 3426 | }) |
| 3427 | if err != nil { |
| 3428 | api.Logger.Warn(ctx, "failed to update chat last read message ID", |
| 3429 | slog.F("chat_id", chatID), |
| 3430 | slog.Error(err), |
| 3431 | ) |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 3436 | // |
no test coverage detected