From 147807ef2c7b28b07ed9821f94e25b62364e8ac8 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Mon, 12 Jan 2026 16:25:44 +0900 Subject: [PATCH] appview: add reactions to comments Signed-off-by: Seongmin Lee --- appview/issues/issues.go | 3 +++ appview/pages/funcmap.go | 16 ++++++++++++++++ appview/pages/pages.go | 3 ++- .../fragments/comment/commentBody.html | 6 +++++- .../fragments/comment/commentList.html | 6 +++++- .../templates/repo/fragments/reaction.html | 7 +++---- .../templates/repo/fragments/reactions.html | 13 ++++++------- .../pages/templates/repo/issues/issue.html | 2 ++ appview/pages/templates/repo/pulls/pull.html | 6 ++++-- appview/pages/templates/strings/string.html | 2 ++ appview/pulls/single.go | 5 +++++ appview/state/reaction.go | 4 +--- appview/strings/strings.go | 19 +++++++++++++++++++ 13 files changed, 73 insertions(+), 19 deletions(-) diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 463feda4..5480b561 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -100,6 +100,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 f1d6b6e2..6a8b9780 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -481,6 +481,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 0581a2d8..8e7976be 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1213,7 +1213,6 @@ func (p *Pages) EditIssueFragment(w io.Writer, params EditIssueParams) error { } type ThreadReactionFragmentParams struct { - ThreadAt syntax.ATURI Kind models.ReactionKind Count int Users []string @@ -1631,6 +1630,8 @@ type SingleStringParams struct { Owner identity.Identity CommentList []models.CommentListItem + Reactions map[syntax.ATURI]map[models.ReactionKind]models.ReactionDisplayData + UserReacted map[syntax.ATURI]map[models.ReactionKind]bool VouchRelationships map[syntax.DID]*models.VouchRelationship } diff --git a/appview/pages/templates/fragments/comment/commentBody.html b/appview/pages/templates/fragments/comment/commentBody.html index 1fcfe931..c5f820d7 100644 --- a/appview/pages/templates/fragments/comment/commentBody.html +++ b/appview/pages/templates/fragments/comment/commentBody.html @@ -1,7 +1,11 @@ {{ define "fragments/comment/commentBody" }}
{{ if not .Comment.Deleted }} -
{{ .Comment.Body.Text | markdown }}
+
{{ .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 1b52fd9c..e5f1c9ef 100644 --- a/appview/pages/templates/fragments/comment/commentList.html +++ b/appview/pages/templates/fragments/comment/commentList.html @@ -14,6 +14,8 @@ {{ template "topLevelComment" (dict "LoggedInUser" $root.LoggedInUser + "Reactions" (index (asReactionMapMap $root.Reactions) $item.Self.AtUri) + "UserReacted" (index (asReactionStatusMapMap $root.UserReacted) $item.Self.AtUri) "VouchRelationship" (index $root.VouchRelationships $item.Self.Did) "Comment" $item.Self) }} @@ -23,6 +25,8 @@ {{ template "replyComment" (dict "LoggedInUser" $root.LoggedInUser + "Reactions" (index (asReactionMapMap $root.Reactions) $reply.AtUri) + "UserReacted" (index (asReactionStatusMapMap $root.UserReacted) $reply.AtUri) "VouchRelationship" (index $root.VouchRelationships $reply.Did) "Comment" $reply) }}
@@ -58,7 +62,7 @@ {{ end }} {{ define "replyComment" }} -
+
{{ template "user/fragments/picLink" (list .Comment.Did.String "size-8 mr-1" .VouchRelationship) }}
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" }}