···
65
-
func GetReactionCountMap(e Execer, threadAt syntax.ATURI) (map[models.ReactionKind]int, error) {
66
-
countMap := map[models.ReactionKind]int{}
65
+
func GetReactionMap(e Execer, threadAt syntax.ATURI) (map[models.ReactionKind]models.ReactionDisplayData, error) {
66
+
const maxUsersPerKind = 20
69
+
select kind, reacted_by_did,
70
+
row_number() over (partition by kind order by created asc) as rn,
71
+
count(*) over (partition by kind) as total
74
+
order by kind, created asc`
76
+
rows, err := e.Query(query, threadAt)
82
+
reactionMap := map[models.ReactionKind]models.ReactionDisplayData{}
for _, kind := range models.OrderedReactionKinds {
68
-
count, err := GetReactionCount(e, threadAt, kind)
70
-
return map[models.ReactionKind]int{}, nil
84
+
reactionMap[kind] = models.ReactionDisplayData{Count: 0, Users: []string{}}
88
+
var kind models.ReactionKind
91
+
if err := rows.Scan(&kind, &did, &rn, &total); err != nil {
72
-
countMap[kind] = count
95
+
data := reactionMap[kind]
97
+
if rn <= maxUsersPerKind {
98
+
data.Users = append(data.Users, did)
100
+
reactionMap[kind] = data
74
-
return countMap, nil
103
+
return reactionMap, rows.Err()
func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind models.ReactionKind) bool {