Changeset 0.29.0 (#195)

This commit is contained in:
2026-03-17 16:28:47 +00:00
parent 128cbb8174
commit 5d637d3a90
129 changed files with 9418 additions and 3016 deletions

View File

@@ -0,0 +1,62 @@
package sqlite
import (
"context"
"database/sql"
"git.gobha.me/xcaliber/chat-switchboard/store"
)
// ── Mention resolution + display info (v0.29.0) ────────────────────────
func (s *UserStore) FindActiveByHandle(ctx context.Context, handle, excludeUserID string) (string, error) {
var id string
err := DB.QueryRowContext(ctx, `
SELECT id FROM users
WHERE LOWER(handle) = LOWER(?) AND id != ? AND is_active = 1
LIMIT 1
`, handle, excludeUserID).Scan(&id)
if err == sql.ErrNoRows {
return "", nil
}
return id, err
}
func (s *UserStore) FindActiveByHandlePrefix(ctx context.Context, prefix, excludeUserID string) (string, int, error) {
var count int
err := DB.QueryRowContext(ctx, `
SELECT COUNT(*) FROM users
WHERE LOWER(handle) LIKE LOWER(?) AND id != ? AND is_active = 1
`, prefix+"%", excludeUserID).Scan(&count)
if err != nil {
return "", 0, err
}
if count != 1 {
return "", count, nil
}
var id string
err = DB.QueryRowContext(ctx, `
SELECT id FROM users
WHERE LOWER(handle) LIKE LOWER(?) AND id != ? AND is_active = 1
LIMIT 1
`, prefix+"%", excludeUserID).Scan(&id)
return id, 1, err
}
func (s *UserStore) GetDisplayInfoByIDs(ctx context.Context, ids []string) (map[string]store.UserDisplayInfo, error) {
result := make(map[string]store.UserDisplayInfo)
for _, id := range ids {
var name, avatar sql.NullString
_ = DB.QueryRowContext(ctx, `
SELECT COALESCE(display_name, username), avatar_url FROM users WHERE id = ?
`, id).Scan(&name, &avatar)
if name.Valid {
info := store.UserDisplayInfo{Name: name.String}
if avatar.Valid {
info.Avatar = avatar.String
}
result[id] = info
}
}
return result, nil
}