[MM-12465] Added capability to export reactions of posts during bulk export (#9600)
* Added capability to export reactions of posts * Added capability to export reactions of replies of a post * Added test case to test the reactions of a post
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
1befeb61d0
Коммит
7562f940bb
@@ -249,8 +249,15 @@ func (a *App) ExportAllPosts(writer io.Writer) *model.AppError {
|
||||
return err
|
||||
}
|
||||
|
||||
reactions, err := a.BuildPostReactions(post.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
postLine.Post.Replies = replies
|
||||
|
||||
postLine.Post.Reactions = reactions
|
||||
|
||||
if err := a.ExportWriteLine(writer, postLine); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -272,8 +279,35 @@ func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppErr
|
||||
replyPosts := result.Data.([]*model.ReplyForExport)
|
||||
|
||||
for _, reply := range replyPosts {
|
||||
replies = append(replies, *ImportReplyFromPost(reply))
|
||||
replyImportObject := ImportReplyFromPost(reply)
|
||||
if reply.HasReactions == true {
|
||||
reactionsOfReply, err := a.BuildPostReactions(reply.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
replyImportObject.Reactions = reactionsOfReply
|
||||
}
|
||||
replies = append(replies, *replyImportObject)
|
||||
}
|
||||
|
||||
return &replies, nil
|
||||
}
|
||||
|
||||
func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError) {
|
||||
var reactionsOfPost []ReactionImportData
|
||||
|
||||
result := <-a.Srv.Store.Reaction().GetForPost(postId, true)
|
||||
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
reactions := result.Data.([]*model.Reaction)
|
||||
|
||||
for _, reaction := range reactions {
|
||||
reactionsOfPost = append(reactionsOfPost, *ImportReactionFromPost(reaction))
|
||||
}
|
||||
|
||||
return &reactionsOfPost, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -111,3 +111,11 @@ func ImportReplyFromPost(post *model.ReplyForExport) *ReplyImportData {
|
||||
CreateAt: &post.CreateAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ImportReactionFromPost(reaction *model.Reaction) *ReactionImportData {
|
||||
return &ReactionImportData{
|
||||
User: &reaction.UserId,
|
||||
EmojiName: &reaction.EmojiName,
|
||||
CreateAt: &reaction.CreateAt,
|
||||
}
|
||||
}
|
||||
|
||||
32
app/export_test.go
Обычный файл
32
app/export_test.go
Обычный файл
@@ -0,0 +1,32 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestReactionsOfPost(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
post := th.BasicPost
|
||||
post.HasReactions = true
|
||||
|
||||
reactionObject := model.Reaction{
|
||||
UserId: model.NewId(),
|
||||
PostId: post.Id,
|
||||
EmojiName: "emoji",
|
||||
CreateAt: model.GetMillis(),
|
||||
}
|
||||
|
||||
th.App.SaveReactionForPost(&reactionObject)
|
||||
reactionsOfPost, err := th.App.BuildPostReactions(post.Id)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("should have reactions")
|
||||
}
|
||||
|
||||
assert.Equal(t, reactionObject.EmojiName, *(*reactionsOfPost)[0].EmojiName)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user