a love letter to tangled (android, iOS, and a search API)
at main 48 lines 1.3 kB view raw
1package normalize 2 3import "tangled.org/desertthunder.dev/twister/internal/store" 4 5const collectionProfile = "sh.tangled.actor.profile" 6 7// ProfileAdapter normalizes sh.tangled.actor.profile records. 8// Title (author handle) is not available in the record payload — it is set by 9// the indexer after identity-event handle resolution. 10type ProfileAdapter struct{} 11 12func (a *ProfileAdapter) Collection() string { return collectionProfile } 13func (a *ProfileAdapter) RecordType() string { return "profile" } 14 15func (a *ProfileAdapter) Searchable(record map[string]any) bool { 16 return str(record, "description") != "" 17} 18 19func (a *ProfileAdapter) Normalize(event TapRecordEvent) (*store.Document, error) { 20 r := event.Record 21 rec := r.Record 22 23 description := str(rec, "description") 24 location := str(rec, "location") 25 26 summary := description 27 if location != "" { 28 if summary != "" { 29 summary = summary + " · " + location 30 } else { 31 summary = location 32 } 33 } 34 35 return &store.Document{ 36 ID: StableID(r.DID, r.Collection, r.RKey), 37 DID: r.DID, 38 Collection: r.Collection, 39 RKey: r.RKey, 40 ATURI: BuildATURI(r.DID, r.Collection, r.RKey), 41 CID: r.CID, 42 RecordType: a.RecordType(), 43 Title: "", 44 Body: description, 45 Summary: truncate(summary, 200), 46 TagsJSON: "[]", 47 }, nil 48}