Permalink
Browse files

githubapi: Fix miscounting reactions.

Also simplify reactionGroups query, unmarshal directly into simpler
native Go types.
  • Loading branch information...
dmitshur committed Dec 1, 2017
1 parent 49abdd1 commit 1d741c0430ca5ddb6f5528a246d0b12f3ca6a46d
Showing with 6 additions and 4 deletions.
  1. +6 −4 githubapi/reactions.go
View
@@ -12,9 +12,9 @@ type reactionGroups []struct {
Content githubql.ReactionContent
Users struct {
Nodes []*githubqlActor
TotalCount githubql.Int
TotalCount int
} `graphql:"users(first:10)"`
ViewerHasReacted githubql.Boolean
ViewerHasReacted bool
}
// reactions converts []githubql.ReactionGroup to []reactions.Reaction.
@@ -28,7 +28,7 @@ func (s service) reactions(rgs reactionGroups) ([]reactions.Reaction, error) {
// Only return the details of first few users and authed user.
var us []users.User
addedAuthedUser := false
for i := 0; i < int(rg.Users.TotalCount); i++ {
for i := 0; i < rg.Users.TotalCount; i++ {
if i < len(rg.Users.Nodes) {
actor := ghActor(rg.Users.Nodes[i])
us = append(us, actor)
@@ -37,8 +37,10 @@ func (s service) reactions(rgs reactionGroups) ([]reactions.Reaction, error) {
}
} else if i == len(rg.Users.Nodes) {
// Add authed user last if they've reacted, but haven't been added already.
if bool(rg.ViewerHasReacted) && !addedAuthedUser {
if rg.ViewerHasReacted && !addedAuthedUser {
us = append(us, s.currentUser)
} else {
us = append(us, users.User{})
}
} else {
us = append(us, users.User{})

0 comments on commit 1d741c0

Please sign in to comment.