tinyrelayfile
tinyrelay/internal/storage/private_repository.go/

internal/storage/private_repository.go raw
1package storage
2
3import (
4 "context"
5 "fmt"
6
7 "github.com/FelineStateMachine/tinyrelay/internal/event"
8)
9
10// HasPrivateRepositories checks the stored announcements, including legacy
11// 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}
15
16// 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}
20
21func (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') tag
29 WHERE json_extract(tag.value, '$[0]')='private'
30 AND lower(json_extract(tag.value, '$[1]'))='true'))`
31 var found bool
32 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, nil
36}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs