Monorepo for Tangled tangled.org

appview: move CommentList out of Issue #1304

open opened by boltless.me targeting master from sl/comment

So that we can render reply comments from non-issue threads.

Signed-off-by: Seongmin Lee git@boltless.me

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mj4ttwo6al22
+81 -84
Diff #3
+1 -1
appview/issues/issues.go
··· 135 135 LoggedInUser: user, 136 136 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 137 137 Issue: issue, 138 - CommentList: issue.CommentList(), 138 + CommentList: models.NewCommentList(issue.Comments), 139 139 Backlinks: backlinks, 140 140 Reactions: reactionMap, 141 141 UserReacted: userReactions,
+72
appview/models/comment.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "sort" 5 6 "strings" 6 7 "time" 7 8 ··· 156 157 PullRoundIdx: pullRoundIdx, 157 158 }, nil 158 159 } 160 + 161 + type CommentListItem struct { 162 + Self *Comment 163 + Replies []*Comment 164 + } 165 + 166 + func (it *CommentListItem) Participants() []syntax.DID { 167 + participantSet := make(map[syntax.DID]struct{}) 168 + participants := []syntax.DID{} 169 + 170 + addParticipant := func(did syntax.DID) { 171 + if _, exists := participantSet[did]; !exists { 172 + participantSet[did] = struct{}{} 173 + participants = append(participants, did) 174 + } 175 + } 176 + 177 + addParticipant(syntax.DID(it.Self.Did)) 178 + 179 + for _, c := range it.Replies { 180 + addParticipant(syntax.DID(c.Did)) 181 + } 182 + 183 + return participants 184 + } 185 + 186 + func NewCommentList(comments []Comment) []CommentListItem { 187 + // Create a map to quickly find comments by their aturi 188 + toplevel := make(map[syntax.ATURI]*CommentListItem) 189 + var replies []*Comment 190 + 191 + // collect top level comments into the map 192 + for _, comment := range comments { 193 + if comment.IsTopLevel() { 194 + toplevel[comment.AtUri()] = &CommentListItem{ 195 + Self: &comment, 196 + } 197 + } else { 198 + replies = append(replies, &comment) 199 + } 200 + } 201 + 202 + for _, r := range replies { 203 + if r.ReplyTo == nil { 204 + continue 205 + } 206 + if parent, exists := toplevel[syntax.ATURI(r.ReplyTo.Uri)]; exists { 207 + parent.Replies = append(parent.Replies, r) 208 + } 209 + } 210 + 211 + var listing []CommentListItem 212 + for _, v := range toplevel { 213 + listing = append(listing, *v) 214 + } 215 + 216 + // sort everything 217 + sortFunc := func(a, b *Comment) bool { 218 + return a.Created.Before(b.Created) 219 + } 220 + sort.Slice(listing, func(i, j int) bool { 221 + return sortFunc(listing[i].Self, listing[j].Self) 222 + }) 223 + for _, r := range listing { 224 + sort.Slice(r.Replies, func(i, j int) bool { 225 + return sortFunc(r.Replies[i], r.Replies[j]) 226 + }) 227 + } 228 + 229 + return listing 230 + }
-72
appview/models/issue.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - "sort" 6 5 "time" 7 6 8 7 "github.com/bluesky-social/indigo/atproto/syntax" ··· 66 65 return "closed" 67 66 } 68 67 69 - type CommentListItem struct { 70 - Self *Comment 71 - Replies []*Comment 72 - } 73 - 74 - func (it *CommentListItem) Participants() []syntax.DID { 75 - participantSet := make(map[syntax.DID]struct{}) 76 - participants := []syntax.DID{} 77 - 78 - addParticipant := func(did syntax.DID) { 79 - if _, exists := participantSet[did]; !exists { 80 - participantSet[did] = struct{}{} 81 - participants = append(participants, did) 82 - } 83 - } 84 - 85 - addParticipant(syntax.DID(it.Self.Did)) 86 - 87 - for _, c := range it.Replies { 88 - addParticipant(syntax.DID(c.Did)) 89 - } 90 - 91 - return participants 92 - } 93 - 94 - func (i *Issue) CommentList() []CommentListItem { 95 - // Create a map to quickly find comments by their aturi 96 - toplevel := make(map[syntax.ATURI]*CommentListItem) 97 - var replies []*Comment 98 - 99 - // collect top level comments into the map 100 - for _, comment := range i.Comments { 101 - if comment.IsTopLevel() { 102 - toplevel[comment.AtUri()] = &CommentListItem{ 103 - Self: &comment, 104 - } 105 - } else { 106 - replies = append(replies, &comment) 107 - } 108 - } 109 - 110 - for _, r := range replies { 111 - if r.ReplyTo == nil { 112 - continue 113 - } 114 - if parent, exists := toplevel[syntax.ATURI(r.ReplyTo.Uri)]; exists { 115 - parent.Replies = append(parent.Replies, r) 116 - } 117 - } 118 - 119 - var listing []CommentListItem 120 - for _, v := range toplevel { 121 - listing = append(listing, *v) 122 - } 123 - 124 - // sort everything 125 - sortFunc := func(a, b *Comment) bool { 126 - return a.Created.Before(b.Created) 127 - } 128 - sort.Slice(listing, func(i, j int) bool { 129 - return sortFunc(listing[i].Self, listing[j].Self) 130 - }) 131 - for _, r := range listing { 132 - sort.Slice(r.Replies, func(i, j int) bool { 133 - return sortFunc(r.Replies[i], r.Replies[j]) 134 - }) 135 - } 136 - 137 - return listing 138 - } 139 - 140 68 func (i *Issue) Participants() []string { 141 69 participantSet := make(map[string]struct{}) 142 70 participants := []string{}
+1 -1
appview/notify/db/db.go
··· 121 121 parent := *comment.ReplyTo 122 122 123 123 // find the parent thread, and add all DIDs from here to the recipient list 124 - for _, t := range issue.CommentList() { 124 + for _, t := range models.NewCommentList(issue.Comments) { 125 125 if t.Self.AtUri() == syntax.ATURI(parent.Uri) { 126 126 for _, p := range t.Participants() { 127 127 recipients.Insert(p)
+5 -6
appview/pages/templates/repo/issues/fragments/commentList.html appview/pages/templates/fragments/comment/commentList.html
··· 1 - {{ define "repo/issues/fragments/commentList" }} 1 + {{ define "fragments/comment/commentList" }} 2 2 <div class="flex flex-col gap-4"> 3 3 {{ range $item := .CommentList }} 4 4 {{ template "commentListItem" (list $ .) }} ··· 9 9 {{ define "commentListItem" }} 10 10 {{ $root := index . 0 }} 11 11 {{ $item := index . 1 }} 12 - {{ $params := 13 - (dict 14 - "LoggedInUser" $root.LoggedInUser 15 - "Comment" $item.Self) }} 16 12 17 13 <div class="rounded border border-gray-200 dark:border-gray-700 w-full overflow-hidden shadow-sm bg-gray-50 dark:bg-gray-800/50"> 18 - {{ template "topLevelComment" $params }} 14 + {{ template "topLevelComment" 15 + (dict 16 + "LoggedInUser" $root.LoggedInUser 17 + "Comment" $item.Self) }} 19 18 20 19 <div class="relative ml-10 border-l-2 border-gray-200 dark:border-gray-700"> 21 20 {{ range $index, $reply := $item.Replies }}
+2 -4
appview/pages/templates/repo/issues/issue.html
··· 113 113 {{ define "repoAfter" }} 114 114 <div class="flex flex-col gap-4 mt-4"> 115 115 {{ 116 - template "repo/issues/fragments/commentList" 116 + template "fragments/comment/commentList" 117 117 (dict 118 - "RepoInfo" $.RepoInfo 119 118 "LoggedInUser" $.LoggedInUser 120 - "Issue" $.Issue 121 - "CommentList" $.Issue.CommentList) 119 + "CommentList" $.CommentList) 122 120 }} 123 121 124 122 {{ template "repo/issues/fragments/newComment" . }}

History

4 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview: move CommentList out of Issue
3/3 failed
expand
no conflicts, ready to merge
expand 0 comments
1 commit
expand
appview: move CommentList out of Issue
3/3 failed
expand
expand 0 comments
1 commit
expand
appview: move CommentList out of Issue
3/3 failed
expand
expand 0 comments
1 commit
expand
appview: move CommentList out of Issue
3/3 failed
expand
expand 0 comments