···2233import (
44 "fmt"
55+ "sort"
56 "strings"
67 "time"
78···157158 PullRoundIdx: pullRoundIdx,
158159 }, nil
159160}
161161+162162+type CommentListItem struct {
163163+ Self *Comment
164164+ Replies []*Comment
165165+}
166166+167167+func (it *CommentListItem) Participants() []syntax.DID {
168168+ participantSet := make(map[syntax.DID]struct{})
169169+ participants := []syntax.DID{}
170170+171171+ addParticipant := func(did syntax.DID) {
172172+ if _, exists := participantSet[did]; !exists {
173173+ participantSet[did] = struct{}{}
174174+ participants = append(participants, did)
175175+ }
176176+ }
177177+178178+ addParticipant(syntax.DID(it.Self.Did))
179179+180180+ for _, c := range it.Replies {
181181+ addParticipant(syntax.DID(c.Did))
182182+ }
183183+184184+ return participants
185185+}
186186+187187+func NewCommentList(comments []Comment) []CommentListItem {
188188+ // Create a map to quickly find comments by their aturi
189189+ toplevel := make(map[syntax.ATURI]*CommentListItem)
190190+ var replies []*Comment
191191+192192+ // collect top level comments into the map
193193+ for _, comment := range comments {
194194+ if comment.IsTopLevel() {
195195+ toplevel[comment.AtUri()] = &CommentListItem{
196196+ Self: &comment,
197197+ }
198198+ } else {
199199+ replies = append(replies, &comment)
200200+ }
201201+ }
202202+203203+ for _, r := range replies {
204204+ if r.ReplyTo == nil {
205205+ continue
206206+ }
207207+ if parent, exists := toplevel[syntax.ATURI(r.ReplyTo.Uri)]; exists {
208208+ parent.Replies = append(parent.Replies, r)
209209+ }
210210+ }
211211+212212+ var listing []CommentListItem
213213+ for _, v := range toplevel {
214214+ listing = append(listing, *v)
215215+ }
216216+217217+ // sort everything
218218+ sortFunc := func(a, b *Comment) bool {
219219+ return a.Created.Before(b.Created)
220220+ }
221221+ sort.Slice(listing, func(i, j int) bool {
222222+ return sortFunc(listing[i].Self, listing[j].Self)
223223+ })
224224+ for _, r := range listing {
225225+ sort.Slice(r.Replies, func(i, j int) bool {
226226+ return sortFunc(r.Replies[i], r.Replies[j])
227227+ })
228228+ }
229229+230230+ return listing
231231+}
-72
appview/models/issue.go
···2233import (
44 "fmt"
55- "sort"
65 "time"
7687 "github.com/bluesky-social/indigo/atproto/syntax"
···6059 return "open"
6160 }
6261 return "closed"
6363-}
6464-6565-type CommentListItem struct {
6666- Self *Comment
6767- Replies []*Comment
6868-}
6969-7070-func (it *CommentListItem) Participants() []syntax.DID {
7171- participantSet := make(map[syntax.DID]struct{})
7272- participants := []syntax.DID{}
7373-7474- addParticipant := func(did syntax.DID) {
7575- if _, exists := participantSet[did]; !exists {
7676- participantSet[did] = struct{}{}
7777- participants = append(participants, did)
7878- }
7979- }
8080-8181- addParticipant(syntax.DID(it.Self.Did))
8282-8383- for _, c := range it.Replies {
8484- addParticipant(syntax.DID(c.Did))
8585- }
8686-8787- return participants
8888-}
8989-9090-func (i *Issue) CommentList() []CommentListItem {
9191- // Create a map to quickly find comments by their aturi
9292- toplevel := make(map[syntax.ATURI]*CommentListItem)
9393- var replies []*Comment
9494-9595- // collect top level comments into the map
9696- for _, comment := range i.Comments {
9797- if comment.IsTopLevel() {
9898- toplevel[comment.AtUri()] = &CommentListItem{
9999- Self: &comment,
100100- }
101101- } else {
102102- replies = append(replies, &comment)
103103- }
104104- }
105105-106106- for _, r := range replies {
107107- if r.ReplyTo == nil {
108108- continue
109109- }
110110- if parent, exists := toplevel[syntax.ATURI(r.ReplyTo.Uri)]; exists {
111111- parent.Replies = append(parent.Replies, r)
112112- }
113113- }
114114-115115- var listing []CommentListItem
116116- for _, v := range toplevel {
117117- listing = append(listing, *v)
118118- }
119119-120120- // sort everything
121121- sortFunc := func(a, b *Comment) bool {
122122- return a.Created.Before(b.Created)
123123- }
124124- sort.Slice(listing, func(i, j int) bool {
125125- return sortFunc(listing[i].Self, listing[j].Self)
126126- })
127127- for _, r := range listing {
128128- sort.Slice(r.Replies, func(i, j int) bool {
129129- return sortFunc(r.Replies[i], r.Replies[j])
130130- })
131131- }
132132-133133- return listing
13462}
1356313664func (i *Issue) Participants() []syntax.DID {
+1-1
appview/notify/db/db.go
···123123 parent := *comment.ReplyTo
124124125125 // find the parent thread, and add all DIDs from here to the recipient list
126126- for _, t := range issue.CommentList() {
126126+ for _, t := range models.NewCommentList(issue.Comments) {
127127 if t.Self.AtUri() == syntax.ATURI(parent.Uri) {
128128 for _, p := range t.Participants() {
129129 recipients.Insert(p)