a love letter to tangled (android, iOS, and a search API)
at main 54 lines 1.3 kB view raw
1package normalize 2 3import ( 4 "fmt" 5 6 "tangled.org/desertthunder.dev/twister/internal/store" 7) 8 9const collectionPull = "sh.tangled.repo.pull" 10 11// PullAdapter normalizes sh.tangled.repo.pull records. 12type PullAdapter struct{} 13 14func (a *PullAdapter) Collection() string { return collectionPull } 15func (a *PullAdapter) RecordType() string { return "pull" } 16 17func (a *PullAdapter) Searchable(_ map[string]any) bool { return true } 18 19func (a *PullAdapter) Normalize(event TapRecordEvent) (*store.Document, error) { 20 r := event.Record 21 rec := r.Record 22 23 title := str(rec, "title") 24 body := str(rec, "body") 25 26 repoDID := "" 27 target := nestedMap(rec, "target") 28 if target != nil { 29 repoURI := str(target, "repo") 30 if repoURI != "" { 31 did, _, _, err := ParseATURI(repoURI) 32 if err != nil { 33 return nil, fmt.Errorf("pull target repo AT-URI: %w", err) 34 } 35 repoDID = did 36 } 37 } 38 39 return &store.Document{ 40 ID: StableID(r.DID, r.Collection, r.RKey), 41 DID: r.DID, 42 Collection: r.Collection, 43 RKey: r.RKey, 44 ATURI: BuildATURI(r.DID, r.Collection, r.RKey), 45 CID: r.CID, 46 RecordType: a.RecordType(), 47 Title: title, 48 Body: body, 49 Summary: truncate(body, 200), 50 RepoDID: repoDID, 51 TagsJSON: "[]", 52 CreatedAt: str(rec, "createdAt"), 53 }, nil 54}