From 56721612fcd1562f134b0862fc34d0ac9382eb9e Mon Sep 17 00:00:00 2001 From: Cameron Smith Date: Mon, 06 Oct 2025 06:36:45 +0000 Subject: [PATCH] appview/{db,pages,models}: show tooltips for user handles when hovering on reactions Signed-off-by: Cameron Smith --- appview/db/reaction.go | 41 ++++++++++++++++++++++++++++++++++------- appview/issues/issues.go | 4 ++-- appview/models/reaction.go | 5 +++++ appview/pages/pages.go | 5 +++-- appview/pages/templates/repo/fragments/reaction.html | 7 ++++++- appview/pages/templates/repo/issues/issue.html | 6 ++++-- appview/pages/templates/repo/pulls/fragments/pullHeader.html | 6 ++++-- appview/pulls/pulls.go | 4 ++-- appview/state/reaction.go | 14 ++++++++------ 9 file(s) changed, 68 insertion(s)(+), 24 deletion(s)(-) diff --git a/appview/db/reaction.go b/appview/db/reaction.go --- a/appview/db/reaction.go +++ b/appview/db/reaction.go @@ -62,16 +62,43 @@ } return count, nil } -func GetReactionCountMap(e Execer, threadAt syntax.ATURI) (map[models.ReactionKind]int, error) { - countMap := map[models.ReactionKind]int{} +func GetReactionMap(e Execer, userLimit int, threadAt syntax.ATURI) (map[models.ReactionKind]models.ReactionDisplayData, error) { + query := ` + select kind, reacted_by_did, + row_number() over (partition by kind order by created asc) as rn, + count(*) over (partition by kind) as total + from reactions + where thread_at = ? + order by kind, created asc` + + rows, err := e.Query(query, threadAt) + if err != nil { + return nil, err + } + defer rows.Close() + + reactionMap := map[models.ReactionKind]models.ReactionDisplayData{} for _, kind := range models.OrderedReactionKinds { - count, err := GetReactionCount(e, threadAt, kind) - if err != nil { - return map[models.ReactionKind]int{}, nil + reactionMap[kind] = models.ReactionDisplayData{Count: 0, Users: []string{}} + } + + for rows.Next() { + var kind models.ReactionKind + var did string + var rn, total int + if err := rows.Scan(&kind, &did, &rn, &total); err != nil { + return nil, err } - countMap[kind] = count + + data := reactionMap[kind] + data.Count = total + if userLimit > 0 && rn <= userLimit { + data.Users = append(data.Users, did) + } + reactionMap[kind] = data } - return countMap, nil + + return reactionMap, rows.Err() } func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind models.ReactionKind) bool { diff --git a/appview/issues/issues.go b/appview/issues/issues.go --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -83,7 +83,7 @@ rp.pages.Error404(w) return } - reactionCountMap, err := db.GetReactionCountMap(rp.db, issue.AtUri()) + reactionMap, err := db.GetReactionMap(rp.db, 20, issue.AtUri()) if err != nil { l.Error("failed to get issue reactions", "err", err) } @@ -115,7 +115,7 @@ RepoInfo: f.RepoInfo(user), Issue: issue, CommentList: issue.CommentList(), OrderedReactionKinds: models.OrderedReactionKinds, - Reactions: reactionCountMap, + Reactions: reactionMap, UserReacted: userReactions, LabelDefs: defs, }) diff --git a/appview/models/reaction.go b/appview/models/reaction.go --- a/appview/models/reaction.go +++ b/appview/models/reaction.go @@ -55,3 +55,8 @@ Created time.Time Rkey string Kind ReactionKind } + +type ReactionDisplayData struct { + Count int + Users []string +} diff --git a/appview/pages/pages.go b/appview/pages/pages.go --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -985,7 +985,7 @@ CommentList []models.CommentListItem LabelDefs map[string]*models.LabelDefinition OrderedReactionKinds []models.ReactionKind - Reactions map[models.ReactionKind]int + Reactions map[models.ReactionKind]models.ReactionDisplayData UserReacted map[models.ReactionKind]bool } @@ -1010,6 +1010,7 @@ type ThreadReactionFragmentParams struct { ThreadAt syntax.ATURI Kind models.ReactionKind Count int + Users []string IsReacted bool } @@ -1138,7 +1139,7 @@ ResubmitCheck ResubmitResult Pipelines map[string]models.Pipeline OrderedReactionKinds []models.ReactionKind - Reactions map[models.ReactionKind]int + Reactions map[models.ReactionKind]models.ReactionDisplayData UserReacted map[models.ReactionKind]bool LabelDefs map[string]*models.LabelDefinition diff --git a/appview/pages/templates/repo/fragments/reaction.html b/appview/pages/templates/repo/fragments/reaction.html --- a/appview/pages/templates/repo/fragments/reaction.html +++ b/appview/pages/templates/repo/fragments/reaction.html @@ -2,7 +2,7 @@ {{ define "repo/fragments/reaction" }}