(aiChatId: string)
| 382 | } |
| 383 | |
| 384 | private getActiveMessageId(aiChatId: string): string | null { |
| 385 | const db = this.getDb() |
| 386 | const row = db.prepare('SELECT active_message_id as activeMessageId FROM ai_chat WHERE id = ?').get(aiChatId) as |
| 387 | | { activeMessageId: string | null } |
| 388 | | undefined |
| 389 | if (row?.activeMessageId) { |
| 390 | const activeExists = db.prepare('SELECT 1 FROM ai_message WHERE id = ?').get(row.activeMessageId) |
| 391 | if (activeExists) return row.activeMessageId |
| 392 | } |
| 393 | |
| 394 | const fallback = db |
| 395 | .prepare('SELECT id FROM ai_message WHERE ai_chat_id = ? ORDER BY timestamp DESC, id DESC LIMIT 1') |
| 396 | .get(aiChatId) as { id: string } | undefined |
| 397 | if (fallback?.id) { |
| 398 | db.prepare('UPDATE ai_chat SET active_message_id = ? WHERE id = ?').run(fallback.id, aiChatId) |
| 399 | return fallback.id |
| 400 | } |
| 401 | return null |
| 402 | } |
| 403 | |
| 404 | private getAllMessageRows(aiChatId: string): AIMessageRow[] { |
| 405 | return this.getDb() |
no test coverage detected