MM-12826 Include list of reactions in post metadata instead of just counts (#9749)

Этот коммит содержится в:
Harrison Healey
2018-10-26 11:26:32 -04:00
родитель 2190c37359
Коммит ba173414d9
5 изменённых файлов: 19 добавлений и 68 удалений

Просмотреть файл

@@ -18,8 +18,8 @@ type PostMetadata struct {
// of file attachments which are contained in PostMetadata.FileInfos.
Images map[string]*PostImage `json:"images,omitempty"`
// A map of emoji names to a count of users that reacted with the given emoji.
ReactionCounts ReactionCounts `json:"reaction_counts,omitempty"`
// A list of reactions made to the post
Reactions []*Reaction `json:"reactions,omitempty"`
}
type PostImage struct {

Просмотреть файл

@@ -17,8 +17,6 @@ type Reaction struct {
CreateAt int64 `json:"create_at"`
}
type ReactionCounts map[string]int
func (o *Reaction) ToJson() string {
b, _ := json.Marshal(o)
return string(b)
@@ -76,13 +74,3 @@ func (o *Reaction) PreSave() {
o.CreateAt = GetMillis()
}
}
func CountReactions(reactions []*Reaction) ReactionCounts {
reactionCounts := ReactionCounts{}
for _, reaction := range reactions {
reactionCounts[reaction.EmojiName] += 1
}
return reactionCounts
}

Просмотреть файл

@@ -82,38 +82,3 @@ func TestReactionIsValid(t *testing.T) {
t.Fatal("create at should be invalid")
}
}
func TestCountReactions(t *testing.T) {
userId := NewId()
userId2 := NewId()
reactions := []*Reaction{
{
UserId: userId,
EmojiName: "smile",
},
{
UserId: userId,
EmojiName: "frowning",
},
{
UserId: userId2,
EmojiName: "smile",
},
{
UserId: userId2,
EmojiName: "neutral_face",
},
}
reactionCounts := CountReactions(reactions)
if len(reactionCounts) != 3 {
t.Fatal("should've received counts for 3 reactions")
} else if reactionCounts["smile"] != 2 {
t.Fatal("should've received 2 smile reactions")
} else if reactionCounts["frowning"] != 1 {
t.Fatal("should've received 1 frowning reaction")
} else if reactionCounts["neutral_face"] != 1 {
t.Fatal("should've received 2 neutral_face reaction")
}
}