Monorepo for Tangled tangled.org
6

Configure Feed

Select the types of activity you want to include in your feed.

1package models 2 3import ( 4 "fmt" 5 "time" 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 8 "tangled.org/core/api/tangled" 9) 10 11type Issue struct { 12 Id int64 13 Did string 14 Rkey string 15 RepoDid syntax.DID 16 IssueId int 17 Created time.Time 18 Edited *time.Time 19 Deleted *time.Time 20 Title string 21 Body string 22 Open bool 23 Mentions []syntax.DID 24 References []syntax.ATURI 25 26 // optionally, populate this when querying for reverse mappings 27 // like comment counts, parent repo etc. 28 Comments []Comment 29 Labels LabelState 30 Repo *Repo 31} 32 33func (i *Issue) AtUri() syntax.ATURI { 34 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", i.Did, tangled.RepoIssueNSID, i.Rkey)) 35} 36 37func (i *Issue) AsRecord() tangled.RepoIssue { 38 mentions := make([]string, len(i.Mentions)) 39 for i, did := range i.Mentions { 40 mentions[i] = string(did) 41 } 42 references := make([]string, len(i.References)) 43 for i, uri := range i.References { 44 references[i] = string(uri) 45 } 46 rec := tangled.RepoIssue{ 47 Repo: string(i.RepoDid), 48 Title: i.Title, 49 Body: &i.Body, 50 Mentions: mentions, 51 References: references, 52 CreatedAt: i.Created.Format(time.RFC3339), 53 } 54 return rec 55} 56 57func (i *Issue) State() string { 58 if i.Open { 59 return "open" 60 } 61 return "closed" 62} 63 64func (i *Issue) Participants() []syntax.DID { 65 participantSet := make(map[syntax.DID]struct{}) 66 participants := []syntax.DID{} 67 68 addParticipant := func(did syntax.DID) { 69 if _, exists := participantSet[did]; !exists { 70 participantSet[did] = struct{}{} 71 participants = append(participants, did) 72 } 73 } 74 75 addParticipant(syntax.DID(i.Did)) 76 77 for _, c := range i.Comments { 78 addParticipant(c.Did) 79 } 80 81 return participants 82} 83 84func IssueFromRecord(did, rkey string, record tangled.RepoIssue) Issue { 85 created, err := time.Parse(time.RFC3339, record.CreatedAt) 86 if err != nil { 87 created = time.Now() 88 } 89 90 body := "" 91 if record.Body != nil { 92 body = *record.Body 93 } 94 95 return Issue{ 96 RepoDid: syntax.DID(record.Repo), 97 Did: did, 98 Rkey: rkey, 99 Created: created, 100 Title: record.Title, 101 Body: body, 102 Open: true, // new issues are open by default 103 } 104}