diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 1788e189..1d8d6a21 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -99,6 +99,9 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { } entities := []syntax.ATURI{issue.AtUri()} + for _, c := range issue.Comments { + entities = append(entities, c.AtUri()) + } reactions, err := db.ListReactionDisplayDataMap(rp.db, entities, 20) if err != nil { l.Error("failed to get reactions", "err", err) diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index ca4985fc..fe2d6b63 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -23,6 +23,7 @@ import ( chromahtml "github.com/alecthomas/chroma/v2/formatters/html" "github.com/alecthomas/chroma/v2/lexers" "github.com/alecthomas/chroma/v2/styles" + "github.com/bluesky-social/indigo/atproto/syntax" "github.com/dustin/go-humanize" "github.com/go-enry/go-enry/v2" "github.com/yuin/goldmark" @@ -487,6 +488,22 @@ func (p *Pages) funcMap() template.FuncMap { "isGenerated": func(path string) bool { return enry.IsGenerated(path, nil) }, + // NOTE(boltless): I know... I hate doing this too + "asReactionMapMap": func(dict any) map[syntax.ATURI]map[models.ReactionKind]models.ReactionDisplayData { + if dict == nil { + return make(map[syntax.ATURI]map[models.ReactionKind]models.ReactionDisplayData) + } + m, _ := dict.(map[syntax.ATURI]map[models.ReactionKind]models.ReactionDisplayData) + return m + }, + "asReactionStatusMapMap": func(dict any) map[syntax.ATURI]map[models.ReactionKind]bool { + if dict == nil { + log.Println("returning empty map") + return make(map[syntax.ATURI]map[models.ReactionKind]bool) + } + m, _ := dict.(map[syntax.ATURI]map[models.ReactionKind]bool) + return m + }, // constant values used to define a template "const": func() map[string]any { return map[string]any{ diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 6787bc5c..f12d66bd 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1152,7 +1152,6 @@ func (p *Pages) EditIssueFragment(w io.Writer, params EditIssueParams) error { } type ThreadReactionFragmentParams struct { - ThreadAt syntax.ATURI Kind models.ReactionKind Count int Users []string @@ -1599,6 +1598,8 @@ type SingleStringParams struct { StarCount int Owner identity.Identity CommentList []models.CommentListItem + Reactions map[syntax.ATURI]map[models.ReactionKind]models.ReactionDisplayData + UserReacted map[syntax.ATURI]map[models.ReactionKind]bool } func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error { diff --git a/appview/pages/templates/fragments/comment/commentBody.html b/appview/pages/templates/fragments/comment/commentBody.html index 1fcfe931..59ac3e2a 100644 --- a/appview/pages/templates/fragments/comment/commentBody.html +++ b/appview/pages/templates/fragments/comment/commentBody.html @@ -2,6 +2,10 @@
{{ if not .Comment.Deleted }}
{{ .Comment.Body.Text | markdown }}
+ {{ template "repo/fragments/reactions" + (dict "Reactions" .Reactions + "UserReacted" .UserReacted + "ThreadAt" .Comment.AtUri) }} {{ else }}
[deleted by author]
{{ end }} diff --git a/appview/pages/templates/fragments/comment/commentList.html b/appview/pages/templates/fragments/comment/commentList.html index c92e0562..4a671333 100644 --- a/appview/pages/templates/fragments/comment/commentList.html +++ b/appview/pages/templates/fragments/comment/commentList.html @@ -11,10 +11,14 @@ {{ $item := index . 1 }}
- {{ template "topLevelComment" + {{ + template "topLevelComment" (dict "LoggedInUser" $root.LoggedInUser - "Comment" $item.Self) }} + "Reactions" (index (asReactionMapMap $root.Reactions) $item.Self.AtUri) + "UserReacted" (index (asReactionStatusMapMap $root.UserReacted) $item.Self.AtUri) + "Comment" $item.Self) + }}
{{ range $index, $reply := $item.Replies }} @@ -23,6 +27,8 @@ template "replyComment" (dict "LoggedInUser" $root.LoggedInUser + "Reactions" (index (asReactionMapMap $root.Reactions) $reply.AtUri) + "UserReacted" (index (asReactionStatusMapMap $root.UserReacted) $reply.AtUri) "Comment" $reply) }}
@@ -58,7 +64,7 @@ {{ end }} {{ define "replyComment" }} -
+
{{ template "user/fragments/picLink" (list .Comment.Did.String "size-8 mr-1") }}
diff --git a/appview/pages/templates/repo/fragments/reaction.html b/appview/pages/templates/repo/fragments/reaction.html index 5268b8de..ac02aaec 100644 --- a/appview/pages/templates/repo/fragments/reaction.html +++ b/appview/pages/templates/repo/fragments/reaction.html @@ -1,6 +1,5 @@ {{ define "repo/fragments/reaction" }}
diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index bf363fba..5eaabc68 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -241,6 +241,11 @@ func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff } entities := []syntax.ATURI{pull.AtUri()} + for _, s := range pull.Submissions { + for _, c := range s.Comments { + entities = append(entities, c.AtUri()) + } + } reactions, err := db.ListReactionDisplayDataMap(s.db, entities, 20) if err != nil { l.Error("failed to get pull reactions", "err", err) diff --git a/appview/state/reaction.go b/appview/state/reaction.go index d887a28c..3257ed70 100644 --- a/appview/state/reaction.go +++ b/appview/state/reaction.go @@ -19,7 +19,7 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { l := s.logger.With("handler", "React") currentUser := s.oauth.GetMultiAccountUser(r) - subject := r.URL.Query().Get("subject") + subject := r.FormValue("subject-uri") if subject == "" { l.Warn("invalid form") return @@ -78,7 +78,6 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { l.Info("created atproto record", "uri", resp.Uri) s.pages.ThreadReactionFragment(w, pages.ThreadReactionFragmentParams{ - ThreadAt: subjectUri, Kind: reactionKind, Count: reactionMap[reactionKind].Count, Users: reactionMap[reactionKind].Users, @@ -117,7 +116,6 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { } s.pages.ThreadReactionFragment(w, pages.ThreadReactionFragmentParams{ - ThreadAt: subjectUri, Kind: reactionKind, Count: reactionMap[reactionKind].Count, Users: reactionMap[reactionKind].Users, diff --git a/appview/strings/strings.go b/appview/strings/strings.go index e806b3f2..8225df18 100644 --- a/appview/strings/strings.go +++ b/appview/strings/strings.go @@ -161,6 +161,23 @@ func (s *Strings) contents(w http.ResponseWriter, r *http.Request) { l.Error("failed to get comments", "err", err) } + entities := []syntax.ATURI{string.AtUri()} + for _, c := range comments { + entities = append(entities, c.AtUri()) + } + reactions, err := db.ListReactionDisplayDataMap(s.Db, entities, 20) + if err != nil { + l.Error("failed to get reactions", "err", err) + } + + var userReactions map[syntax.ATURI]map[models.ReactionKind]bool + if user != nil { + userReactions, err = db.ListReactionStatusMap(s.Db, entities, syntax.DID(user.Did)) + if err != nil { + l.Error("failed to get user reactions", "err", err) + } + } + s.Pages.SingleString(w, pages.SingleStringParams{ LoggedInUser: user, RenderToggle: renderToggle, @@ -171,6 +188,8 @@ func (s *Strings) contents(w http.ResponseWriter, r *http.Request) { StarCount: starCount, Owner: id, CommentList: models.NewCommentList(comments), + Reactions: reactions, + UserReacted: userReactions, }) }