github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/api/reaction_groups.go (about) 1 package api 2 3 import ( 4 "bytes" 5 "encoding/json" 6 ) 7 8 type ReactionGroups []ReactionGroup 9 10 func (rg ReactionGroups) MarshalJSON() ([]byte, error) { 11 buf := bytes.Buffer{} 12 buf.WriteRune('[') 13 encoder := json.NewEncoder(&buf) 14 encoder.SetEscapeHTML(false) 15 16 hasPrev := false 17 for _, g := range rg { 18 if g.Users.TotalCount == 0 { 19 continue 20 } 21 if hasPrev { 22 buf.WriteRune(',') 23 } 24 if err := encoder.Encode(&g); err != nil { 25 return nil, err 26 } 27 hasPrev = true 28 } 29 buf.WriteRune(']') 30 return buf.Bytes(), nil 31 } 32 33 type ReactionGroup struct { 34 Content string `json:"content"` 35 Users ReactionGroupUsers `json:"users"` 36 } 37 38 type ReactionGroupUsers struct { 39 TotalCount int `json:"totalCount"` 40 } 41 42 func (rg ReactionGroup) Count() int { 43 return rg.Users.TotalCount 44 } 45 46 func (rg ReactionGroup) Emoji() string { 47 return reactionEmoji[rg.Content] 48 } 49 50 var reactionEmoji = map[string]string{ 51 "THUMBS_UP": "\U0001f44d", 52 "THUMBS_DOWN": "\U0001f44e", 53 "LAUGH": "\U0001f604", 54 "HOORAY": "\U0001f389", 55 "CONFUSED": "\U0001f615", 56 "HEART": "\u2764\ufe0f", 57 "ROCKET": "\U0001f680", 58 "EYES": "\U0001f440", 59 }