Changeset 0.17.1 (#76)

This commit is contained in:
2026-02-28 01:40:31 +00:00
parent c9141a6896
commit 856dc9b0ac
64 changed files with 8037 additions and 1657 deletions

View File

@@ -12,15 +12,15 @@ import (
func GetSiblingCount(channelID string, parentID *string) int {
var count int
if parentID == nil {
database.DB.QueryRow(`
database.DB.QueryRow(database.Q(`
SELECT COUNT(*) FROM messages
WHERE channel_id = $1 AND parent_id IS NULL AND deleted_at IS NULL
`, channelID).Scan(&count)
`), channelID).Scan(&count)
} else {
database.DB.QueryRow(`
database.DB.QueryRow(database.Q(`
SELECT COUNT(*) FROM messages
WHERE parent_id = $1 AND deleted_at IS NULL
`, *parentID).Scan(&count)
`), *parentID).Scan(&count)
}
if count == 0 {
count = 1
@@ -34,10 +34,10 @@ func GetSiblings(messageID string) ([]SiblingInfo, int, error) {
// First get the parent_id of the target message
var parentID *string
var channelID string
err := database.DB.QueryRow(`
err := database.DB.QueryRow(database.Q(`
SELECT parent_id, channel_id FROM messages
WHERE id = $1 AND deleted_at IS NULL
`, messageID).Scan(&parentID, &channelID)
`), messageID).Scan(&parentID, &channelID)
if err != nil {
return nil, 0, fmt.Errorf("message not found: %w", err)
}
@@ -45,19 +45,19 @@ func GetSiblings(messageID string) ([]SiblingInfo, int, error) {
var rows *sql.Rows
if parentID == nil {
// Root messages: siblings are other roots in the same channel
rows, err = database.DB.Query(`
SELECT id, role, model, sibling_index, LEFT(content, 80), created_at
rows, err = database.DB.Query(database.Q(`
SELECT id, role, model, sibling_index, SUBSTR(content, 1, 80), created_at
FROM messages
WHERE channel_id = $1 AND parent_id IS NULL AND deleted_at IS NULL
ORDER BY sibling_index, created_at
`, channelID)
`), channelID)
} else {
rows, err = database.DB.Query(`
SELECT id, role, model, sibling_index, LEFT(content, 80), created_at
rows, err = database.DB.Query(database.Q(`
SELECT id, role, model, sibling_index, SUBSTR(content, 1, 80), created_at
FROM messages
WHERE parent_id = $1 AND deleted_at IS NULL
ORDER BY sibling_index, created_at
`, *parentID)
`), *parentID)
}
if err != nil {
return nil, 0, err
@@ -85,7 +85,7 @@ func GetSiblings(messageID string) ([]SiblingInfo, int, error) {
// Used when switching branches: clicking a mid-tree sibling navigates to its leaf.
func FindLeafFromMessage(messageID string) (string, error) {
var leafID string
err := database.DB.QueryRow(`
err := database.DB.QueryRow(database.Q(`
WITH RECURSIVE descendants AS (
SELECT id, 0 AS depth
FROM messages
@@ -105,7 +105,7 @@ func FindLeafFromMessage(messageID string) (string, error) {
SELECT id FROM descendants
ORDER BY depth DESC
LIMIT 1
`, messageID).Scan(&leafID)
`), messageID).Scan(&leafID)
if err != nil {
return messageID, nil // if anything fails, just use the message itself