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