1package storage23import (4 "context"5 "fmt"67 "github.com/FelineStateMachine/tinyrelay/internal/event"8)910// HasPrivateRepositories checks the stored announcements, including legacy11// events. Multiword tags such as private are not in the NIP-01 tag index.12func (s *Store) HasPrivateRepositories(ctx context.Context) (bool, error) {13 return s.hasPrivateRepository(ctx, "", "")14}1516// IsPrivateRepository resolves a state event's privacy from its announcement.17func (s *Store) IsPrivateRepository(ctx context.Context, pubkey, identifier string) (bool, error) {18 return s.hasPrivateRepository(ctx, pubkey, identifier)19}2021func (s *Store) hasPrivateRepository(ctx context.Context, pubkey, identifier string) (bool, error) {22 query := `SELECT EXISTS(SELECT 1 FROM events e WHERE e.kind=?`23 args := []any{event.KIND_REPO}24 if pubkey != "" {25 query += ` AND e.pubkey=? AND e.d=?`26 args = append(args, pubkey, identifier)27 }28 query += ` AND EXISTS(SELECT 1 FROM json_each(e.raw, '$.tags') tag29 WHERE json_extract(tag.value, '$[0]')='private'30 AND lower(json_extract(tag.value, '$[1]'))='true'))`31 var found bool32 if err := s.DB().QueryRowContext(ctx, query, args...).Scan(&found); err != nil {33 return false, fmt.Errorf("check stored repository privacy: %w", err)34 }35 return found, nil36}